}
alt i {
- 0u {
+ 0u => {
if str::len(part) == 8u {
correct += 1u;
}
}
- 1u | 2u | 3u {
+ 1u | 2u | 3u => {
if str::len(part) == 4u {
correct += 1u;
}
}
- 4u {
+ 4u => {
if str::len(part) == 12u {
correct += 1u;
}
}
- _ { }
+ _ => { }
}
}
if correct >= 5u {
// url parsing, we wouldn't need it
alt str::find_str(u, ~"://") {
- option::some(i) { has_archive_extension(u) }
- _ { false }
+ option::some(i) => has_archive_extension(u),
+ _ => false
}
}
let mut uuid = none;
for mis.each |a| {
alt a.node {
- ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) {
+ ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => {
alt *v {
- ~"name" { name = some(*s); }
- ~"vers" { vers = some(*s); }
- ~"uuid" { uuid = some(*s); }
- _ { }
+ ~"name" => name = some(*s),
+ ~"vers" => vers = some(*s),
+ ~"uuid" => uuid = some(*s),
+ _ => { }
}
}
- _ { fail ~"load_link: meta items must be name-values"; }
+ _ => fail ~"load_link: meta items must be name-values"
}
}
(name, vers, uuid)
for c.node.attrs.each |a| {
alt a.node.value.node {
- ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) {
+ ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => {
alt *v {
- ~"desc" { desc = some(*v); }
- ~"sigs" { sigs = some(*v); }
- ~"crate_type" { crate_type = some(*v); }
- _ { }
+ ~"desc" => desc = some(*v),
+ ~"sigs" => sigs = some(*v),
+ ~"crate_type" => crate_type = some(*v),
+ _ => { }
}
}
- ast::meta_list(v, mis) {
+ ast::meta_list(v, mis) => {
if *v == ~"link" {
let (n, v, u) = load_link(mis);
name = n;
uuid = u;
}
}
- _ {
+ _ => {
fail ~"crate attributes may not contain " +
~"meta_words";
}
fn goto_view_item(e: env, i: @ast::view_item) {
alt i.node {
- ast::view_item_use(ident, metas, id) {
+ ast::view_item_use(ident, metas, id) => {
let name_items =
attr::find_meta_items_by_name(metas, ~"name");
let m = if name_items.is_empty() {
for m.each |item| {
alt attr::get_meta_item_value_str(item) {
- some(value) {
+ some(value) => {
let name = attr::get_meta_item_name(item);
alt *name {
- ~"vers" { attr_vers = *value; }
- ~"from" { attr_from = *value; }
- _ {}
+ ~"vers" => attr_vers = *value,
+ ~"from" => attr_from = *value,
+ _ => ()
}
}
- none {}
+ none => ()
}
}
};
alt *attr_name {
- ~"std" | ~"core" { }
- _ { vec::push(e.deps, query); }
+ ~"std" | ~"core" => (),
+ _ => vec::push(e.deps, query)
}
}
- _ { }
+ _ => ()
}
}
fn goto_item(_e: env, _i: @ast::item) {
let deps = copy e.deps;
alt (name, vers, uuid) {
- (some(name0), some(vers0), some(uuid0)) {
+ (some(name0), some(vers0), some(uuid0)) => {
some({
name: name0,
vers: vers0,
crate_type: crate_type,
deps: deps })
}
- _ { return none; }
+ _ => return none
}
}
}
alt j {
- json::dict(j) {
+ json::dict(j) => {
let mut url = alt j.find(~"url") {
- some(json::string(u)) {
- *u
- }
- _ { fail ~"needed 'url' field in source"; }
+ some(json::string(u)) => *u,
+ _ => fail ~"needed 'url' field in source"
};
let method = alt j.find(~"method") {
- some(json::string(u)) {
- *u
- }
- _ { assume_source_method(url) }
+ some(json::string(u)) => *u,
+ _ => assume_source_method(url)
};
let key = alt j.find(~"key") {
- some(json::string(u)) {
- some(*u)
- }
- _ { none }
+ some(json::string(u)) => some(*u),
+ _ => none
};
let keyfp = alt j.find(~"keyfp") {
- some(json::string(u)) {
- some(*u)
- }
- _ { none }
+ some(json::string(u)) => some(*u),
+ _ => none
};
if method == ~"file" {
url = os::make_absolute(url);
mut keyfp: keyfp,
mut packages: ~[mut] };
}
- _ { fail ~"needed dict value in source"; }
+ _ => fail ~"needed dict value in source"
};
}
if !os::path_exists(filename) { return; }
let c = io::read_whole_file_str(filename);
alt json::from_str(result::get(c)) {
- ok(json::dict(j)) {
+ ok(json::dict(j)) => {
for j.each |k, v| {
sources.insert(k, parse_source(k, v));
debug!{"source: %s", k};
}
}
- ok(_) { fail ~"malformed sources.json"; }
- err(e) { fail fmt!{"%s:%s", filename, e.to_str()}; }
+ ok(_) => fail ~"malformed sources.json",
+ err(e) => fail fmt!{"%s:%s", filename, e.to_str()}
}
}
fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
let name = alt p.find(~"name") {
- some(json::string(n)) {
+ some(json::string(n)) => {
if !valid_pkg_name(*n) {
warn(~"malformed source json: "
+ src.name + ~", '" + *n + ~"'"+
}
*n
}
- _ {
+ _ => {
warn(~"malformed source json: " + src.name + ~" (missing name)");
return;
}
};
let uuid = alt p.find(~"uuid") {
- some(json::string(n)) {
+ some(json::string(n)) => {
if !is_uuid(*n) {
warn(~"malformed source json: "
+ src.name + ~", '" + *n + ~"'"+
}
*n
}
- _ {
+ _ => {
warn(~"malformed source json: " + src.name + ~" (missing uuid)");
return;
}
};
let url = alt p.find(~"url") {
- some(json::string(n)) { *n }
- _ {
+ some(json::string(n)) => *n,
+ _ => {
warn(~"malformed source json: " + src.name + ~" (missing url)");
return;
}
};
let method = alt p.find(~"method") {
- some(json::string(n)) { *n }
- _ {
+ some(json::string(n)) => *n,
+ _ => {
warn(~"malformed source json: "
+ src.name + ~" (missing method)");
return;
};
let reference = alt p.find(~"ref") {
- some(json::string(n)) { some(*n) }
- _ { none }
+ some(json::string(n)) => some(*n),
+ _ => none
};
let mut tags = ~[];
alt p.find(~"tags") {
- some(json::list(js)) {
+ some(json::list(js)) => {
for (*js).each |j| {
alt j {
- json::string(j) { vec::grow(tags, 1u, *j); }
- _ { }
+ json::string(j) => vec::grow(tags, 1u, *j),
+ _ => ()
}
}
}
- _ { }
+ _ => ()
}
let description = alt p.find(~"description") {
- some(json::string(n)) { *n }
- _ {
+ some(json::string(n)) => *n,
+ _ => {
warn(~"malformed source json: " + src.name
+ ~" (missing description)");
return;
};
alt vec::position(src.packages, |pkg| pkg.uuid == uuid) {
- some(idx) {
+ some(idx) => {
src.packages[idx] = newpkg;
log(debug, ~" updated package: " + src.name + ~"/" + name);
}
- none {
+ none => {
vec::grow(src.packages, 1u, newpkg);
}
}
if !os::path_exists(srcfile) { return; }
let srcstr = io::read_whole_file_str(srcfile);
alt json::from_str(result::get(srcstr)) {
- ok(json::dict(s)) {
+ ok(json::dict(s)) => {
let o = parse_source(src.name, json::dict(s));
src.key = o.key;
src.keyfp = o.keyfp;
}
- ok(_) {
+ ok(_) => {
warn(~"malformed source.json: " + src.name +
~"(source info is not a dict)");
}
- err(e) {
+ err(e) => {
warn(fmt!{"%s:%s", src.name, e.to_str()});
}
};
if !os::path_exists(pkgfile) { return; }
let pkgstr = io::read_whole_file_str(pkgfile);
alt json::from_str(result::get(pkgstr)) {
- ok(json::list(js)) {
+ ok(json::list(js)) => {
for (*js).each |j| {
alt j {
- json::dict(p) {
+ json::dict(p) => {
load_one_source_package(src, p);
}
- _ {
+ _ => {
warn(~"malformed source json: " + src.name +
~" (non-dict pkg)");
}
}
}
}
- ok(_) {
+ ok(_) => {
warn(~"malformed packages.json: " + src.name +
~"(packages is not a list)");
}
- err(e) {
+ err(e) => {
warn(fmt!{"%s:%s", src.name, e.to_str()});
}
};
fn build_cargo_options(argv: ~[~str]) -> options {
let matches = alt getopts::getopts(argv, opts()) {
- result::ok(m) { m }
- result::err(f) {
+ result::ok(m) => m,
+ result::err(f) => {
fail fmt!{"%s", getopts::fail_str(f)};
}
};
fn configure(opts: options) -> cargo {
let home = alt get_cargo_root() {
- ok(home) { home }
- err(_err) { result::get(get_cargo_sysroot()) }
+ ok(home) => home,
+ err(_err) => result::get(get_cargo_sysroot())
};
let get_cargo_dir = alt opts.mode {
- system_mode { get_cargo_sysroot }
- user_mode { get_cargo_root }
- local_mode { get_cargo_root_nearest }
+ system_mode => get_cargo_sysroot,
+ user_mode => get_cargo_root,
+ local_mode => get_cargo_root_nearest
};
let p = result::get(get_cargo_dir());
fn test_one_crate(_c: cargo, path: ~str, cf: ~str) {
let buildpath = alt run_in_buildpath(~"testing", path, ~"/test", cf,
~[ ~"--test"]) {
- none { return; }
- some(bp) { bp }
+ none => return,
+ some(bp) => bp
};
run_programs(buildpath);
}
fn install_one_crate(c: cargo, path: ~str, cf: ~str) {
let buildpath = alt run_in_buildpath(~"installing", path,
~"/build", cf, ~[]) {
- none { return; }
- some(bp) { bp }
+ none => return,
+ some(bp) => bp
};
let newv = os::list_dir_path(buildpath);
let exec_suffix = os::exe_suffix();
fn rustc_sysroot() -> ~str {
alt os::self_exe_path() {
- some(path) {
+ some(path) => {
let path = ~[path, ~"..", ~"bin", ~"rustc"];
let rustc = path::normalize(path::connect_many(path));
debug!{" rustc: %s", rustc};
rustc
}
- none { ~"rustc" }
+ none => ~"rustc"
}
}
for cratefiles.each |cf| {
alt load_crate(cf) {
- none { again; }
- some(crate) {
+ none => again,
+ some(crate) => {
for crate.deps.each |query| {
// FIXME (#1356): handle cyclic dependencies
// (n.b. #1356 says "Cyclic dependency is an error
let wd_base = c.workdir + path::path_sep();
let wd = alt tempfile::mkdtemp(wd_base, ~"") {
- some(wd) { wd }
- none { fail fmt!{"needed temp dir: %s", wd_base}; }
+ some(wd) => wd,
+ none => fail fmt!{"needed temp dir: %s", wd_base}
};
install_query(c, wd, query);
fn install_package(c: cargo, src: ~str, wd: ~str, pkg: package) {
let url = copy pkg.url;
let method = alt pkg.method {
- ~"git" { ~"git" }
- ~"file" { ~"file" }
- _ { ~"curl" }
+ ~"git" => ~"git",
+ ~"file" => ~"file",
+ _ => ~"curl"
};
info(fmt!{"installing %s/%s via %s...", src, pkg.name, method});
alt method {
- ~"git" { install_git(c, wd, url, copy pkg.reference); }
- ~"file" { install_file(c, wd, url); }
- ~"curl" { install_curl(c, wd, copy url); }
- _ {}
+ ~"git" => install_git(c, wd, url, copy pkg.reference),
+ ~"file" => install_file(c, wd, url),
+ ~"curl" => install_curl(c, wd, copy url),
+ _ => ()
}
}
fn install_uuid_specific(c: cargo, wd: ~str, src: ~str, uuid: ~str) {
alt c.sources.find(src) {
- some(s) {
+ some(s) => {
let packages = copy s.packages;
if vec::any(packages, |p| {
if p.uuid == uuid {
} else { false }
}) { return; }
}
- _ { }
+ _ => ()
}
error(~"can't find package: " + src + ~"/" + uuid);
}
fn install_named_specific(c: cargo, wd: ~str, src: ~str, name: ~str) {
alt c.sources.find(src) {
- some(s) {
+ some(s) => {
let packages = copy s.packages;
if vec::any(packages, |p| {
if p.name == name {
} else { false }
}) { return; }
}
- _ { }
+ _ => ()
}
error(~"can't find package: " + src + ~"/" + name);
}
if is_uuid(target) {
for os::list_dir(lib).each |file| {
alt str::find_str(file, ~"-" + target + ~"-") {
- some(idx) {
+ some(idx) => {
let full = path::normalize(path::connect(lib, file));
if os::remove_file(full) {
info(~"uninstalled: '" + full + ~"'");
}
return;
}
- none { again; }
+ none => again
}
}
} else {
for os::list_dir(lib).each |file| {
alt str::find_str(file, ~"lib" + target + ~"-") {
- some(idx) {
+ some(idx) => {
let full = path::normalize(path::connect(lib,
file));
if os::remove_file(full) {
}
return;
}
- none { again; }
+ none => again
}
}
for os::list_dir(bin).each |file| {
alt str::find_str(file, target) {
- some(idx) {
+ some(idx) => {
let full = path::normalize(path::connect(bin, file));
if os::remove_file(full) {
info(~"uninstalled: '" + full + ~"'");
}
return;
}
- none { again; }
+ none => again
}
}
fn install_query(c: cargo, wd: ~str, target: ~str) {
alt c.dep_cache.find(target) {
- some(inst) {
+ some(inst) => {
if inst {
return;
}
}
- none {}
+ none => ()
}
c.dep_cache.insert(target, true);
let mut ps = copy target;
alt str::find_char(ps, '/') {
- option::some(idx) {
+ option::some(idx) => {
let source = str::slice(ps, 0u, idx);
ps = str::slice(ps, idx + 1u, str::len(ps));
if is_uuid(ps) {
install_named_specific(c, wd, source, ps);
}
}
- option::none {
+ option::none => {
if is_uuid(ps) {
install_uuid(c, wd, ps);
} else {
fn cmd_install(c: cargo) unsafe {
let wd_base = c.workdir + path::path_sep();
let wd = alt tempfile::mkdtemp(wd_base, ~"") {
- some(wd) { wd }
- none { fail fmt!{"needed temp dir: %s", wd_base}; }
+ some(wd) => wd,
+ none => fail fmt!{"needed temp dir: %s", wd_base}
};
if vec::len(c.opts.free) == 2u {
os::copy_file(path::connect(url, ~"packages.json.sig"), sigfile);
alt copy src.key {
- some(u) {
+ some(u) => {
let p = run::program_output(~"curl",
~[~"-f", ~"-s", ~"-o", keyfile, u]);
if p.status != 0 {
}
pgp::add(c.root, keyfile);
}
- _ { }
+ _ => ()
}
alt (src.key, src.keyfp) {
- (some(_), some(f)) {
+ (some(_), some(f)) => {
let r = pgp::verify(c.root, pkgfile, sigfile, f);
if !r {
}
}
}
- _ {}
+ _ => ()
}
copy_warn(pkgfile, destpkgfile);
let has_src_file = os::path_exists(srcfile);
alt copy src.key {
- some(u) {
+ some(u) => {
let p = run::program_output(~"curl",
~[~"-f", ~"-s", ~"-o", keyfile, u]);
if p.status != 0 {
}
pgp::add(c.root, keyfile);
}
- _ { }
+ _ => ()
}
alt (src.key, src.keyfp) {
- (some(_), some(f)) {
+ (some(_), some(f)) => {
let r = pgp::verify(c.root, pkgfile, sigfile, f);
if !r {
}
}
}
- _ {}
+ _ => ()
}
os::remove_file(keyfile);
}
alt copy src.key {
- some(u) {
+ some(u) => {
let p = run::program_output(~"curl",
~[~"-f", ~"-s", ~"-o", keyfile, u]);
if p.status != 0 {
}
pgp::add(c.root, keyfile);
}
- _ { }
+ _ => ()
}
alt (src.key, src.keyfp) {
- (some(_), some(f)) {
+ (some(_), some(f)) => {
if smart {
url = src.url + ~"/packages.json.sig";
}
}
}
}
- _ {}
+ _ => ()
}
copy_warn(pkgfile, destpkgfile);
need_dir(dir);
let result = alt src.method {
- ~"git" { sync_one_git(c, dir, src) }
- ~"file" { sync_one_file(c, dir, src) }
- _ { sync_one_curl(c, dir, src) }
+ ~"git" => sync_one_git(c, dir, src),
+ ~"file" => sync_one_file(c, dir, src),
+ _ => sync_one_curl(c, dir, src)
};
if result {
error(fmt!{"'%s' is an invalid source name", name});
} else {
alt c.sources.find(name) {
- some(source) {
+ some(source) => {
print_source(source);
}
- none {
+ none => {
error(fmt!{"no such source: %s", name});
}
}
}
alt io::buffered_file_writer(out) {
- result::ok(writer) {
+ result::ok(writer) => {
let hash = map::str_hash();
let root = json::dict(hash);
chash.insert(~"method", json::string(@v.method));
alt copy v.key {
- some(key) {
+ some(key) => {
chash.insert(~"key", json::string(@key));
}
- _ {}
+ _ => ()
}
alt copy v.keyfp {
- some(keyfp) {
+ some(keyfp) => {
chash.insert(~"keyfp", json::string(@keyfp));
}
- _ {}
+ _ => ()
}
hash.insert(k, child);
writer.write_str(json::to_str(root));
}
- result::err(e) {
+ result::err(e) => {
error(fmt!{"could not dump sources: %s", e});
}
}
let action = c.opts.free[2u];
alt action {
- ~"clear" {
+ ~"clear" => {
for c.sources.each_key |k| {
c.sources.remove(k);
}
info(~"cleared sources");
}
- ~"add" {
+ ~"add" => {
if vec::len(c.opts.free) < 5u {
cmd_usage();
return;
}
alt c.sources.find(name) {
- some(source) {
+ some(source) => {
error(fmt!{"source already exists: %s", name});
}
- none {
+ none => {
c.sources.insert(name, @{
name: name,
mut url: url,
}
}
}
- ~"remove" {
+ ~"remove" => {
if vec::len(c.opts.free) < 4u {
cmd_usage();
return;
}
alt c.sources.find(name) {
- some(source) {
+ some(source) => {
c.sources.remove(name);
info(fmt!{"removed source: %s", name});
}
- none {
+ none => {
error(fmt!{"no such source: %s", name});
}
}
}
- ~"set-url" {
+ ~"set-url" => {
if vec::len(c.opts.free) < 5u {
cmd_usage();
return;
}
alt c.sources.find(name) {
- some(source) {
+ some(source) => {
let old = copy source.url;
let method = assume_source_method(url);
info(fmt!{"changed source url: '%s' to '%s'", old, url});
}
- none {
+ none => {
error(fmt!{"no such source: %s", name});
}
}
}
- ~"set-method" {
+ ~"set-method" => {
if vec::len(c.opts.free) < 5u {
cmd_usage();
return;
}
alt c.sources.find(name) {
- some(source) {
+ some(source) => {
let old = copy source.method;
source.method = alt method {
- ~"git" { ~"git" }
- ~"file" { ~"file" }
- _ { ~"curl" }
+ ~"git" => ~"git",
+ ~"file" => ~"file",
+ _ => ~"curl"
};
c.sources.insert(name, source);
info(fmt!{"changed source method: '%s' to '%s'", old,
method});
}
- none {
+ none => {
error(fmt!{"no such source: %s", name});
}
}
}
- ~"rename" {
+ ~"rename" => {
if vec::len(c.opts.free) < 5u {
cmd_usage();
return;
}
alt c.sources.find(name) {
- some(source) {
+ some(source) => {
c.sources.remove(name);
c.sources.insert(newn, source);
info(fmt!{"renamed source: %s to %s", name, newn});
}
- none {
+ none => {
error(fmt!{"no such source: %s", name});
}
}
}
- _ { cmd_usage(); }
+ _ => cmd_usage()
}
}
}
if o.help {
alt o.free[1] {
- ~"init" { cmd_usage_init(); }
- ~"install" { cmd_usage_install(); }
- ~"uninstall" { cmd_usage_uninstall(); }
- ~"list" { cmd_usage_list(); }
- ~"search" { cmd_usage_search(); }
- ~"sources" { cmd_usage_sources(); }
- _ { cmd_usage(); }
+ ~"init" => cmd_usage_init(),
+ ~"install" => cmd_usage_install(),
+ ~"uninstall" => cmd_usage_uninstall(),
+ ~"list" => cmd_usage_list(),
+ ~"search" => cmd_usage_search(),
+ ~"sources" => cmd_usage_sources(),
+ _ => cmd_usage()
}
return;
}
}
alt o.free[1] {
- ~"init" { cmd_init(c); }
- ~"install" { cmd_install(c); }
- ~"uninstall" { cmd_uninstall(c); }
- ~"list" { cmd_list(c); }
- ~"search" { cmd_search(c); }
- ~"sources" { cmd_sources(c); }
- _ { cmd_usage(); }
+ ~"init" => cmd_init(c),
+ ~"install" => cmd_install(c),
+ ~"uninstall" => cmd_uninstall(c),
+ ~"list" => cmd_list(c),
+ ~"search" => cmd_search(c),
+ ~"sources" => cmd_sources(c),
+ _ => cmd_usage()
}
dump_cache(c);
let args_ = vec::tail(args);
let matches =
alt getopts::getopts(args_, opts) {
- ok(m) { m }
- err(f) { fail getopts::fail_str(f) }
+ ok(m) => m,
+ err(f) => fail getopts::fail_str(f)
};
return {compile_lib_path: getopts::opt_str(matches, ~"compile-lib-path"),
}
fn opt_str(maybestr: option<~str>) -> ~str {
- alt maybestr { option::some(s) { s } option::none { ~"(none)" } }
+ alt maybestr { option::some(s) => s, option::none => ~"(none)" }
}
fn str_opt(maybestr: ~str) -> option<~str> {
fn str_mode(s: ~str) -> mode {
alt s {
- ~"compile-fail" { mode_compile_fail }
- ~"run-fail" { mode_run_fail }
- ~"run-pass" { mode_run_pass }
- ~"pretty" { mode_pretty }
- _ { fail ~"invalid mode" }
+ ~"compile-fail" => mode_compile_fail,
+ ~"run-fail" => mode_run_fail,
+ ~"run-pass" => mode_run_pass,
+ ~"pretty" => mode_pretty,
+ _ => fail ~"invalid mode"
}
}
fn mode_str(mode: mode) -> ~str {
alt mode {
- mode_compile_fail { ~"compile-fail" }
- mode_run_fail { ~"run-fail" }
- mode_run_pass { ~"run-pass" }
- mode_pretty { ~"pretty" }
+ mode_compile_fail => ~"compile-fail",
+ mode_run_fail => ~"run-fail",
+ mode_run_pass => ~"run-pass",
+ mode_pretty => ~"pretty"
}
}
fn test_opts(config: config) -> test::test_opts {
{filter:
alt config.filter {
- option::some(s) { option::some(s) }
- option::none { option::none }
+ option::some(s) => option::some(s),
+ option::none => option::none
},
run_ignored: config.run_ignored,
logfile:
alt config.logfile {
- option::some(s) { option::some(s) }
- option::none { option::none }
+ option::some(s) => option::some(s),
+ option::none => option::none
}
}
}
fn is_test(config: config, testfile: ~str) -> bool {
// Pretty-printer does not work with .rc files yet
let valid_extensions =
- alt config.mode { mode_pretty { ~[~".rs"] } _ { ~[~".rc", ~".rs"] } };
+ alt config.mode {
+ mode_pretty => ~[~".rs"],
+ _ => ~[~".rc", ~".rs"]
+ };
let invalid_prefixes = ~[~".", ~"#", ~"~"];
let name = path::basename(testfile);
let error_tag = ~"//~";
let mut idx;
alt str::find_str(line, error_tag) {
- option::none { return ~[]; }
- option::some(nn) { idx = (nn as uint) + str::len(error_tag); }
+ option::none => return ~[],
+ option::some(nn) => { idx = (nn as uint) + str::len(error_tag); }
}
// "//~^^^ kind msg" denotes a message expected
let mut pp_exact = option::none;
for iter_header(testfile) |ln| {
alt parse_error_pattern(ln) {
- option::some(ep) { vec::push(error_patterns, ep) }
- option::none { }
+ option::some(ep) => vec::push(error_patterns, ep),
+ option::none => ()
};
if option::is_none(compile_flags) {
// nv is either FOO or FOO=BAR
let strs = str::splitn_char(nv, '=', 1u);
alt strs.len() {
- 1u { (strs[0], ~"") }
- 2u { (strs[0], strs[1]) }
- n { fail fmt!{"Expected 1 or 2 strings, not %u", n}; }
+ 1u => (strs[0], ~""),
+ 2u => (strs[0], strs[1]),
+ n => fail fmt!{"Expected 1 or 2 strings, not %u", n}
}
}
}
fn parse_pp_exact(line: ~str, testfile: ~str) -> option<~str> {
alt parse_name_value_directive(line, ~"pp-exact") {
- option::some(s) { option::some(s) }
- option::none {
+ option::some(s) => option::some(s),
+ option::none => {
if parse_name_directive(line, ~"pp-exact") {
option::some(path::basename(testfile))
} else {
directive: ~str) -> option<~str> unsafe {
let keycolon = directive + ~":";
alt str::find_str(line, keycolon) {
- option::some(colon) {
+ option::some(colon) => {
let value = str::slice(line, colon + str::len(keycolon),
str::len(line));
debug!{"%s: %s", directive, value};
option::some(value)
}
- option::none { option::none }
+ option::none => option::none
}
}
while count > 0 {
let stream = comm::recv(p);
alt check stream {
- (1, s) {
+ (1, s) => {
outs = s;
}
- (2, s) {
+ (2, s) => {
errs = s;
}
};
debug!{"running %s", testfile};
let props = load_props(testfile);
alt config.mode {
- mode_compile_fail { run_cfail_test(config, props, testfile); }
- mode_run_fail { run_rfail_test(config, props, testfile); }
- mode_run_pass { run_rpass_test(config, props, testfile); }
- mode_pretty { run_pretty_test(config, props, testfile); }
+ mode_compile_fail => run_cfail_test(config, props, testfile),
+ mode_run_fail => run_rfail_test(config, props, testfile),
+ mode_run_pass => run_rpass_test(config, props, testfile),
+ mode_pretty => run_pretty_test(config, props, testfile)
}
}
} else { logv(config, ~"testing for converging pretty-printing"); }
let rounds =
- alt props.pp_exact { option::some(_) { 1 } option::none { 2 } };
+ alt props.pp_exact { option::some(_) => 1, option::none => 2 };
let mut srcs = ~[result::get(io::read_whole_file_str(testfile))];
let mut expected =
alt props.pp_exact {
- option::some(file) {
+ option::some(file) => {
let filepath = path::connect(path::dirname(testfile), file);
result::get(io::read_whole_file_str(filepath))
}
- option::none { srcs[vec::len(srcs) - 2u] }
+ option::none => { srcs[vec::len(srcs) - 2u] }
};
let mut actual = srcs[vec::len(srcs) - 1u];
// then split apart its command
let runtool =
alt config.runtool {
- option::some(s) { option::some(s) }
- option::none { option::none }
+ option::some(s) => option::some(s),
+ option::none => option::none
};
split_maybe_args(runtool)
};
}
alt argstr {
- option::some(s) { rm_whitespace(str::split_char(s, ' ')) }
- option::none { ~[] }
+ option::some(s) => rm_whitespace(str::split_char(s, ' ')),
+ option::none => ~[]
}
}
// Windows just uses PATH as the library search path, so we have to
// maintain the current value while adding our own
alt getenv(lib_path_env_var()) {
- option::some(curr) {
+ option::some(curr) => {
fmt!{"%s%s%s", path, path_div(), curr}
}
- option::none { path }
+ option::none => path
}
}
pure fn safe_to_use_expr(e: ast::expr, tm: test_mode) -> bool {
alt tm {
- tm_converge {
+ tm_converge => {
alt e.node {
// If the fuzzer moves a block-ending-in-semicolon into callee
// position, the pretty-printer can't preserve this even by
// parenthesizing!! See email to marijn.
- ast::expr_if(_, _, _) { false }
- ast::expr_block(_) { false }
- ast::expr_alt(_, _, _) { false }
- ast::expr_while(_, _) { false }
+ ast::expr_if(_, _, _) => { false }
+ ast::expr_block(_) => { false }
+ ast::expr_alt(_, _, _) => { false }
+ ast::expr_while(_, _) => { false }
// https://github.com/mozilla/rust/issues/929
- ast::expr_cast(_, _) { false }
- ast::expr_assert(_) { false }
- ast::expr_binary(_, _, _) { false }
- ast::expr_assign(_, _) { false }
- ast::expr_assign_op(_, _, _) { false }
+ ast::expr_cast(_, _) => { false }
+ ast::expr_assert(_) => { false }
+ ast::expr_binary(_, _, _) => { false }
+ ast::expr_assign(_, _) => { false }
+ ast::expr_assign_op(_, _, _) => { false }
- ast::expr_fail(option::none) { false }
- ast::expr_ret(option::none) { false }
+ ast::expr_fail(option::none) => { false }
+ ast::expr_ret(option::none) => { false }
// https://github.com/mozilla/rust/issues/953
- ast::expr_fail(option::some(_)) { false }
+ ast::expr_fail(option::some(_)) => { false }
// https://github.com/mozilla/rust/issues/928
//ast::expr_cast(_, _) { false }
// https://github.com/mozilla/rust/issues/1458
- ast::expr_call(_, _, _) { false }
+ ast::expr_call(_, _, _) => { false }
- _ { true }
+ _ => { true }
}
}
- tm_run { true }
+ tm_run => { true }
}
}
fn safe_to_replace_expr(e: ast::expr_, _tm: test_mode) -> bool {
alt e {
// https://github.com/mozilla/rust/issues/652
- ast::expr_if(*) { false }
- ast::expr_block(_) { false }
+ ast::expr_if(*) => { false }
+ ast::expr_block(_) => { false }
// expr_call is also missing a constraint
- ast::expr_fn_block(*) { false }
+ ast::expr_fn_block(*) => { false }
- _ { true }
+ _ => { true }
}
}
fn safe_to_replace_ty(t: ast::ty_, _tm: test_mode) -> bool {
alt t {
- ast::ty_infer { false } // always implicit, always top level
- ast::ty_bot { false } // in source, can only appear
+ ast::ty_infer => { false } // always implicit, always top level
+ ast::ty_bot => { false } // in source, can only appear
// as the out type of a function
- ast::ty_mac(_) { false }
- _ { true }
+ ast::ty_mac(_) => { false }
+ _ => { true }
}
}
pprust::no_ann(),
false));
alt cx.mode {
- tm_converge {
+ tm_converge => {
check_roundtrip_convergence(str3, 1u);
}
- tm_run {
+ tm_run => {
let file_label = fmt!{"rusttmp/%s_%s_%u_%u",
last_part(filename),
thing_label, i, j};
let compile_result = check_compiling(filename);
let run_result = alt (compile_result, allow_running) {
- (passed, true) { check_running(suggested_filename_prefix) }
- (h, _) { h }
+ (passed, true) => { check_running(suggested_filename_prefix) }
+ (h, _) => { h }
};
alt run_result {
- passed | cleanly_rejected(_) | known_bug(_) {
+ passed | cleanly_rejected(_) | known_bug(_) => {
removeIfExists(suggested_filename_prefix);
removeIfExists(suggested_filename_prefix + ~".rs");
removeDirIfExists(suggested_filename_prefix + ~".dSYM");
}
- failed(s) {
+ failed(s) => {
log(error, ~"check_whole_compiler failure: " + s);
log(error, ~"Saved as: " + filename);
}
failed(~"Mentioned malloc")
} else {
alt p.status {
- 0 { passed }
- 100 { cleanly_rejected(~"running: explicit fail") }
- 101 | 247 { cleanly_rejected(~"running: timed out") }
- 245 | 246 | 138 | 252 {
+ 0 => { passed }
+ 100 => { cleanly_rejected(~"running: explicit fail") }
+ 101 | 247 => { cleanly_rejected(~"running: timed out") }
+ 245 | 246 | 138 | 252 => {
known_bug(~"https://github.com/mozilla/rust/issues/1466")
}
- 136 | 248 {
+ 136 | 248 => {
known_bug(
~"SIGFPE - https://github.com/mozilla/rust/issues/944")
}
- rc {
+ rc => {
failed(~"Rust program ran but exited with status " +
int::str(rc))
}
let has_rp = @mut false;
fn visit_ty(flag: @mut bool, t: @ast::ty) {
alt t.node {
- ast::ty_ptr(_) { *flag = true; }
- _ { }
+ ast::ty_ptr(_) => { *flag = true; }
+ _ => { }
}
}
let v =
/// Parse logic value from `s`
pure fn from_str(s: ~str) -> option<bool> {
alt check s {
- ~"true" { some(true) }
- ~"false" { some(false) }
- _ { none }
+ ~"true" => some(true),
+ ~"false" => some(false),
+ _ => none
}
}
*/
pure fn to_digit(c: char, radix: uint) -> option<uint> {
let val = alt c {
- '0' to '9' { c as uint - ('0' as uint) }
- 'a' to 'z' { c as uint + 10u - ('a' as uint) }
- 'A' to 'Z' { c as uint + 10u - ('A' as uint) }
- _ { return none; }
+ '0' to '9' => c as uint - ('0' as uint),
+ 'a' to 'z' => c as uint + 10u - ('a' as uint),
+ 'A' to 'Z' => c as uint + 10u - ('A' as uint),
+ _ => return none
};
if val < radix { some(val) }
else { none }
*/
fn escape_default(c: char) -> ~str {
alt c {
- '\t' { ~"\\t" }
- '\r' { ~"\\r" }
- '\n' { ~"\\n" }
- '\\' { ~"\\\\" }
- '\'' { ~"\\'" }
- '"' { ~"\\\"" }
- '\x20' to '\x7e' { str::from_char(c) }
- _ { escape_unicode(c) }
+ '\t' => ~"\\t",
+ '\r' => ~"\\r",
+ '\n' => ~"\\n",
+ '\\' => ~"\\\\",
+ '\'' => ~"\\'",
+ '"' => ~"\\\"",
+ '\x20' to '\x7e' => str::from_char(c),
+ _ => escape_unicode(c)
}
}
let mut bs = 0;
for iter::repeat(msgs * times * 2u) {
alt check select2(po_a, po_b) {
- either::left(~"a") { as += 1 }
- either::right(~"b") { bs += 1 }
+ either::left(~"a") => as += 1,
+ either::right(~"b") => bs += 1
}
}
impl private_methods<T> for dlist_node<T> {
pure fn assert_links() {
alt self.next {
- some(neighbour) {
- alt neighbour.prev {
- some(me) {
- if !box::ptr_eq(*self, *me) {
- fail ~"Asymmetric next-link in dlist node."
- }
- }
- none { fail ~"One-way next-link in dlist node." }
- }
+ some(neighbour) => alt neighbour.prev {
+ some(me) => if !box::ptr_eq(*self, *me) {
+ fail ~"Asymmetric next-link in dlist node."
+ }
+ none => fail ~"One-way next-link in dlist node."
}
- none { }
+ none => ()
}
alt self.prev {
- some(neighbour) {
- alt neighbour.next {
- some(me) {
- if !box::ptr_eq(*me, *self) {
- fail ~"Asymmetric prev-link in dlist node."
- }
- }
- none { fail ~"One-way prev-link in dlist node." }
- }
+ some(neighbour) => alt neighbour.next {
+ some(me) => if !box::ptr_eq(*me, *self) {
+ fail ~"Asymmetric prev-link in dlist node."
+ }
+ none => fail ~"One-way prev-link in dlist node."
}
- none { }
+ none => ()
}
}
}
/// Get the next node in the list, failing if there isn't one.
pure fn next_node() -> dlist_node<T> {
alt self.next_link() {
- some(nobe) { nobe }
- none { fail ~"This dlist node has no next neighbour." }
+ some(nobe) => nobe,
+ none => fail ~"This dlist node has no next neighbour."
}
}
/// Get the previous node in the list, if there is one.
/// Get the previous node in the list, failing if there isn't one.
pure fn prev_node() -> dlist_node<T> {
alt self.prev_link() {
- some(nobe) { nobe }
- none { fail ~"This dlist node has no previous neighbour." }
+ some(nobe) => nobe,
+ none => fail ~"This dlist node has no previous neighbour."
}
}
}
#[inline(always)]
fn link(+before: dlist_link<T>, +after: dlist_link<T>) {
alt before {
- some(neighbour) { neighbour.next = after; }
- none { self.hd = after; }
+ some(neighbour) => neighbour.next = after,
+ none => self.hd = after
}
alt after {
- some(neighbour) { neighbour.prev = before; }
- none { self.tl = before; }
+ some(neighbour) => neighbour.prev = before,
+ none => self.tl = before
}
}
// Remove a node from the list.
/// Get the node at the list's head, failing if empty. O(1).
pure fn head_n() -> dlist_node<T> {
alt self.hd {
- some(nobe) { nobe }
- none {
- fail ~"Attempted to get the head of an empty dlist."
- }
+ some(nobe) => nobe,
+ none => fail ~"Attempted to get the head of an empty dlist."
}
}
/// Get the node at the list's tail, failing if empty. O(1).
pure fn tail_n() -> dlist_node<T> {
alt self.tl {
- some(nobe) { nobe }
- none {
- fail ~"Attempted to get the tail of an empty dlist."
- }
+ some(nobe) => nobe,
+ none => fail ~"Attempted to get the tail of an empty dlist."
}
}
* result is returned.
*/
- alt value { left(l) { f_left(l) } right(r) { f_right(r) } }
+ alt value {
+ left(l) => f_left(l),
+ right(r) => f_right(r)
+ }
}
fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] {
let mut result: ~[T] = ~[];
for vec::each(eithers) |elt| {
- alt elt { left(l) { vec::push(result, l); } _ {/* fallthrough */ } }
+ alt elt {
+ left(l) => vec::push(result, l),
+ _ => { /* fallthrough */ }
+ }
}
return result;
}
let mut result: ~[U] = ~[];
for vec::each(eithers) |elt| {
- alt elt { right(r) { vec::push(result, r); } _ {/* fallthrough */ } }
+ alt elt {
+ right(r) => vec::push(result, r),
+ _ => { /* fallthrough */ }
+ }
}
return result;
}
let mut rights: ~[U] = ~[];
for vec::each(eithers) |elt| {
alt elt {
- left(l) { vec::push(lefts, l); }
- right(r) { vec::push(rights, r); }
+ left(l) => vec::push(lefts, l),
+ right(r) => vec::push(rights, r)
}
}
return {lefts: lefts, rights: rights};
//! Flips between left and right of a given either
alt eith {
- right(r) { left(r) }
- left(l) { right(l) }
+ right(r) => left(r),
+ left(l) => right(l)
}
}
*/
alt eith {
- right(r) { result::ok(r) }
- left(l) { result::err(l) }
+ right(r) => result::ok(r),
+ left(l) => result::err(l)
}
}
pure fn is_left<T, U>(eith: either<T, U>) -> bool {
//! Checks whether the given value is a left
- alt eith { left(_) { true } _ { false } }
+ alt eith { left(_) => true, _ => false }
}
pure fn is_right<T, U>(eith: either<T, U>) -> bool {
//! Checks whether the given value is a right
- alt eith { right(_) { true } _ { false } }
+ alt eith { right(_) => true, _ => false }
}
#[test]
if !('0' as u8 <= c && c <= '9' as u8) { return option::none; }
let n = (c - ('0' as u8)) as uint;
return alt peek_num(s, i + 1u, lim) {
- none { some({num: n, next: i + 1u}) }
- some(next) {
+ none => some({num: n, next: i + 1u}),
+ some(next) => {
let m = next.num;
let j = next.next;
some({num: n * 10u + m, next: j})
if i >= lim { return {param: none, next: i}; }
let num = peek_num(s, i, lim);
return alt num {
- none { {param: none, next: i} }
- some(t) {
+ none => {param: none, next: i},
+ some(t) => {
let n = t.num;
let j = t.next;
if j < lim && s[j] == '$' as u8 {
let param = parse_parameter(s, i + 1u, lim);
let j = param.next;
alt param.param {
- none { {count: count_is_next_param, next: j} }
- some(n) { {count: count_is_param(n), next: j} }
+ none => {count: count_is_next_param, next: j},
+ some(n) => {count: count_is_param(n), next: j}
}
} else {
let num = peek_num(s, i, lim);
alt num {
- none { {count: count_implied, next: i} }
- some(num) {
- {count: count_is(num.num as int), next: num.next}
+ none => {count: count_implied, next: i},
+ some(num) => {
+ count: count_is(num.num as int),
+ next: num.next
}
}
};
// If there were no digits specified, i.e. the precision
// was ".", then the precision is 0
alt count.count {
- count_implied { {count: count_is(0), next: count.next} }
- _ { count }
+ count_implied => {count: count_is(0), next: count.next},
+ _ => count
}
} else { {count: count_implied, next: i} };
}
let prec = get_int_precision(cv);
let mut rs =
alt cv.ty {
- ty_default { uint_to_str_prec(u, 10u, prec) }
- ty_hex_lower { uint_to_str_prec(u, 16u, prec) }
- ty_hex_upper { str::to_upper(uint_to_str_prec(u, 16u, prec)) }
- ty_bits { uint_to_str_prec(u, 2u, prec) }
- ty_octal { uint_to_str_prec(u, 8u, prec) }
+ ty_default => uint_to_str_prec(u, 10u, prec),
+ ty_hex_lower => uint_to_str_prec(u, 16u, prec),
+ ty_hex_upper => str::to_upper(uint_to_str_prec(u, 16u, prec)),
+ ty_bits => uint_to_str_prec(u, 2u, prec),
+ ty_octal => uint_to_str_prec(u, 8u, prec)
};
return unchecked { pad(cv, rs, pad_unsigned) };
}
// For strings, precision is the maximum characters
// displayed
let mut unpadded = alt cv.precision {
- count_implied { s.to_unique() }
- count_is(max) {
- if max as uint < str::char_len(s) {
- str::substr(s, 0u, max as uint)
- } else { s.to_unique() }
+ count_implied => s.to_unique(),
+ count_is(max) => if max as uint < str::char_len(s) {
+ str::substr(s, 0u, max as uint)
+ } else {
+ s.to_unique()
}
};
return unchecked { pad(cv, unpadded, pad_nozero) };
}
pure fn conv_float(cv: conv, f: float) -> ~str {
let (to_str, digits) = alt cv.precision {
- count_is(c) { (float::to_str_exact, c as uint) }
- count_implied { (float::to_str, 6u) }
+ count_is(c) => (float::to_str_exact, c as uint),
+ count_implied => (float::to_str, 6u)
};
let mut s = unchecked { to_str(f, digits) };
if 0.0 <= f {
}
pure fn get_int_precision(cv: conv) -> uint {
return alt cv.precision {
- count_is(c) { c as uint }
- count_implied { 1u }
+ count_is(c) => c as uint,
+ count_implied => 1u
};
}
enum pad_mode { pad_signed, pad_unsigned, pad_nozero, pad_float }
fn pad(cv: conv, &s: ~str, mode: pad_mode) -> ~str {
let uwidth : uint = alt cv.width {
- count_implied { return s; }
- count_is(width) {
+ count_implied => return s,
+ count_is(width) => {
// FIXME: width should probably be uint (see Issue #1996)
width as uint
}
return s + padstr;
}
let {might_zero_pad, signed} = alt mode {
- pad_nozero { {might_zero_pad:false, signed:false} }
- pad_signed { {might_zero_pad:true, signed:true } }
- pad_float { {might_zero_pad:true, signed:true } }
- pad_unsigned { {might_zero_pad:true, signed:false} }
+ pad_nozero => {might_zero_pad:false, signed:false},
+ pad_signed => {might_zero_pad:true, signed:true },
+ pad_float => {might_zero_pad:true, signed:true},
+ pad_unsigned => {might_zero_pad:true, signed:false}
};
pure fn have_precision(cv: conv) -> bool {
- return alt cv.precision { count_implied { false } _ { true } };
+ return alt cv.precision { count_implied => false, _ => true };
}
let zero_padding = {
if might_zero_pad && have_flag(cv.flags, flag_left_zero_pad) &&
//The string must start with one of the following characters.
alt str::char_at(num, 0u) {
- '-' | '+' | '0' to '9' | '.' {}
- _ { return none; }
+ '-' | '+' | '0' to '9' | '.' => (),
+ _ => return none
}
//Determine if first char is '-'/'+'. Set [pos] and [neg] accordingly.
let mut neg = false; //Sign of the result
alt str::char_at(num, 0u) {
- '-' {
+ '-' => {
neg = true;
pos = 1u;
}
- '+' {
+ '+' => {
pos = 1u;
}
- _ {}
+ _ => ()
}
//Examine the following chars until '.', 'e', 'E'
c = char_range.ch;
pos = char_range.next;
alt c {
- '0' to '9' {
+ '0' to '9' => {
total = total * 10f;
total += ((c as int) - ('0' as int)) as float;
}
- '.' | 'e' | 'E' {
- break;
- }
- _ {
- return none;
- }
+ '.' | 'e' | 'E' => break,
+ _ => return none
}
}
c = char_range.ch;
pos = char_range.next;
alt c {
- '0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' {
+ '0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' => {
decimal /= 10f;
total += (((c as int) - ('0' as int)) as float)*decimal;
}
- 'e' | 'E' {
- break;
- }
- _ {
- return none;
- }
+ 'e' | 'E' => break,
+ _ => return none
}
}
}
let char_range = str::char_range_at(num, pos);
c = char_range.ch;
alt c {
- '+' {
+ '+' => {
pos = char_range.next;
}
- '-' {
+ '-' => {
pos = char_range.next;
neg_exponent = true;
}
- _ {}
+ _ => ()
}
while(pos < len) {
let char_range = str::char_range_at(num, pos);
c = char_range.ch;
alt c {
- '0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' {
+ '0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' => {
exponent *= 10u;
exponent += ((c as uint) - ('0' as uint));
}
- _ {
- break;
- }
+ _ => break
}
pos = char_range.next;
}
assert from_str(~"-inf") == some(neg_infinity);
// note: NaN != NaN, hence this slightly complex test
alt from_str(~"NaN") {
- some(f) { assert is_NaN(f); }
- none { fail; }
+ some(f) => assert is_NaN(f),
+ none => fail
}
assert from_str(~"") == none;
port_ <-> *port;
let port = option::unwrap(port_);
alt recv(port) {
- future_pipe::completed(data) { move_it!{data} }
+ future_pipe::completed(data) => move_it!{data}
}
}
}
//! Work with the value without copying it
let v = alt copy future.v {
- either::left(v) { v }
- either::right(f) {
+ either::left(v) => v,
+ either::right(f) => {
let v = @f();
future.v = either::left(v);
v
let mut n = 0 as T;
loop {
alt char::to_digit(buf[i] as char, radix) {
- some(d) { n += (d as T) * power; }
- none { return none; }
+ some(d) => n += (d as T) * power,
+ none => return none
}
power *= radix as T;
if i <= start { return some(n); }
fn convert_whence(whence: seek_style) -> i32 {
return alt whence {
- seek_set { 0i32 }
- seek_cur { 1i32 }
- seek_end { 2i32 }
+ seek_set => 0i32,
+ seek_cur => 1i32,
+ seek_end => 2i32
};
}
let mut fflags: c_int = wb();
for vec::each(flags) |f| {
alt f {
- append { fflags |= O_APPEND as c_int; }
- create { fflags |= O_CREAT as c_int; }
- truncate { fflags |= O_TRUNC as c_int; }
- no_flag { }
+ append => fflags |= O_APPEND as c_int,
+ create => fflags |= O_CREAT as c_int,
+ truncate => fflags |= O_TRUNC as c_int,
+ no_flag => ()
}
}
let fd = do os::as_c_charp(path) |pathbuf| {
fn u64_to_le_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T {
assert size <= 8u;
alt size {
- 1u { f(&[n as u8]) }
- 2u { f(&[n as u8,
- (n >> 8) as u8]) }
- 4u { f(&[n as u8,
+ 1u => f(&[n as u8]),
+ 2u => f(&[n as u8,
+ (n >> 8) as u8]),
+ 4u => f(&[n as u8,
(n >> 8) as u8,
(n >> 16) as u8,
- (n >> 24) as u8]) }
- 8u { f(&[n as u8,
+ (n >> 24) as u8]),
+ 8u => f(&[n as u8,
(n >> 8) as u8,
(n >> 16) as u8,
(n >> 24) as u8,
(n >> 32) as u8,
(n >> 40) as u8,
(n >> 48) as u8,
- (n >> 56) as u8]) }
- _ {
+ (n >> 56) as u8]),
+ _ => {
let mut bytes: ~[u8] = ~[], i = size, n = n;
while i > 0u {
fn u64_to_be_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T {
assert size <= 8u;
alt size {
- 1u { f(&[n as u8]) }
- 2u { f(&[(n >> 8) as u8,
- n as u8]) }
- 4u { f(&[(n >> 24) as u8,
+ 1u => f(&[n as u8]),
+ 2u => f(&[(n >> 8) as u8,
+ n as u8]),
+ 4u => f(&[(n >> 24) as u8,
(n >> 16) as u8,
(n >> 8) as u8,
- n as u8]) }
- 8u { f(&[(n >> 56) as u8,
+ n as u8]),
+ 8u => f(&[(n >> 56) as u8,
(n >> 48) as u8,
(n >> 40) as u8,
(n >> 32) as u8,
(n >> 24) as u8,
(n >> 16) as u8,
(n >> 8) as u8,
- n as u8]) }
- _ {
+ n as u8]),
+ _ => {
let mut bytes: ~[u8] = ~[];
let mut i = size;
while i > 0u {
let mut bpos = pos as int;
let blen = len as int;
alt whence {
- seek_set { bpos = offset; }
- seek_cur { bpos += offset; }
- seek_end { bpos = blen + offset; }
+ seek_set => bpos = offset,
+ seek_cur => bpos += offset,
+ seek_end => bpos = blen + offset
}
if bpos < 0 { bpos = 0; } else if bpos > blen { bpos = blen; }
return bpos as uint;
new(-arg: arg<t>) { self.arg <- arg; }
drop {
alt self.arg.opt_level {
- option::none { }
- option::some(level) {
+ option::none => (),
+ option::some(level) => {
// fail hard if not succesful
assert(self.arg.fsync_fn(self.arg.val, level) != -1);
}
#[test]
fn file_reader_not_exist() {
alt io::file_reader(~"not a file") {
- result::err(e) {
+ result::err(e) => {
assert e == ~"error opening not a file";
}
- result::ok(_) { fail; }
+ result::ok(_) => fail
}
}
#[test]
fn file_writer_bad_name() {
alt io::file_writer(~"?/?", ~[]) {
- result::err(e) {
+ result::err(e) => {
assert str::starts_with(e, ~"error opening ?/?");
}
- result::ok(_) { fail; }
+ result::ok(_) => fail
}
}
#[test]
fn buffered_file_writer_bad_name() {
alt io::buffered_file_writer(~"?/?") {
- result::err(e) {
+ result::err(e) => {
assert e == ~"error opening ?/?";
}
- result::ok(_) { fail; }
+ result::ok(_) => fail
}
}
pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
alt self {
- none { }
- some(a) { f(a); }
+ none => (),
+ some(a) => { f(a); }
}
}
fn SIZE_HINT<A>(self: IMPL_T<A>) -> option<uint> {
alt self {
- none { some(0u) }
- some(_) { some(1u) }
+ none => some(0u),
+ some(_) => some(1u)
}
}
fn min<A:copy,IA:base_iter<A>>(self: IA) -> A {
alt do foldl::<A,option<A>,IA>(self, none) |a, b| {
alt a {
- some(a_) if a_ < b {
+ some(a_) if a_ < b => {
// FIXME (#2005): Not sure if this is successfully optimized to
// a move
a
}
- _ { some(b) }
+ _ => some(b)
}
} {
- some(val) { val }
- none { fail ~"min called on empty iterator" }
+ some(val) => val,
+ none => fail ~"min called on empty iterator"
}
}
fn max<A:copy,IA:base_iter<A>>(self: IA) -> A {
alt do foldl::<A,option<A>,IA>(self, none) |a, b| {
alt a {
- some(a_) if a_ > b {
+ some(a_) if a_ > b => {
// FIXME (#2005): Not sure if this is successfully optimized to
// a move.
a
}
- _ { some(b) }
+ _ => some(b)
}
} {
- some(val) { val }
- none { fail ~"max called on empty iterator" }
+ some(val) => val,
+ none => fail ~"max called on empty iterator"
}
}
* Fails if the value equals `none`
*/
- alt opt { some(x) { return x; } none { fail ~"option::get none"; } }
+ alt opt {
+ some(x) => return x,
+ none => fail ~"option::get none"
+ }
}
pure fn expect<T: copy>(opt: option<T>, reason: ~str) -> T {
Fails if the value equals `none`
"];
- alt opt { some(x) { x } none { fail reason; } }
+ alt opt { some(x) => x, none => fail reason }
}
pure fn map<T, U>(opt: option<T>, f: fn(T) -> U) -> option<U> {
//! Maps a `some` value from one type to another
- alt opt { some(x) { some(f(x)) } none { none } }
+ alt opt { some(x) => some(f(x)), none => none }
}
pure fn map_consume<T, U>(-opt: option<T>, f: fn(-T) -> U) -> option<U> {
* function that returns an option.
*/
- alt opt { some(x) { f(x) } none { none } }
+ alt opt { some(x) => f(x), none => none }
}
#[inline(always)]
pure fn is_none<T>(opt: option<T>) -> bool {
//! Returns true if the option equals `none`
- alt opt { none { true } some(_) { false } }
+ alt opt { none => true, some(_) => false }
}
pure fn is_some<T>(opt: option<T>) -> bool {
pure fn get_default<T: copy>(opt: option<T>, def: T) -> T {
//! Returns the contained value or a default
- alt opt { some(x) { x } none { def } }
+ alt opt { some(x) => x, none => def }
}
pure fn map_default<T, U>(opt: option<T>, +def: U, f: fn(T) -> U) -> U {
//! Applies a function to the contained value or returns a default
- alt opt { none { def } some(t) { f(t) } }
+ alt opt { none => def, some(t) => f(t) }
}
pure fn iter<T>(opt: option<T>, f: fn(T)) {
//! Performs an operation on the contained value or does nothing
- alt opt { none { } some(t) { f(t); } }
+ alt opt { none => (), some(t) => f(t) }
}
#[inline(always)]
unsafe {
let addr = alt opt {
- some(x) { ptr::addr_of(x) }
- none { fail ~"option::unwrap none" }
+ some(x) => ptr::addr_of(x),
+ none => fail ~"option::unwrap none"
};
let liberated_value = unsafe::reinterpret_cast(*addr);
unsafe::forget(opt);
do priv::weaken_task |weak_po| {
loop {
alt comm::select2(msg_po, weak_po) {
- either::left(msg_getenv(n, resp_ch)) {
+ either::left(msg_getenv(n, resp_ch)) => {
comm::send(resp_ch, impl::getenv(n))
}
- either::left(msg_setenv(n, v, resp_ch)) {
+ either::left(msg_setenv(n, v, resp_ch)) => {
comm::send(resp_ch, impl::setenv(n, v))
}
- either::left(msg_env(resp_ch)) {
+ either::left(msg_env(resp_ch)) => {
comm::send(resp_ch, impl::env())
}
- either::right(_) {
- break;
- }
+ either::right(_) => break
}
}
}
import libc::funcs::posix01::unistd::*;
alt level {
io::fsync::fsync
- | io::fsync::fullfsync { return fsync(fd); }
- io::fsync::fdatasync { return fdatasync(fd); }
+ | io::fsync::fullfsync => return fsync(fd),
+ io::fsync::fdatasync => return fdatasync(fd)
}
}
import libc::funcs::posix88::fcntl::*;
import libc::funcs::posix01::unistd::*;
alt level {
- io::fsync::fsync { return fsync(fd); }
- _ {
+ io::fsync::fsync => return fsync(fd),
+ _ => {
// According to man fnctl, the ok retval is only specified to be !=-1
if (fcntl(F_FULLFSYNC as c_int, fd) == -1 as c_int)
{ return -1 as c_int; }
*/
fn homedir() -> option<path> {
return alt getenv(~"HOME") {
- some(p) {
- if !str::is_empty(p) {
- some(p)
- } else {
- secondary()
- }
- }
- none {
- secondary()
+ some(p) => if !str::is_empty(p) {
+ some(p)
+ } else {
+ secondary()
}
+ none => secondary()
};
#[cfg(unix)]
alt str::rfind(pp, |ch|
ch == consts::path_sep || ch == consts::alt_path_sep
) {
- some(i) {
- {dirname: str::slice(pp, 0u, i),
- basename: str::slice(pp, i + 1u, str::len(pp))}
- }
- none { {dirname: ~".", basename: pp} }
+ some(i) => {
+ dirname: str::slice(pp, 0u, i),
+ basename: str::slice(pp, i + 1u, str::len(pp))
+ },
+ none => {dirname: ~".", basename: pp}
}
}
assert self.state != blocked || self.blocked_task != none;
self.blocked_task = none;
alt swap_state_acq(self.state, empty) {
- empty | blocked { }
- terminated { self.state = terminated; }
- full { self.state = full; }
+ empty | blocked => (),
+ terminated => self.state = terminated,
+ full => self.state = full
}
}
p.payload <- some(payload);
let old_state = swap_state_rel(p.header.state, full);
alt old_state {
- empty {
+ empty => {
// Yay, fastpath.
// The receiver will eventually clean this up.
//unsafe { forget(p); }
}
- full { fail ~"duplicate send" }
- blocked {
+ full => fail ~"duplicate send",
+ blocked => {
debug!{"waking up task for %?", p_};
alt p.header.blocked_task {
- some(task) {
- rustrt::task_signal_event(
- task, ptr::addr_of(p.header) as *libc::c_void);
- }
- none { debug!{"just kidding!"} }
+ some(task) => rustrt::task_signal_event(
+ task, ptr::addr_of(p.header) as *libc::c_void),
+ none => debug!{"just kidding!"}
}
// The receiver will eventually clean this up.
//unsafe { forget(p); }
}
- terminated {
+ terminated => {
// The receiver will never receive this. Rely on drop_glue
// to clean everything up.
}
let old_state = swap_state_acq(p.header.state,
blocked);
alt old_state {
- empty {
+ empty => {
debug!{"no data available on %?, going to sleep.", p_};
if count == 0 {
wait_event(this);
}
debug!{"woke up, p.state = %?", copy p.header.state};
}
- blocked {
- if first {
- fail ~"blocking on already blocked packet"
- }
+ blocked => if first {
+ fail ~"blocking on already blocked packet"
}
- full {
+ full => {
let mut payload = none;
payload <-> p.payload;
p.header.blocked_task = none;
p.header.state = empty;
return some(option::unwrap(payload))
}
- terminated {
+ terminated => {
// This assert detects when we've accidentally unsafely
// casted too big of a number to a state.
assert old_state == terminated;
/// Returns true if messages are available.
pure fn peek<T: send, Tb: send>(p: recv_packet_buffered<T, Tb>) -> bool {
alt unsafe {(*p.header()).state} {
- empty { false }
- blocked { fail ~"peeking on blocked packet" }
- full | terminated { true }
+ empty => false,
+ blocked => fail ~"peeking on blocked packet",
+ full | terminated => true
}
}
fn sender_terminate<T: send>(p: *packet<T>) {
let p = unsafe { &*p };
alt swap_state_rel(p.header.state, terminated) {
- empty {
+ empty => {
// The receiver will eventually clean up.
//unsafe { forget(p) }
}
- blocked {
+ blocked => {
// wake up the target
alt p.header.blocked_task {
some(target) =>
// The receiver will eventually clean up.
//unsafe { forget(p) }
}
- full {
+ full => {
// This is impossible
fail ~"you dun goofed"
}
- terminated {
+ terminated => {
// I have to clean up, use drop_glue
}
}
let p = unsafe { &*p };
assert p.header.blocked_task == none;
alt swap_state_rel(p.header.state, terminated) {
- empty {
+ empty => {
// the sender will clean up
//unsafe { forget(p) }
}
- blocked {
+ blocked => {
// this shouldn't happen.
fail ~"terminating a blocked packet"
}
- terminated | full {
+ terminated | full => {
// I have to clean up, use drop_glue
}
}
let p = unsafe { &*p };
let old = p.mark_blocked(this);
alt old {
- full | terminated {
+ full | terminated => {
data_avail = true;
ready_packet = i;
(*p).state = old;
break;
}
- blocked { fail ~"blocking on blocked packet" }
- empty { }
+ blocked => fail ~"blocking on blocked packet",
+ empty => ()
}
}
let pos = vec::position(pkts, |p| p == event);
alt pos {
- some(i) {
+ some(i) => {
ready_packet = i;
data_avail = true;
}
- none {
- debug!{"ignoring spurious event, %?", event};
- }
+ none => debug!{"ignoring spurious event, %?", event}
}
}
unsafe {
alt i {
- 0 { left((try_recv(a), b)) }
- 1 { right((a, try_recv(b))) }
- _ { fail ~"select2 return an invalid packet" }
+ 0 => left((try_recv(a), b)),
+ 1 => right((a, try_recv(b))),
+ _ => fail ~"select2 return an invalid packet"
}
}
}
fn select2i<A: selectable, B: selectable>(a: A, b: B) -> either<(), ()> {
alt wait_many([a.header(), b.header()]/_) {
- 0 { left(()) }
- 1 { right(()) }
- _ { fail ~"wait returned unexpected index" }
+ 0 => left(()),
+ 1 => right(()),
+ _ => fail ~"wait returned unexpected index"
}
}
pure fn header() -> *packet_header {
alt self.p {
- some(packet) {
- unsafe {
- let packet = &*packet;
- let header = ptr::addr_of(packet.header);
- //forget(packet);
- header
- }
+ some(packet) => unsafe {
+ let packet = &*packet;
+ let header = ptr::addr_of(packet.header);
+ //forget(packet);
+ header
}
- none { fail ~"packet already consumed" }
+ none => fail ~"packet already consumed"
}
}
pure fn header() -> *packet_header {
alt self.p {
- some(packet) {
- unsafe {
- let packet = &*packet;
- let header = ptr::addr_of(packet.header);
- //forget(packet);
- header
- }
+ some(packet) => unsafe {
+ let packet = &*packet;
+ let header = ptr::addr_of(packet.header);
+ //forget(packet);
+ header
}
- none { fail ~"packet already consumed" }
+ none => fail ~"packet already consumed"
}
}
let mut endp = none;
endp <-> self.endp;
alt move pipes::try_recv(unwrap(endp)) {
- some(streamp::data(x, endp)) {
+ some(streamp::data(x, endp)) => {
self.endp = some(move_it!{endp});
some(move_it!{x})
}
- none { none }
+ none => none
}
}
let mut endp = none;
endp <-> self.endp;
let peek = alt endp {
- some(endp) {
- pipes::peek(endp)
- }
- none { fail ~"peeking empty stream" }
+ some(endp) => pipes::peek(endp),
+ none => fail ~"peeking empty stream"
};
self.endp <-> endp;
peek
while result == none && ports.len() > 0 {
let i = wait_many(ports.map(|p| p.header()));
alt move ports[i].try_recv() {
- some(copy m) {
+ some(copy m) => {
result = some(move m);
}
- none {
+ none => {
// Remove this port.
let mut ports_ = ~[];
ports <-> ports_;
fn recv() -> T {
match move self.try_recv() {
- some(copy x) { move x }
- none { fail ~"port_set: endpoints closed" }
+ some(copy x) => move x,
+ none => fail ~"port_set: endpoints closed"
}
}
impl<T: send> of selectable for port<T> {
pure fn header() -> *packet_header unchecked {
alt self.endp {
- some(endp) {
- endp.header()
- }
- none { fail ~"peeking empty stream" }
+ some(endp) => endp.header(),
+ none => fail ~"peeking empty stream"
}
}
}
fn select() -> either<T, U> {
alt self {
- (lp, rp) {
- alt select2i(lp, rp) {
- left(()) { left (lp.recv()) }
- right(()) { right(rp.recv()) }
- }
+ (lp, rp) => alt select2i(lp, rp) {
+ left(()) => left (lp.recv()),
+ right(()) => right(rp.recv())
}
}
}
fn try_select() -> either<option<T>, option<U>> {
alt self {
- (lp, rp) {
- alt select2i(lp, rp) {
- left(()) { left (lp.try_recv()) }
- right(()) { right(rp.try_recv()) }
- }
+ (lp, rp) => alt select2i(lp, rp) {
+ left(()) => left (lp.try_recv()),
+ right(()) => right(rp.try_recv())
}
}
}
c1.send(~"abc");
alt (p1, p2).select() {
- right(_) { fail }
- _ { }
+ right(_) => fail,
+ _ => ()
}
c2.send(123);
// Wait to hear if we are the official instance of
// this global task
alt comm::recv::<msg>(setup_po) {
- proceed { f(po); }
- abort { }
+ proceed => f(po),
+ abort => ()
}
};
*/
pure fn get<T: copy, U>(res: result<T, U>) -> T {
alt res {
- ok(t) { t }
- err(the_err) {
- unchecked{ fail fmt!{"get called on error result: %?", the_err}; }
+ ok(t) => t,
+ err(the_err) => unchecked {
+ fail fmt!{"get called on error result: %?", the_err}
}
}
}
*/
pure fn get_err<T, U: copy>(res: result<T, U>) -> U {
alt res {
- err(u) { u }
- ok(_) {
- fail ~"get_error called on ok result";
- }
+ err(u) => u,
+ ok(_) => fail ~"get_error called on ok result"
}
}
/// Returns true if the result is `ok`
pure fn is_ok<T, U>(res: result<T, U>) -> bool {
alt res {
- ok(_) { true }
- err(_) { false }
+ ok(_) => true,
+ err(_) => false
}
}
*/
pure fn to_either<T: copy, U: copy>(res: result<U, T>) -> either<T, U> {
alt res {
- ok(res) { either::right(res) }
- err(fail_) { either::left(fail_) }
+ ok(res) => either::right(res),
+ err(fail_) => either::left(fail_)
}
}
fn chain<T, U: copy, V: copy>(res: result<T, V>, op: fn(T) -> result<U, V>)
-> result<U, V> {
alt res {
- ok(t) { op(t) }
- err(e) { err(e) }
+ ok(t) => op(t),
+ err(e) => err(e)
}
}
op: fn(V) -> result<T, U>)
-> result<T, U> {
alt res {
- ok(t) { ok(t) }
- err(v) { op(v) }
+ ok(t) => ok(t),
+ err(v) => op(v)
}
}
*/
fn iter<T, E>(res: result<T, E>, f: fn(T)) {
alt res {
- ok(t) { f(t) }
- err(_) { }
+ ok(t) => f(t),
+ err(_) => ()
}
}
*/
fn iter_err<T, E>(res: result<T, E>, f: fn(E)) {
alt res {
- ok(_) { }
- err(e) { f(e) }
+ ok(_) => (),
+ err(e) => f(e)
}
}
fn map<T, E: copy, U: copy>(res: result<T, E>, op: fn(T) -> U)
-> result<U, E> {
alt res {
- ok(t) { ok(op(t)) }
- err(e) { err(e) }
+ ok(t) => ok(op(t)),
+ err(e) => err(e)
}
}
fn map_err<T: copy, E, F: copy>(res: result<T, E>, op: fn(E) -> F)
-> result<T, F> {
alt res {
- ok(t) { ok(t) }
- err(e) { err(op(e)) }
+ ok(t) => ok(t),
+ err(e) => err(op(e))
}
}
fn iter(f: fn(T)) {
alt self {
- ok(t) { f(t) }
- err(_) { }
+ ok(t) => f(t),
+ err(_) => ()
}
}
fn iter_err(f: fn(E)) {
alt self {
- ok(_) { }
- err(e) { f(e) }
+ ok(_) => (),
+ err(e) => f(e)
}
}
}
fn map_err<F:copy>(op: fn(E) -> F) -> result<T,F> {
alt self {
- ok(t) { ok(t) }
- err(e) { err(op(e)) }
+ ok(t) => ok(t),
+ err(e) => err(op(e))
}
}
}
fn map<U:copy>(op: fn(T) -> U) -> result<U,E> {
alt self {
- ok(t) { ok(op(t)) }
- err(e) { err(e) }
+ ok(t) => ok(op(t)),
+ err(e) => err(e)
}
}
}
vec::reserve(vs, vec::len(ts));
for vec::each(ts) |t| {
alt op(t) {
- ok(v) { vec::push(vs, v); }
- err(u) { return err(u); }
+ ok(v) => vec::push(vs, v),
+ err(u) => return err(u)
}
}
return ok(vs);
o_t: option<T>, op: fn(T) -> result<V,U>) -> result<option<V>,U> {
alt o_t {
- none { ok(none) }
- some(t) {
- alt op(t) {
- ok(v) { ok(some(v)) }
- err(e) { err(e) }
- }
+ none => ok(none),
+ some(t) => alt op(t) {
+ ok(v) => ok(some(v)),
+ err(e) => err(e)
}
}
}
let mut i = 0u;
while i < n {
alt op(ss[i],ts[i]) {
- ok(v) { vec::push(vs, v); }
- err(u) { return err(u); }
+ ok(v) => vec::push(vs, v),
+ err(u) => return err(u)
}
i += 1u;
}
let mut i = 0u;
while i < n {
alt op(ss[i],ts[i]) {
- ok(()) { }
- err(u) { return err(u); }
+ ok(()) => (),
+ err(u) => return err(u)
}
i += 1u;
}
fn unwrap<T, U>(-res: result<T, U>) -> T {
unsafe {
let addr = alt res {
- ok(x) { ptr::addr_of(x) }
- err(_) { fail ~"error result" }
+ ok(x) => ptr::addr_of(x),
+ err(_) => fail ~"error result"
};
let liberated_value = unsafe::reinterpret_cast(*addr);
unsafe::forget(res);
// On posixy systems we can pass a char** for envp, which is
// a null-terminated array of "k=v\n" strings.
alt env {
- some(es) if !vec::is_empty(es) {
+ some(es) if !vec::is_empty(es) => {
let mut tmps = ~[];
let mut ptrs = ~[];
unsafe { cb(::unsafe::reinterpret_cast(p)) }
)
}
- _ {
- cb(ptr::null())
- }
+ _ => cb(ptr::null())
}
}
// \0 to terminate.
unsafe {
alt env {
- some(es) if !vec::is_empty(es) {
+ some(es) if !vec::is_empty(es) => {
let mut blk : ~[u8] = ~[];
for vec::each(es) |e| {
let (k,v) = e;
blk += ~[0_u8];
vec::as_buf(blk, |p, _len| cb(::unsafe::reinterpret_cast(p)))
}
- _ {
- cb(ptr::null())
- }
+ _ => cb(ptr::null())
}
}
}
fn with_dirp<T>(d: option<~str>,
cb: fn(*libc::c_char) -> T) -> T {
alt d {
- some(dir) { str::as_c_str(dir, cb) }
- none { cb(ptr::null()) }
+ some(dir) => str::as_c_str(dir, cb),
+ none => cb(ptr::null())
}
}
while count > 0 {
let stream = comm::recv(p);
alt check stream {
- (1, s) {
+ (1, s) => {
outs = s;
}
- (2, s) {
+ (2, s) => {
errs = s;
}
};
let _ = for self.bucket_sequence(hash) |i| {
alt buckets[i] {
- some(bkt) {
- if bkt.hash == hash && self.eqfn(k, &bkt.key) {
- return found_entry(i);
- }
- }
- none => {
- return found_hole(i);
+ some(bkt) => if bkt.hash == hash && self.eqfn(k, &bkt.key) {
+ return found_entry(i);
}
+ none => return found_hole(i)
}
};
return table_full;
alt self.bucket_for_key_with_hash(self.buckets, hash,
unsafe{borrow(k)}) {
table_full => {fail ~"Internal logic error";}
- found_hole(idx) {
+ found_hole(idx) => {
debug!{"insert fresh (%?->%?) at idx %?, hash %?",
k, v, idx, hash};
self.buckets[idx] = some({hash: hash, key: k, value: v});
/// Returns a string with leading whitespace removed
pure fn trim_left(s: &str) -> ~str {
alt find(s, |c| !char::is_whitespace(c)) {
- none { ~"" }
- some(first) {
- unsafe { unsafe::slice_bytes(s, first, len(s)) }
- }
+ none => ~"",
+ some(first) => unsafe { unsafe::slice_bytes(s, first, len(s)) }
}
}
/// Returns a string with trailing whitespace removed
pure fn trim_right(s: &str) -> ~str {
alt rfind(s, |c| !char::is_whitespace(c)) {
- none { ~"" }
- some(last) {
+ none => ~"",
+ some(last) => {
let {next, _} = char_range_at(s, last);
unsafe { unsafe::slice_bytes(s, 0u, next) }
}
let mut i = 0;
do chars_iter(~"x\u03c0y") |ch| {
alt check i {
- 0 { assert ch == 'x'; }
- 1 { assert ch == '\u03c0'; }
- 2 { assert ch == 'y'; }
+ 0 => assert ch == 'x',
+ 1 => assert ch == '\u03c0',
+ 2 => assert ch == 'y'
}
i += 1;
}
do bytes_iter(~"xyz") |bb| {
alt check i {
- 0 { assert bb == 'x' as u8; }
- 1 { assert bb == 'y' as u8; }
- 2 { assert bb == 'z' as u8; }
+ 0 => assert bb == 'x' as u8,
+ 1 => assert bb == 'y' as u8,
+ 2 => assert bb == 'z' as u8
}
i += 1;
}
do split_char_iter(data, ' ') |xx| {
alt ii {
- 0 { assert ~"\nMary" == xx; }
- 1 { assert ~"had" == xx; }
- 2 { assert ~"a" == xx; }
- 3 { assert ~"little" == xx; }
- _ { () }
+ 0 => assert ~"\nMary" == xx,
+ 1 => assert ~"had" == xx,
+ 2 => assert ~"a" == xx,
+ 3 => assert ~"little" == xx,
+ _ => ()
}
ii += 1;
}
do splitn_char_iter(data, ' ', 2u) |xx| {
alt ii {
- 0 { assert ~"\nMary" == xx; }
- 1 { assert ~"had" == xx; }
- 2 { assert ~"a little lamb\nLittle lamb\n" == xx; }
- _ { () }
+ 0 => assert ~"\nMary" == xx,
+ 1 => assert ~"had" == xx,
+ 2 => assert ~"a little lamb\nLittle lamb\n" == xx,
+ _ => ()
}
ii += 1;
}
do words_iter(data) |ww| {
alt ii {
- 0 { assert ~"Mary" == ww; }
- 1 { assert ~"had" == ww; }
- 2 { assert ~"a" == ww; }
- 3 { assert ~"little" == ww; }
- _ { () }
+ 0 => assert ~"Mary" == ww,
+ 1 => assert ~"had" == ww,
+ 2 => assert ~"a" == ww,
+ 3 => assert ~"little" == ww,
+ _ => ()
}
ii += 1;
}
do lines_iter(lf) |x| {
alt ii {
- 0 { assert ~"" == x; }
- 1 { assert ~"Mary had a little lamb" == x; }
- 2 { assert ~"Little lamb" == x; }
- 3 { assert ~"" == x; }
- _ { () }
+ 0 => assert ~"" == x,
+ 1 => assert ~"Mary had a little lamb" == x,
+ 2 => assert ~"Little lamb" == x,
+ 3 => assert ~"" == x,
+ _ => ()
}
ii += 1;
}
blk(do future::from_fn {
alt comm::recv(po) {
- exit(_, result) { result }
+ exit(_, result) => result
}
});
comm::send(ch, f());
}
alt future::get(option::unwrap(result)) {
- success { result::ok(comm::recv(po)) }
- failure { result::err(()) }
+ success => result::ok(comm::recv(po)),
+ failure => result::err(())
}
}
* Step 1. Get spawner's taskgroup info.
*######################################################################*/
let spawner_group = alt unsafe { local_get(spawner, taskgroup_key()) } {
- none {
+ none => {
// Main task, doing first spawn ever. Lazily initialise here.
let mut members = new_taskset();
taskset_insert(&mut members, spawner);
unsafe { local_set(spawner, taskgroup_key(), group); }
group
}
- some(group) { group }
+ some(group) => group
};
/*######################################################################*
* Step 2. Process spawn options for child.
// it should be enabled only in debug builds.
let new_generation =
alt *old_ancestors {
- some(arc) { access_ancestors(arc, |a| a.generation+1) }
- none { 0 } // the actual value doesn't really matter.
+ some(arc) => access_ancestors(arc, |a| a.generation+1),
+ none => 0 // the actual value doesn't really matter.
};
assert new_generation < uint::max_value;
// Build a new node in the ancestor list.
let (child_tg, ancestors, f) = option::swap_unwrap(child_data);
// Create child task.
let new_task = alt opts.sched {
- none { rustrt::new_task() }
- some(sched_opts) { new_task_in_new_sched(sched_opts) }
+ none => rustrt::new_task(),
+ some(sched_opts) => new_task_in_new_sched(sched_opts)
};
assert !new_task.is_null();
// Getting killed after here would leak the task.
}
let num_threads = alt opts.mode {
- single_threaded { 1u }
- thread_per_core {
+ single_threaded => 1u,
+ thread_per_core => {
fail ~"thread_per_core scheduling mode unimplemented"
}
- thread_per_task {
+ thread_per_task => {
fail ~"thread_per_task scheduling mode unimplemented"
}
- manual_threads(threads) {
+ manual_threads(threads) => {
if threads == 0u {
fail ~"can not create a scheduler with no threads";
}
threads
}
- osmain { 0u /* Won't be used */ }
+ osmain => 0u /* Won't be used */
};
let sched_id = if opts.mode != osmain {
let key_value = key_to_key_value(key);
let map_pos = (*map).position(|entry|
- alt entry { some((k,_,_)) { k == key_value } none { false } }
+ alt entry {
+ some((k,_,_)) => k == key_value,
+ none => false
+ }
);
do map_pos.map |index| {
// .get() is guaranteed because of "none { false }" above.
let new_entry = some((keyval, data_ptr, data_box));
// Find a place to put it.
alt local_data_lookup(map, key) {
- some((index, _old_data_ptr)) {
+ some((index, _old_data_ptr)) => {
// Key already had a value set, _old_data_ptr, whose reference
// will get dropped when the local_data box is overwritten.
(*map).set_elt(index, new_entry);
}
- none {
+ none => {
// Find an empty slot. If not, grow the vector.
alt (*map).position(|x| x == none) {
- some(empty_index) {
- (*map).set_elt(empty_index, new_entry);
- }
- none {
- (*map).push(new_entry);
- }
+ some(empty_index) => (*map).set_elt(empty_index, new_entry),
+ none => (*map).push(new_entry)
}
}
}
alt do try {
~"Success!"
} {
- result::ok(~"Success!") { }
- _ { fail; }
+ result::ok(~"Success!") => (),
+ _ => fail
}
}
alt do try {
fail
} {
- result::err(()) { }
- result::ok(()) { fail; }
+ result::err(()) => (),
+ result::ok(()) => fail
}
}
fn my_key(+_x: @~str) { }
local_data_modify(my_key, |data| {
alt data {
- some(@val) { fail ~"unwelcome value: " + val }
- none { some(@~"first data") }
+ some(@val) => fail ~"unwelcome value: " + val,
+ none => some(@~"first data")
}
});
local_data_modify(my_key, |data| {
alt data {
- some(@~"first data") { some(@~"next data") }
- some(@val) { fail ~"wrong value: " + val }
- none { fail ~"missing value" }
+ some(@~"first data") => some(@~"next data"),
+ some(@val) => fail ~"wrong value: " + val,
+ none => fail ~"missing value"
}
});
assert *(local_data_pop(my_key).get()) == ~"next data";
let mut n = 0u as T;
loop {
alt char::to_digit(buf[i] as char, radix) {
- some(d) { n += d as T * power; }
- none { return none; }
+ some(d) => n += d as T * power,
+ none => return none
}
power *= radix as T;
if i == 0u { return some(n); }
let mut power = 1u64, n = 0u64;
loop {
alt char::to_digit(buf[i] as char, radix as uint) {
- some(d) { n += d as u64 * power; }
- none { return none; }
+ some(d) => n += d as u64 * power,
+ none => return none
}
power *= radix;
if i == 0u { return some(n); }
pure fn Cc(c: char) -> bool {
return alt c {
'\x00' to '\x1f'
- | '\x7f' to '\x9f'
- { true }
- _ { false }
+ | '\x7f' to '\x9f' => true,
+ _ => false
};
}
| '\ufff9' to '\ufffb'
| '\U000110bd'
| '\U0001d173' to '\U0001d17a'
- | '\U000e0001' to '\U000e007f'
- { true }
- _ { false }
+ | '\U000e0001' to '\U000e007f' => true,
+ _ => false
};
}
pure fn Co(c: char) -> bool {
return alt c {
- '\ue000' to '\uf8ff'
- { true }
- _ { false }
+ '\ue000' to '\uf8ff' => true,
+ _ => false
};
}
pure fn Cs(c: char) -> bool {
return alt c {
- '\ud800' to '\udfff'
- { true }
- _ { false }
+ '\ud800' to '\udfff' => true,
+ _ => false
};
}
| '\U0001d7aa' to '\U0001d7c2'
| '\U0001d7c4' to '\U0001d7c9'
| '\U0001d7cb'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\uaadd'
| '\uff70'
| '\uff9e' to '\uff9f'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\U00012000' to '\U0001236e'
| '\U00013000' to '\U0001b001'
| '\U00020000' to '\U0002fa1d'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\u1fbc'
| '\u1fcc'
| '\u1ffc'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\U0001d756' to '\U0001d76e'
| '\U0001d790' to '\U0001d7a8'
| '\U0001d7ca'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\U000110b7' to '\U000110b8'
| '\U0001d165' to '\U0001d166'
| '\U0001d16d' to '\U0001d172'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\u20dd' to '\u20e0'
| '\u20e2' to '\u20e4'
| '\ua670' to '\ua672'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\U0001d1aa' to '\U0001d1ad'
| '\U0001d242' to '\U0001d244'
| '\U000e0100' to '\U000e01ef'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\U000104a0' to '\U000104a9'
| '\U00011066' to '\U0001106f'
| '\U0001d7ce' to '\U0001d7ff'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\U0001034a'
| '\U000103d1' to '\U000103d5'
| '\U00012400' to '\U00012462'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\U00011052' to '\U00011065'
| '\U0001d360' to '\U0001d371'
| '\U0001f100' to '\U0001f10a'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\ufe33' to '\ufe34'
| '\ufe4d' to '\ufe4f'
| '\uff3f'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\ufe58'
| '\ufe63'
| '\uff0d'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\uff5d'
| '\uff60'
| '\uff63'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\u2e0d'
| '\u2e1d'
| '\u2e21'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\u2e0c'
| '\u2e1c'
| '\u2e20'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\U000110bb' to '\U000110bc'
| '\U000110be' to '\U000110c1'
| '\U00012470' to '\U00012473'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\uff5b'
| '\uff5f'
| '\uff62'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\uff04'
| '\uffe0' to '\uffe1'
| '\uffe5' to '\uffe6'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\uff3e'
| '\uff40'
| '\uffe3'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\U0001d789'
| '\U0001d7a9'
| '\U0001d7c3'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\U0001d245' to '\U0001d356'
| '\U0001f000' to '\U0001f0df'
| '\U0001f110' to '\U0001f773'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
pure fn Zl(c: char) -> bool {
return alt c {
- '\u2028'
- { true }
- _ { false }
+ '\u2028' => true,
+ _ => false
};
}
pure fn Zp(c: char) -> bool {
return alt c {
- '\u2029'
- { true }
- _ { false }
+ '\u2029' => true,
+ _ => false
};
}
| '\u202f'
| '\u205f'
| '\u3000'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\U0002a700' to '\U0002b734'
| '\U0002b740' to '\U0002b81d'
| '\U0002f800' to '\U0002fa1d'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\U0002b740' to '\U0002b81d'
| '\U0002f800' to '\U0002fa1d'
| '\U000e0100' to '\U000e01ef'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
| '\U0002a700' to '\U0002b734'
| '\U0002b740' to '\U0002b81d'
| '\U0002f800' to '\U0002fa1d'
- { true }
- _ { false }
+ => true,
+ _ => false
};
}
let mut result = ~[];
while start < ln {
alt position_between(v, start, ln, f) {
- none { break }
- some(i) {
+ none => break,
+ some(i) => {
push(result, slice(v, start, i));
start = i + 1u;
}
let mut result = ~[];
while start < ln && count > 0u {
alt position_between(v, start, ln, f) {
- none { break }
- some(i) {
+ none => break,
+ some(i) => {
push(result, slice(v, start, i));
// Make sure to skip the separator.
start = i + 1u;
let mut result = ~[];
while end > 0u {
alt rposition_between(v, 0u, end, f) {
- none { break }
- some(i) {
+ none => break,
+ some(i) => {
push(result, slice(v, i + 1u, end));
end = i;
}
let mut result = ~[];
while end > 0u && count > 0u {
alt rposition_between(v, 0u, end, f) {
- none { break }
- some(i) {
+ none => break,
+ some(i) => {
push(result, slice(v, i + 1u, end));
// Make sure to skip the separator.
end = i;
let mut result = ~[];
for each(v) |elem| {
alt f(elem) {
- none {/* no-op */ }
- some(result_elem) { unsafe { push(result, result_elem); } }
+ none => {/* no-op */ }
+ some(result_elem) => unsafe { push(result, result_elem); }
}
}
return result;
}
alt check len % 3u {
- 0u { }
- 1u {
+ 0u => (),
+ 1u => {
let n = (self[i] as uint) << 16u;
str::push_char(s, chars[(n >> 18u) & 63u]);
str::push_char(s, chars[(n >> 12u) & 63u]);
str::push_char(s, '=');
str::push_char(s, '=');
}
- 2u {
+ 2u => {
let n = (self[i] as uint) << 16u | (self[i + 1u] as uint) << 8u;
str::push_char(s, chars[(n >> 18u) & 63u]);
str::push_char(s, chars[(n >> 12u) & 63u]);
n |= 0x3Fu;
} else if ch == '=' {
alt len - i {
- 1u {
+ 1u => {
vec::push(r, ((n >> 16u) & 0xFFu) as u8);
vec::push(r, ((n >> 8u ) & 0xFFu) as u8);
return copy r;
}
- 2u {
+ 2u => {
vec::push(r, ((n >> 10u) & 0xFFu) as u8);
return copy r;
}
- _ {
- fail ~"invalid base64 padding";
- }
+ _ => fail ~"invalid base64 padding"
}
} else {
fail ~"invalid base64 character";
self.die();
}
alt self.rep {
- small(s) {
- alt other.rep {
- small(s1) {
- alt op {
- union { s.union(s1) }
- intersect { s.intersect(s1) }
- assign { s.become(s1) }
- difference { s.difference(s1) }
- }
- }
- big(s1) {
- self.die();
- }
+ small(s) => alt other.rep {
+ small(s1) => alt op {
+ union => s.union(s1),
+ intersect => s.intersect(s1),
+ assign => s.become(s1),
+ difference => s.difference(s1)
+ }
+ big(s1) => self.die()
}
- }
- big(s) {
- alt other.rep {
- small(_) { self.die(); }
- big(s1) {
- alt op {
- union { s.union(s1) }
- intersect { s.intersect(s1) }
- assign { s.become(s1) }
- difference { s.difference(s1) }
- }
- }
+ big(s) => alt other.rep {
+ small(_) => self.die(),
+ big(s1) => alt op {
+ union => s.union(s1),
+ intersect => s.intersect(s1),
+ assign => s.become(s1),
+ difference => s.difference(s1)
}
+ }
}
- }
}
}
#[inline(always)]
fn clone() -> ~bitv {
~alt self.rep {
- small(b) {
+ small(b) => {
bitv{nbits: self.nbits, rep: small(~small_bitv{bits: b.bits})}
}
- big(b) {
+ big(b) => {
let st = to_mut(from_elem(self.nbits / uint_bits + 1, 0));
let len = st.len();
for uint::range(0, len) |i| { st[i] = b.storage[i]; };
pure fn get(i: uint) -> bool {
assert (i < self.nbits);
alt self.rep {
- big(b) { b.get(i) }
- small(s) { s.get(i) }
+ big(b) => b.get(i),
+ small(s) => s.get(i)
}
}
fn set(i: uint, x: bool) {
assert (i < self.nbits);
alt self.rep {
- big(b) { b.set(i, x); }
- small(s) { s.set(i, x); }
+ big(b) => b.set(i, x),
+ small(s) => s.set(i, x)
}
}
fn equal(v1: bitv) -> bool {
if self.nbits != v1.nbits { return false; }
alt self.rep {
- small(b) {
- alt v1.rep {
- small(b1) { b.equals(b1) }
- _ { false }
- }
+ small(b) => alt v1.rep {
+ small(b1) => b.equals(b1),
+ _ => false
}
- big(s) {
- alt v1.rep {
- big(s1) {
- s.equals(s1)
- }
- small(_) { return false; }
- }
+ big(s) => alt v1.rep {
+ big(s1) => s.equals(s1),
+ small(_) => return false
}
}
}
#[inline(always)]
fn clear() {
alt self.rep {
- small(b) { b.clear(); }
- big(s) {
- for s.each_storage() |w| { w = 0u }
- }
+ small(b) => b.clear(),
+ big(s) => for s.each_storage() |w| { w = 0u }
}
}
#[inline(always)]
fn set_all() {
alt self.rep {
- small(b) { b.set_all(); }
- big(s) {
- for s.each_storage() |w| { w = !0u } }
- }
+ small(b) => b.set_all(),
+ big(s) => for s.each_storage() |w| { w = !0u } }
}
/// Invert all bits
#[inline(always)]
fn invert() {
alt self.rep {
- small(b) { b.invert(); }
- big(s) {
- for s.each_storage() |w| { w = !w } }
- }
+ small(b) => b.invert(),
+ big(s) => for s.each_storage() |w| { w = !w } }
}
/**
#[inline(always)]
fn is_true() -> bool {
alt self.rep {
- small(b) { b.is_true() }
- _ {
+ small(b) => b.is_true(),
+ _ => {
for self.each() |i| { if !i { return false; } }
true
}
fn is_false() -> bool {
alt self.rep {
- small(b) { b.is_false() }
- big(_) {
+ small(b) => b.is_false(),
+ big(_) => {
for self.each() |i| { if i { return false; } }
true
}
new(dtor: option<fn@()>) { self.dtor = dtor; }
drop {
alt self.dtor {
- option::none { }
- option::some(f) { f(); }
+ option::none => (),
+ option::some(f) => f()
}
}
}
return rv;
}
fn get<T: copy>(elts: dvec<cell<T>>, i: uint) -> T {
- alt elts.get_elt(i) { some(t) { t } _ { fail } }
+ alt elts.get_elt(i) { some(t) => t, _ => fail }
}
type repr<T> = {mut nelts: uint,
fn intboxeq(&&a: @int, &&b: @int) -> bool { return a == b; }
fn taggyeq(a: taggy, b: taggy) -> bool {
alt a {
- one(a1) {
- alt b { one(b1) {return a1 == b1; } _ { return false; } }
+ one(a1) => alt b {
+ one(b1) => return a1 == b1,
+ _ => return false
}
- two(a1, a2) {
- alt b {
- two(b1, b2) { return a1 == b1 && a2 == b2; }
- _ { return false; }
- }
+ two(a1, a2) => alt b {
+ two(b1, b2) => return a1 == b1 && a2 == b2,
+ _ => return false
}
- three(a1, a2, a3) {
- alt b {
- three(b1, b2, b3) {
- return a1 == b1 && a2 == b2 && a3 == b3;
- }
- _ { return false; }
- }
+ three(a1, a2, a3) => alt b {
+ three(b1, b2, b3) => return a1 == b1 && a2 == b2 && a3 == b3,
+ _ => return false
}
}
}
fn taggypareq<T>(a: taggypar<T>, b: taggypar<T>) -> bool {
alt a {
- onepar::<T>(a1) {
- alt b {
- onepar::<T>(b1) { return a1 == b1; } _ { return false; }
- }
+ onepar::<T>(a1) => alt b {
+ onepar::<T>(b1) => return a1 == b1,
+ _ => return false
}
- twopar::<T>(a1, a2) {
- alt b {
- twopar::<T>(b1, b2) { return a1 == b1 && a2 == b2; }
- _ { return false; }
- }
+ twopar::<T>(a1, a2) => alt b {
+ twopar::<T>(b1, b2) => return a1 == b1 && a2 == b2,
+ _ => return false
}
- threepar::<T>(a1, a2, a3) {
- alt b {
- threepar::<T>(b1, b2, b3) {
- return a1 == b1 && a2 == b2 && a3 == b3;
- }
- _ { return false; }
+ threepar::<T>(a1, a2, a3) => alt b {
+ threepar::<T>(b1, b2, b3) => {
+ return a1 == b1 && a2 == b2 && a3 == b3
}
+ _ => return false
}
}
}
fn get_doc(d: doc, tg: uint) -> doc {
alt maybe_get_doc(d, tg) {
- some(d) { return d; }
- none {
+ some(d) => return d,
+ none => {
error!{"failed to find block with tag %u", tg};
fail;
}
fn write_sized_vuint(w: io::writer, n: uint, size: uint) {
alt size {
- 1u {
- w.write(&[0x80u8 | (n as u8)]);
- }
- 2u {
- w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]);
- }
- 3u {
- w.write(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8,
- n as u8]);
- }
- 4u {
- w.write(&[0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8,
- (n >> 8_u) as u8, n as u8]);
- }
- _ { fail fmt!{"vint to write too big: %?", n}; }
+ 1u => w.write(&[0x80u8 | (n as u8)]),
+ 2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]),
+ 3u => w.write(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8,
+ n as u8]),
+ 4u => w.write(&[0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8,
+ (n >> 8_u) as u8, n as u8]),
+ _ => fail fmt!{"vint to write too big: %?", n}
};
}
fn serialize_0<S: serialization::serializer>(s: S, v: option<int>) {
do s.emit_enum(~"core::option::t") {
alt v {
- none {
- s.emit_enum_variant(~"core::option::none", 0u, 0u, || { } );
- }
- some(v0) {
+ none => s.emit_enum_variant(
+ ~"core::option::none", 0u, 0u, || { } ),
+ some(v0) => {
do s.emit_enum_variant(~"core::option::some", 1u, 1u) {
s.emit_enum_variant_arg(0u, || serialize_1(s, v0));
}
do s.read_enum(~"core::option::t") {
do s.read_enum_variant |i| {
alt check i {
- 0u { none }
- 1u {
+ 0u => none,
+ 1u => {
let v0 = do s.read_enum_variant_arg(0u) {
deserialize_1(s)
};
/// Insert a value into the map
fn insert<K: copy, V: copy>(m: treemap<K, V>, k: K, v: V) -> treemap<K, V> {
@alt m {
- @empty { node(@k, @v, @empty, @empty) }
- @node(@kk, vv, left, right) {
+ @empty => node(@k, @v, @empty, @empty),
+ @node(@kk, vv, left, right) => {
if k < kk {
node(@kk, vv, insert(left, k, v), right)
} else if k == kk {
/// Find a value based on the key
fn find<K, V: copy>(m: treemap<K, V>, k: K) -> option<V> {
alt *m {
- empty { none }
- node(@kk, @v, left, right) {
+ empty => none,
+ node(@kk, @v, left, right) => {
if k == kk {
some(v)
} else if k < kk { find(left, k) } else { find(right, k) }
/// Visit all pairs in the map in order.
fn traverse<K, V: copy>(m: treemap<K, V>, f: fn(K, V)) {
alt *m {
- empty { }
+ empty => (),
/*
Previously, this had what looked like redundant
matches to me, so I changed it. but that may be a
de-optimization -- tjc
*/
- node(@k, @v, left, right) {
+ node(@k, @v, left, right) => {
// copy v to make aliases work out
let v1 = v;
traverse(left, f);
}
fn name_str(nm: name) -> ~str {
- return alt nm { short(ch) { str::from_char(ch) } long(s) { s } };
+ return alt nm {
+ short(ch) => str::from_char(ch),
+ long(s) => s
+ };
}
fn find_opt(opts: ~[opt], nm: name) -> option<uint> {
/// Convert a `fail_` enum into an error string
fn fail_str(f: fail_) -> ~str {
return alt f {
- argument_missing(nm) {
- ~"Argument to option '" + nm + ~"' missing."
- }
- unrecognized_option(nm) { ~"Unrecognized option: '" + nm + ~"'." }
- option_missing(nm) { ~"Required option '" + nm + ~"' missing." }
- option_duplicated(nm) {
- ~"Option '" + nm + ~"' given more than once."
- }
- unexpected_argument(nm) {
- ~"Option " + nm + ~" does not take an argument."
- }
- };
+ argument_missing(nm) => ~"Argument to option '" + nm + ~"' missing.",
+ unrecognized_option(nm) => ~"Unrecognized option: '" + nm + ~"'.",
+ option_missing(nm) => ~"Required option '" + nm + ~"' missing.",
+ option_duplicated(nm) => ~"Option '" + nm + ~"' given more than once.",
+ unexpected_argument(nm) => {
+ ~"Option " + nm + ~" does not take an argument."
+ }
+ };
}
/**
*/
alt find_opt(opts, opt) {
- some(id) {
- last_valid_opt_id = option::some(id);
- }
- none {
+ some(id) => last_valid_opt_id = option::some(id),
+ none => {
let arg_follows =
option::is_some(last_valid_opt_id) &&
alt opts[option::get(last_valid_opt_id)].hasarg {
- yes | maybe { true }
- no { false }
+ yes | maybe => true,
+ no => false
};
if arg_follows && j + 1 < curlen {
i_arg = option::some(str::slice(cur, j, curlen));
for vec::each(names) |nm| {
name_pos += 1u;
let optid = alt find_opt(opts, nm) {
- some(id) { id }
- none { return err(unrecognized_option(name_str(nm))); }
+ some(id) => id,
+ none => return err(unrecognized_option(name_str(nm)))
};
alt opts[optid].hasarg {
- no {
+ no => {
if !option::is_none::<~str>(i_arg) {
return err(unexpected_argument(name_str(nm)));
}
vec::push(vals[optid], given);
}
- maybe {
+ maybe => {
if !option::is_none::<~str>(i_arg) {
vec::push(vals[optid], val(option::get(i_arg)));
} else if name_pos < vec::len::<name>(names) ||
vec::push(vals[optid], given);
} else { i += 1u; vec::push(vals[optid], val(args[i])); }
}
- yes {
+ yes => {
if !option::is_none::<~str>(i_arg) {
vec::push(vals[optid],
val(option::get::<~str>(i_arg)));
fn opt_vals(m: matches, nm: ~str) -> ~[optval] {
return alt find_opt(m.opts, mkname(nm)) {
- some(id) { m.vals[id] }
- none { error!{"No option '%s' defined", nm}; fail }
- };
+ some(id) => m.vals[id],
+ none => {
+ error!{"No option '%s' defined", nm};
+ fail
+ }
+ };
}
fn opt_val(m: matches, nm: ~str) -> optval { return opt_vals(m, nm)[0]; }
fn opts_present(m: matches, names: ~[~str]) -> bool {
for vec::each(names) |nm| {
alt find_opt(m.opts, mkname(nm)) {
- some(_) { return true; }
- _ { }
+ some(_) => return true,
+ _ => ()
}
}
return false;
* argument
*/
fn opt_str(m: matches, nm: ~str) -> ~str {
- return alt opt_val(m, nm) { val(s) { s } _ { fail } };
+ return alt opt_val(m, nm) { val(s) => s, _ => fail };
}
/**
fn opts_str(m: matches, names: ~[~str]) -> ~str {
for vec::each(names) |nm| {
alt opt_val(m, nm) {
- val(s) { return s }
- _ { }
+ val(s) => return s,
+ _ => ()
}
}
fail;
fn opt_strs(m: matches, nm: ~str) -> ~[~str] {
let mut acc: ~[~str] = ~[];
for vec::each(opt_vals(m, nm)) |v| {
- alt v { val(s) { vec::push(acc, s); } _ { } }
+ alt v { val(s) => vec::push(acc, s), _ => () }
}
return acc;
}
fn opt_maybe_str(m: matches, nm: ~str) -> option<~str> {
let vals = opt_vals(m, nm);
if vec::len::<optval>(vals) == 0u { return none::<~str>; }
- return alt vals[0] { val(s) { some::<~str>(s) } _ { none::<~str> } };
+ return alt vals[0] { val(s) => some::<~str>(s), _ => none::<~str> };
}
fn opt_default(m: matches, nm: ~str, def: ~str) -> option<~str> {
let vals = opt_vals(m, nm);
if vec::len::<optval>(vals) == 0u { return none::<~str>; }
- return alt vals[0] { val(s) { some::<~str>(s) } _ { some::<~str>(def) } }
+ return alt vals[0] { val(s) => some::<~str>(s), _ => some::<~str>(def) }
}
#[cfg(test)]
fn check_fail_type(f: fail_, ft: fail_type) {
alt f {
- argument_missing(_) { assert (ft == argument_missing_); }
- unrecognized_option(_) { assert (ft == unrecognized_option_); }
- option_missing(_) { assert (ft == option_missing_); }
- option_duplicated(_) { assert (ft == option_duplicated_); }
- unexpected_argument(_) { assert (ft == unexpected_argument_); }
+ argument_missing(_) => assert ft == argument_missing_,
+ unrecognized_option(_) => assert ft == unrecognized_option_,
+ option_missing(_) => assert ft == option_missing_,
+ option_duplicated(_) => assert ft == option_duplicated_,
+ unexpected_argument(_) => assert ft == unexpected_argument_
}
}
let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts);
alt check rs {
- ok(m) {
+ ok(m) => {
assert (opt_present(m, ~"test"));
assert (opt_str(m, ~"test") == ~"20");
}
let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, option_missing_); }
- _ { fail; }
+ err(f) => check_fail_type(f, option_missing_),
+ _ => fail
}
}
let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, argument_missing_); }
- _ { fail; }
+ err(f) => check_fail_type(f, argument_missing_),
+ _ => fail
}
}
let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, option_duplicated_); }
- _ { fail; }
+ err(f) => check_fail_type(f, option_duplicated_),
+ _ => fail
}
}
let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts);
alt rs {
- ok(m) {
+ ok(m) => {
assert (opt_present(m, ~"t"));
assert (opt_str(m, ~"t") == ~"20");
}
- _ { fail; }
+ _ => fail
}
}
let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, option_missing_); }
- _ { fail; }
+ err(f) => check_fail_type(f, option_missing_),
+ _ => fail
}
}
let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, argument_missing_); }
- _ { fail; }
+ err(f) => check_fail_type(f, argument_missing_),
+ _ => fail
}
}
let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, option_duplicated_); }
- _ { fail; }
+ err(f) => check_fail_type(f, option_duplicated_),
+ _ => fail
}
}
let opts = ~[optopt(~"test")];
let rs = getopts(args, opts);
alt rs {
- ok(m) {
+ ok(m) => {
assert (opt_present(m, ~"test"));
assert (opt_str(m, ~"test") == ~"20");
}
- _ { fail; }
+ _ => fail
}
}
let opts = ~[optopt(~"test")];
let rs = getopts(args, opts);
alt rs {
- ok(m) { assert (!opt_present(m, ~"test")); }
- _ { fail; }
+ ok(m) => assert (!opt_present(m, ~"test")),
+ _ => fail
}
}
let opts = ~[optopt(~"test")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, argument_missing_); }
- _ { fail; }
+ err(f) => check_fail_type(f, argument_missing_),
+ _ => fail
}
}
let opts = ~[optopt(~"test")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, option_duplicated_); }
- _ { fail; }
+ err(f) => check_fail_type(f, option_duplicated_),
+ _ => fail
}
}
let opts = ~[optopt(~"t")];
let rs = getopts(args, opts);
alt rs {
- ok(m) {
+ ok(m) => {
assert (opt_present(m, ~"t"));
assert (opt_str(m, ~"t") == ~"20");
}
- _ { fail; }
+ _ => fail
}
}
let opts = ~[optopt(~"t")];
let rs = getopts(args, opts);
alt rs {
- ok(m) { assert (!opt_present(m, ~"t")); }
- _ { fail; }
+ ok(m) => assert (!opt_present(m, ~"t")),
+ _ => fail
}
}
let opts = ~[optopt(~"t")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, argument_missing_); }
- _ { fail; }
+ err(f) => check_fail_type(f, argument_missing_),
+ _ => fail
}
}
let opts = ~[optopt(~"t")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, option_duplicated_); }
- _ { fail; }
+ err(f) => check_fail_type(f, option_duplicated_),
+ _ => fail
}
}
let opts = ~[optflag(~"test")];
let rs = getopts(args, opts);
alt rs {
- ok(m) { assert (opt_present(m, ~"test")); }
- _ { fail; }
+ ok(m) => assert (opt_present(m, ~"test")),
+ _ => fail
}
}
let opts = ~[optflag(~"test")];
let rs = getopts(args, opts);
alt rs {
- ok(m) { assert (!opt_present(m, ~"test")); }
- _ { fail; }
+ ok(m) => assert (!opt_present(m, ~"test")),
+ _ => fail
}
}
let opts = ~[optflag(~"test")];
let rs = getopts(args, opts);
alt rs {
- err(f) {
+ err(f) => {
log(error, fail_str(f));
check_fail_type(f, unexpected_argument_);
}
- _ { fail; }
+ _ => fail
}
}
let opts = ~[optflag(~"test")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, option_duplicated_); }
- _ { fail; }
+ err(f) => check_fail_type(f, option_duplicated_),
+ _ => fail
}
}
let opts = ~[optflag(~"t")];
let rs = getopts(args, opts);
alt rs {
- ok(m) { assert (opt_present(m, ~"t")); }
- _ { fail; }
+ ok(m) => assert (opt_present(m, ~"t")),
+ _ => fail
}
}
let opts = ~[optflag(~"t")];
let rs = getopts(args, opts);
alt rs {
- ok(m) { assert (!opt_present(m, ~"t")); }
- _ { fail; }
+ ok(m) => assert (!opt_present(m, ~"t")),
+ _ => fail
}
}
let opts = ~[optflag(~"t")];
let rs = getopts(args, opts);
alt rs {
- ok(m) {
+ ok(m) => {
// The next variable after the flag is just a free argument
assert (m.free[0] == ~"20");
}
- _ { fail; }
+ _ => fail
}
}
let opts = ~[optflag(~"t")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, option_duplicated_); }
- _ { fail; }
+ err(f) => check_fail_type(f, option_duplicated_),
+ _ => fail
}
}
let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts);
alt rs {
- ok(m) {
+ ok(m) => {
assert (opt_present(m, ~"test"));
assert (opt_str(m, ~"test") == ~"20");
}
- _ { fail; }
+ _ => fail
}
}
let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts);
alt rs {
- ok(m) { assert (!opt_present(m, ~"test")); }
- _ { fail; }
+ ok(m) => assert (!opt_present(m, ~"test")),
+ _ => fail
}
}
let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, argument_missing_); }
- _ { fail; }
+ err(f) => check_fail_type(f, argument_missing_),
+ _ => fail
}
}
let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts);
alt rs {
- ok(m) {
+ ok(m) => {
assert (opt_present(m, ~"test"));
assert (opt_str(m, ~"test") == ~"20");
assert (opt_strs(m, ~"test")[0] == ~"20");
assert (opt_strs(m, ~"test")[1] == ~"30");
}
- _ { fail; }
+ _ => fail
}
}
let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts);
alt rs {
- ok(m) {
+ ok(m) => {
assert (opt_present(m, ~"t"));
assert (opt_str(m, ~"t") == ~"20");
}
- _ { fail; }
+ _ => fail
}
}
let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts);
alt rs {
- ok(m) { assert (!opt_present(m, ~"t")); }
- _ { fail; }
+ ok(m) => assert (!opt_present(m, ~"t")),
+ _ => fail
}
}
let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, argument_missing_); }
- _ { fail; }
+ err(f) => check_fail_type(f, argument_missing_),
+ _ => fail
}
}
let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts);
alt rs {
- ok(m) {
+ ok(m) => {
assert (opt_present(m, ~"t"));
assert (opt_str(m, ~"t") == ~"20");
assert (opt_strs(m, ~"t")[0] == ~"20");
assert (opt_strs(m, ~"t")[1] == ~"30");
}
- _ { fail; }
+ _ => fail
}
}
let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, unrecognized_option_); }
- _ { fail; }
+ err(f) => check_fail_type(f, unrecognized_option_),
+ _ => fail
}
}
let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts);
alt rs {
- err(f) { check_fail_type(f, unrecognized_option_); }
- _ { fail; }
+ err(f) => check_fail_type(f, unrecognized_option_),
+ _ => fail
}
}
optopt(~"notpresent")];
let rs = getopts(args, opts);
alt rs {
- ok(m) {
+ ok(m) => {
assert (m.free[0] == ~"prog");
assert (m.free[1] == ~"free1");
assert (opt_str(m, ~"s") == ~"20");
assert (opt_strs(m, ~"n")[1] == ~"-60 70");
assert (!opt_present(m, ~"notpresent"));
}
- _ { fail; }
+ _ => fail
}
}
let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"];
let opts = ~[optopt(~"e"), optopt(~"encrypt")];
let matches = alt getopts(args, opts) {
- result::ok(m) { m }
- result::err(f) { fail; }
+ result::ok(m) => m,
+ result::err(f) => fail
};
assert opts_present(matches, ~[~"e"]);
assert opts_present(matches, ~[~"encrypt"]);
let args = ~[~"-Lfoo"];
let opts = ~[optmulti(~"L")];
let matches = alt getopts(args, opts) {
- result::ok(m) { m }
- result::err(f) { fail; }
+ result::ok(m) => m,
+ result::err(f) => fail
};
assert opts_present(matches, ~[~"L"]);
assert opts_str(matches, ~[~"L"]) == ~"foo";
/// Serializes a json value into a io::writer
fn to_writer(wr: io::writer, j: json) {
alt j {
- num(n) { wr.write_str(float::to_str(n, 6u)); }
- string(s) {
- wr.write_str(escape_str(*s));
- }
- boolean(b) {
- wr.write_str(if b { ~"true" } else { ~"false" });
- }
- list(v) {
+ num(n) => wr.write_str(float::to_str(n, 6u)),
+ string(s) => wr.write_str(escape_str(*s)),
+ boolean(b) => wr.write_str(if b { ~"true" } else { ~"false" }),
+ list(v) => {
wr.write_char('[');
let mut first = true;
for (*v).each |item| {
};
wr.write_char(']');
}
- dict(d) {
+ dict(d) => {
if d.size() == 0u {
wr.write_str(~"{}");
return;
};
wr.write_str(~" }");
}
- null {
- wr.write_str(~"null");
- }
+ null => wr.write_str(~"null")
}
}
let mut escaped = ~"\"";
do str::chars_iter(s) |c| {
alt c {
- '"' { escaped += ~"\\\""; }
- '\\' { escaped += ~"\\\\"; }
- '\x08' { escaped += ~"\\b"; }
- '\x0c' { escaped += ~"\\f"; }
- '\n' { escaped += ~"\\n"; }
- '\r' { escaped += ~"\\r"; }
- '\t' { escaped += ~"\\t"; }
- _ { escaped += str::from_char(c); }
+ '"' => escaped += ~"\\\"",
+ '\\' => escaped += ~"\\\\",
+ '\x08' => escaped += ~"\\b",
+ '\x0c' => escaped += ~"\\f",
+ '\n' => escaped += ~"\\n",
+ '\r' => escaped += ~"\\r",
+ '\t' => escaped += ~"\\t",
+ _ => escaped += str::from_char(c)
}
};
fn parse() -> result<json, error> {
alt self.parse_value() {
- ok(value) {
+ ok(value) => {
// Skip trailing whitespaces.
self.parse_whitespace();
// Make sure there is no trailing characters.
self.error(~"trailing characters")
}
}
- e { e }
+ e => e
}
}
if self.eof() { return self.error(~"EOF while parsing value"); }
alt self.ch {
- 'n' { self.parse_ident(~"ull", null) }
- 't' { self.parse_ident(~"rue", boolean(true)) }
- 'f' { self.parse_ident(~"alse", boolean(false)) }
- '0' to '9' | '-' { self.parse_number() }
- '"' {
- alt self.parse_str() {
- ok(s) { ok(string(s)) }
- err(e) { err(e) }
- }
+ 'n' => self.parse_ident(~"ull", null),
+ 't' => self.parse_ident(~"rue", boolean(true)),
+ 'f' => self.parse_ident(~"alse", boolean(false)),
+ '0' to '9' | '-' => self.parse_number(),
+ '"' => alt self.parse_str() {
+ ok(s) => ok(string(s)),
+ err(e) => err(e)
}
- '[' { self.parse_list() }
- '{' { self.parse_object() }
- _ { self.error(~"invalid syntax") }
+ '[' => self.parse_list(),
+ '{' => self.parse_object(),
+ _ => self.error(~"invalid syntax")
}
}
}
let mut res = alt self.parse_integer() {
- ok(res) { res }
- err(e) { return err(e); }
+ ok(res) => res,
+ err(e) => return err(e)
};
if self.ch == '.' {
alt self.parse_decimal(res) {
- ok(r) { res = r; }
- err(e) { return err(e); }
+ ok(r) => res = r,
+ err(e) => return err(e)
}
}
if self.ch == 'e' || self.ch == 'E' {
alt self.parse_exponent(res) {
- ok(r) { res = r; }
- err(e) { return err(e); }
+ ok(r) => res = r,
+ err(e) => return err(e)
}
}
let mut res = 0f;
alt self.ch {
- '0' {
+ '0' => {
self.bump();
// There can be only one leading '0'.
alt self.ch {
- '0' to '9' { return self.error(~"invalid number"); }
- _ {}
+ '0' to '9' => return self.error(~"invalid number"),
+ _ => ()
}
}
- '1' to '9' {
+ '1' to '9' => {
while !self.eof() {
alt self.ch {
- '0' to '9' {
+ '0' to '9' => {
res *= 10f;
res += ((self.ch as int) - ('0' as int)) as float;
self.bump();
}
- _ { break; }
+ _ => break
}
}
}
- _ { return self.error(~"invalid number"); }
+ _ => return self.error(~"invalid number")
}
ok(res)
// Make sure a digit follows the decimal place.
alt self.ch {
- '0' to '9' {}
- _ { return self.error(~"invalid number"); }
+ '0' to '9' => (),
+ _ => return self.error(~"invalid number")
}
let mut res = res;
let mut dec = 1f;
while !self.eof() {
alt self.ch {
- '0' to '9' {
+ '0' to '9' => {
dec /= 10f;
res += (((self.ch as int) - ('0' as int)) as float) * dec;
self.bump();
}
- _ { break; }
+ _ => break
}
}
let mut neg_exp = false;
alt self.ch {
- '+' { self.bump(); }
- '-' { self.bump(); neg_exp = true; }
- _ {}
+ '+' => self.bump(),
+ '-' => { self.bump(); neg_exp = true; }
+ _ => ()
}
// Make sure a digit follows the exponent place.
alt self.ch {
- '0' to '9' {}
- _ { return self.error(~"invalid number"); }
+ '0' to '9' => (),
+ _ => return self.error(~"invalid number")
}
while !self.eof() {
alt self.ch {
- '0' to '9' {
+ '0' to '9' => {
exp *= 10u;
exp += (self.ch as uint) - ('0' as uint);
self.bump();
}
- _ { break; }
+ _ => break
}
}
if (escape) {
alt self.ch {
- '"' { str::push_char(res, '"'); }
- '\\' { str::push_char(res, '\\'); }
- '/' { str::push_char(res, '/'); }
- 'b' { str::push_char(res, '\x08'); }
- 'f' { str::push_char(res, '\x0c'); }
- 'n' { str::push_char(res, '\n'); }
- 'r' { str::push_char(res, '\r'); }
- 't' { str::push_char(res, '\t'); }
- 'u' {
+ '"' => str::push_char(res, '"'),
+ '\\' => str::push_char(res, '\\'),
+ '/' => str::push_char(res, '/'),
+ 'b' => str::push_char(res, '\x08'),
+ 'f' => str::push_char(res, '\x0c'),
+ 'n' => str::push_char(res, '\n'),
+ 'r' => str::push_char(res, '\r'),
+ 't' => str::push_char(res, '\t'),
+ 'u' => {
// Parse \u1234.
let mut i = 0u;
let mut n = 0u;
while i < 4u {
alt self.next_char() {
- '0' to '9' {
+ '0' to '9' => {
n = n * 10u +
(self.ch as uint) - ('0' as uint);
}
- _ { return self.error(~"invalid \\u escape"); }
+ _ => return self.error(~"invalid \\u escape")
}
i += 1u;
}
str::push_char(res, n as char);
}
- _ { return self.error(~"invalid escape"); }
+ _ => return self.error(~"invalid escape")
}
escape = false;
} else if self.ch == '\\' {
loop {
alt self.parse_value() {
- ok(v) { vec::push(values, v); }
- e { return e; }
+ ok(v) => vec::push(values, v),
+ e => return e
}
self.parse_whitespace();
}
alt self.ch {
- ',' { self.bump(); }
- ']' { self.bump(); return ok(list(@values)); }
- _ { return self.error(~"expected `,` or `]`"); }
+ ',' => self.bump(),
+ ']' => { self.bump(); return ok(list(@values)); }
+ _ => return self.error(~"expected `,` or `]`")
}
};
}
}
let key = alt self.parse_str() {
- ok(key) { key }
- err(e) { return err(e); }
+ ok(key) => key,
+ err(e) => return err(e)
};
self.parse_whitespace();
self.bump();
alt self.parse_value() {
- ok(value) { values.insert(copy *key, value); }
- e { return e; }
+ ok(value) => { values.insert(copy *key, value); }
+ e => return e
}
self.parse_whitespace();
alt self.ch {
- ',' { self.bump(); }
- '}' { self.bump(); return ok(dict(values)); }
- _ {
+ ',' => self.bump(),
+ '}' => { self.bump(); return ok(dict(values)); }
+ _ => {
if self.eof() { break; }
return self.error(~"expected `,` or `}`");
}
/// Test if two json values are equal
fn eq(value0: json, value1: json) -> bool {
alt (value0, value1) {
- (num(f0), num(f1)) { f0 == f1 }
- (string(s0), string(s1)) { s0 == s1 }
- (boolean(b0), boolean(b1)) { b0 == b1 }
- (list(l0), list(l1)) { vec::all2(*l0, *l1, eq) }
- (dict(d0), dict(d1)) {
+ (num(f0), num(f1)) => f0 == f1,
+ (string(s0), string(s1)) => s0 == s1,
+ (boolean(b0), boolean(b1)) => b0 == b1,
+ (list(l0), list(l1)) => vec::all2(*l0, *l1, eq),
+ (dict(d0), dict(d1)) => {
if d0.size() == d1.size() {
let mut equal = true;
for d0.each |k, v0| {
alt d1.find(k) {
- some(v1) {
- if !eq(v0, v1) { equal = false; } }
- none { equal = false; }
+ some(v1) => if !eq(v0, v1) { equal = false },
+ none => equal = false
}
};
equal
false
}
}
- (null, null) { true }
- _ { false }
+ (null, null) => true,
+ _ => false
}
}
impl <A: to_json> of to_json for option<A> {
fn to_json() -> json {
alt self {
- none { null }
- some(value) { value.to_json() }
+ none => null,
+ some(value) => value.to_json()
}
}
}
let mut ls = ls;
loop {
ls = alt *ls {
- cons(hd, tl) {
+ cons(hd, tl) => {
if f(hd) { return some(hd); }
tl
}
- nil { return none; }
+ nil => return none
}
};
}
/// Returns true if the list is empty
pure fn is_empty<T: copy>(ls: @list<T>) -> bool {
alt *ls {
- nil { true }
- _ { false }
+ nil => true,
+ _ => false
}
}
/// Returns all but the first element of a list
pure fn tail<T: copy>(ls: @list<T>) -> @list<T> {
alt *ls {
- cons(_, tl) { return tl; }
- nil { fail ~"list empty" }
+ cons(_, tl) => return tl,
+ nil => fail ~"list empty"
}
}
/// Returns the first element of a list
pure fn head<T: copy>(ls: @list<T>) -> T {
- alt check *ls { cons(hd, _) { hd } }
+ alt check *ls { cons(hd, _) => hd }
}
/// Appends one list to another
pure fn append<T: copy>(l: @list<T>, m: @list<T>) -> @list<T> {
alt *l {
- nil { return m; }
- cons(x, xs) { let rest = append(xs, m); return @cons(x, rest); }
+ nil => return m,
+ cons(x, xs) => {
+ let rest = append(xs, m);
+ return @cons(x, rest);
+ }
}
}
let mut cur = l;
loop {
cur = alt *cur {
- cons(hd, tl) {
+ cons(hd, tl) => {
f(hd);
tl
}
- nil { break; }
+ nil => break
}
}
}
let mut cur = l;
loop {
cur = alt *cur {
- cons(hd, tl) {
+ cons(hd, tl) => {
if !f(hd) { return; }
tl
}
- nil { break; }
+ nil => break
}
}
}
let mut comp = 1u; // for logging
loop {
alt copy e0.next {
- none {
+ none => {
debug!{"search_tbl: absent, comp %u, hash %u, idx %u",
comp, h, idx};
return not_found;
}
- some(e1) {
+ some(e1) => {
comp += 1u;
if e1.hash == h && self.eqer(&e1.key, k) {
debug!{"search_tbl: present, comp %u, \
fn search_tbl(k: &K, h: uint) -> search_result<K,V> {
let idx = h % vec::len(self.chains);
alt copy self.chains[idx] {
- none {
+ none => {
debug!{"search_tbl: none, comp %u, hash %u, idx %u",
0u, h, idx};
return not_found;
}
- some(e) {
+ some(e) => {
if e.hash == h && self.eqer(&e.key, k) {
debug!{"search_tbl: present, comp %u, hash %u, idx %u",
1u, h, idx};
let mut chain = self.chains[i];
loop {
chain = alt chain {
- none { break; }
- some(entry) {
+ none => break,
+ some(entry) => {
let next = entry.next;
if !blk(entry) { return; }
next
fn contains_key_ref(k: &K) -> bool {
let hash = self.hasher(k);
alt self.search_tbl(k, hash) {
- not_found {false}
- found_first(*) | found_after(*) {true}
+ not_found => false,
+ found_first(*) | found_after(*) => true
}
}
fn insert(+k: K, +v: V) -> bool {
let hash = self.hasher(&k);
alt self.search_tbl(&k, hash) {
- not_found {
+ not_found => {
self.count += 1u;
let idx = hash % vec::len(self.chains);
let old_chain = self.chains[idx];
return true;
}
- found_first(idx, entry) {
+ found_first(idx, entry) => {
self.chains[idx] = some(@entry {
hash: hash,
key: k,
next: entry.next});
return false;
}
- found_after(prev, entry) {
+ found_after(prev, entry) => {
prev.next = some(@entry {
hash: hash,
key: k,
fn find(+k: K) -> option<V> {
alt self.search_tbl(&k, self.hasher(&k)) {
- not_found {none}
- found_first(_, entry) {some(entry.value)}
- found_after(_, entry) {some(entry.value)}
+ not_found => none,
+ found_first(_, entry) => some(entry.value),
+ found_after(_, entry) => some(entry.value)
}
}
fn remove(+k: K) -> option<V> {
alt self.search_tbl(&k, self.hasher(&k)) {
- not_found {none}
- found_first(idx, entry) {
+ not_found => none,
+ found_first(idx, entry) => {
self.count -= 1u;
self.chains[idx] = entry.next;
some(entry.value)
}
- found_after(eprev, entry) {
+ found_after(eprev, entry) => {
self.count -= 1u;
eprev.next = entry.next;
some(entry.value)
while i < num_to_insert {
let v = hm.remove(i);
alt v {
- option::some(u) { assert (u == i * i); }
- option::none { fail; }
+ option::some(u) => assert (u == i * i),
+ option::none => fail
}
i += 2u;
}
*/
fn format_addr(ip: ip_addr) -> ~str {
alt ip {
- ipv4(addr) {
- unsafe {
- let result = uv_ip4_name(&addr);
- if result == ~"" {
- fail ~"failed to convert inner sockaddr_in address to str"
- }
- result
+ ipv4(addr) => unsafe {
+ let result = uv_ip4_name(&addr);
+ if result == ~"" {
+ fail ~"failed to convert inner sockaddr_in address to str"
}
+ result
}
- ipv6(addr) {
- unsafe {
- let result = uv_ip6_name(&addr);
- if result == ~"" {
- fail ~"failed to convert inner sockaddr_in address to str"
- }
- result
+ ipv6(addr) => unsafe {
+ let result = uv_ip6_name(&addr);
+ if result == ~"" {
+ fail ~"failed to convert inner sockaddr_in address to str"
}
+ result
}
}
}
ptr::null(),
ptr::null());
alt result {
- 0i32 {
+ 0i32 => {
set_data_for_req(handle_ptr, handle_data_ptr);
}
- _ {
+ _ => {
output_ch.send(result::err(get_addr_unknown_error));
}
}
*/
fn parse_addr(ip: ~str) -> ip_addr {
alt try_parse_addr(ip) {
- result::ok(addr) { copy(addr) }
- result::err(err_data) {
- fail err_data.err_msg
- }
+ result::ok(addr) => copy(addr),
+ result::err(err_data) => fail err_data.err_msg
}
}
// the simple, old style numberic representation of
fn parse_to_ipv4_rep(ip: ~str) -> result::result<ipv4_rep, ~str> {
let parts = vec::map(str::split_char(ip, '.'), |s| {
alt uint::from_str(s) {
- some(n) if n <= 255u { n }
- _ { 256u }
+ some(n) if n <= 255u => n,
+ _ => 256u
}
});
if vec::len(parts) != 4u {
*/
fn parse_addr(ip: ~str) -> ip_addr {
alt try_parse_addr(ip) {
- result::ok(addr) { copy(addr) }
- result::err(err_data) {
- fail err_data.err_msg
- }
+ result::ok(addr) => copy(addr),
+ result::err(err_data) => fail err_data.err_msg
}
}
fn try_parse_addr(ip: ~str) -> result::result<ip_addr,parse_addr_err> {
#[test]
fn test_ip_ipv4_bad_parse() {
alt v4::try_parse_addr(~"b4df00d") {
- result::err(err_info) {
+ result::err(err_info) => {
log(debug, fmt!{"got error as expected %?", err_info});
assert true;
}
- result::ok(addr) {
+ result::ok(addr) => {
fail fmt!{"Expected failure, but got addr %?", addr};
}
}
#[ignore(target_os="win32")]
fn test_ip_ipv6_bad_parse() {
alt v6::try_parse_addr(~"::,~2234k;") {
- result::err(err_info) {
+ result::err(err_info) => {
log(debug, fmt!{"got error as expected %?", err_info});
assert true;
}
- result::ok(addr) {
+ result::ok(addr) => {
fail fmt!{"Expected failure, but got addr %?", addr};
}
}
localhost_name, vec::len(results)});
for vec::each(results) |r| {
let ipv_prefix = alt r {
- ipv4(_) {
- ~"IPv4"
- }
- ipv6(_) {
- ~"IPv6"
- }
+ ipv4(_) => ~"IPv4",
+ ipv6(_) => ~"IPv6"
};
log(debug, fmt!{"test_get_addr: result %s: '%s'",
ipv_prefix, format_addr(r)});
log(debug, fmt!{"stream_handle_ptr in interact %?",
stream_handle_ptr});
alt uv::ll::tcp_init( loop_ptr, stream_handle_ptr) {
- 0i32 {
+ 0i32 => {
log(debug, ~"tcp_init successful");
alt input_ip {
- ipv4 {
+ ipv4 => {
log(debug, ~"dealing w/ ipv4 connection..");
let connect_req_ptr =
ptr::addr_of((*socket_data_ptr).connect_req);
let addr_str = ip::format_addr(input_ip);
let connect_result = alt input_ip {
- ip::ipv4(addr) {
+ ip::ipv4(addr) => {
// have to "recreate" the sockaddr_in/6
// since the ip_addr discards the port
// info.. should probably add an additional
ptr::addr_of(in_addr),
tcp_connect_on_connect_cb)
}
- ip::ipv6(addr) {
+ ip::ipv6(addr) => {
log(debug, fmt!{"addr: %?", addr});
let in_addr = uv::ll::ip6_addr(addr_str, port as int);
uv::ll::tcp_connect6(
}
};
alt connect_result {
- 0i32 {
+ 0i32 => {
log(debug, ~"tcp_connect successful");
// reusable data that we'll have for the
// duration..
// let tcp_connect_on_connect_cb send on
// the result_ch, now..
}
- _ {
+ _ => {
// immediate connect failure.. probably a garbage
// ip or somesuch
let err_data = uv::ll::get_last_err_data(loop_ptr);
}
}
}
- _ {
+ _ => {
// failure to create a tcp handle
let err_data = uv::ll::get_last_err_data(loop_ptr);
comm::send((*conn_data_ptr).result_ch,
}
};
alt comm::recv(result_po) {
- conn_success {
+ conn_success => {
log(debug, ~"tcp::connect - received success on result_po");
result::ok(tcp_socket(socket_data))
}
- conn_failure(err_data) {
+ conn_failure(err_data) => {
comm::recv(closed_signal_po);
log(debug, ~"tcp::connect - received failure on result_po");
// still have to free the malloc'd stream handle..
rustrt::rust_uv_current_kernel_free(stream_handle_ptr
as *libc::c_void);
let tcp_conn_err = alt err_data.err_name {
- ~"ECONNREFUSED" { connection_refused }
- _ { generic_connect_err(err_data.err_name, err_data.err_msg) }
+ ~"ECONNREFUSED" => connection_refused,
+ _ => generic_connect_err(err_data.err_name, err_data.err_msg)
};
result::err(tcp_conn_err)
}
-> result::result<tcp_socket, tcp_err_data> unsafe {
alt new_conn{
- new_tcp_conn(server_handle_ptr) {
+ new_tcp_conn(server_handle_ptr) => {
let server_data_ptr = uv::ll::get_data_for_uv_handle(
server_handle_ptr) as *tcp_listen_fc_data;
let reader_po = comm::port::<result::result<~[u8], tcp_err_data>>();
let loop_ptr = uv::ll::get_loop_for_uv_handle(
server_handle_ptr);
alt uv::ll::tcp_init(loop_ptr, client_stream_handle_ptr) {
- 0i32 {
+ 0i32 => {
log(debug, ~"uv_tcp_init successful for client stream");
alt uv::ll::accept(
server_handle_ptr as *libc::c_void,
client_stream_handle_ptr as *libc::c_void) {
- 0i32 {
+ 0i32 => {
log(debug, ~"successfully accepted client connection");
uv::ll::set_data_for_uv_handle(client_stream_handle_ptr,
client_socket_data_ptr
as *libc::c_void);
comm::send(result_ch, none);
}
- _ {
+ _ => {
log(debug, ~"failed to accept client conn");
comm::send(result_ch, some(
uv::ll::get_last_err_data(loop_ptr).to_tcp_err()));
}
}
}
- _ {
+ _ => {
log(debug, ~"failed to init client stream");
comm::send(result_ch, some(
uv::ll::get_last_err_data(loop_ptr).to_tcp_err()));
}
// UNSAFE LIBUV INTERACTION END
alt comm::recv(result_po) {
- some(err_data) {
- result::err(err_data)
- }
- none {
- result::ok(tcp_socket(client_socket_data))
- }
+ some(err_data) => result::err(err_data),
+ none => result::ok(tcp_socket(client_socket_data))
}
}
}
let loc_ip = copy(host_ip);
do iotask::interact(iotask) |loop_ptr| {
alt uv::ll::tcp_init(loop_ptr, server_stream_ptr) {
- 0i32 {
+ 0i32 => {
uv::ll::set_data_for_uv_handle(
server_stream_ptr,
server_data_ptr);
let addr_str = ip::format_addr(loc_ip);
let bind_result = alt loc_ip {
- ip::ipv4(addr) {
+ ip::ipv4(addr) => {
log(debug, fmt!{"addr: %?", addr});
let in_addr = uv::ll::ip4_addr(addr_str, port as int);
uv::ll::tcp_bind(server_stream_ptr,
ptr::addr_of(in_addr))
}
- ip::ipv6(addr) {
+ ip::ipv6(addr) => {
log(debug, fmt!{"addr: %?", addr});
let in_addr = uv::ll::ip6_addr(addr_str, port as int);
uv::ll::tcp_bind6(server_stream_ptr,
}
};
alt bind_result {
- 0i32 {
+ 0i32 => {
alt uv::ll::listen(server_stream_ptr,
backlog as libc::c_int,
tcp_lfc_on_connection_cb) {
- 0i32 {
- comm::send(setup_ch, none);
- }
- _ {
+ 0i32 => comm::send(setup_ch, none),
+ _ => {
log(debug, ~"failure to uv_listen()");
let err_data = uv::ll::get_last_err_data(loop_ptr);
comm::send(setup_ch, some(err_data));
}
}
}
- _ {
+ _ => {
log(debug, ~"failure to uv_tcp_bind");
let err_data = uv::ll::get_last_err_data(loop_ptr);
comm::send(setup_ch, some(err_data));
}
}
}
- _ {
+ _ => {
log(debug, ~"failure to uv_tcp_init");
let err_data = uv::ll::get_last_err_data(loop_ptr);
comm::send(setup_ch, some(err_data));
setup_ch.recv()
};
alt setup_result {
- some(err_data) {
+ some(err_data) => {
do iotask::interact(iotask) |loop_ptr| {
log(debug, fmt!{"tcp::listen post-kill recv hl interact %?",
loop_ptr});
};
stream_closed_po.recv();
alt err_data.err_name {
- ~"EACCES" {
+ ~"EACCES" => {
log(debug, ~"Got EACCES error");
result::err(access_denied)
}
- ~"EADDRINUSE" {
+ ~"EADDRINUSE" => {
log(debug, ~"Got EADDRINUSE error");
result::err(address_in_use)
}
- _ {
+ _ => {
log(debug, fmt!{"Got '%s' '%s' libuv error",
err_data.err_name, err_data.err_msg});
result::err(
}
}
}
- none {
+ none => {
on_establish_cb(kill_ch);
let kill_result = comm::recv(kill_po);
do iotask::interact(iotask) |loop_ptr| {
stream_closed_po.recv();
alt kill_result {
// some failure post bind/listen
- some(err_data) {
- result::err(generic_listen_err(err_data.err_name,
- err_data.err_msg))
- }
+ some(err_data) => result::err(generic_listen_err(err_data.err_name,
+ err_data.err_msg)),
// clean exit
- none {
- result::ok(())
- }
+ none => result::ok(())
}
}
}
};
log(debug, ~"tcp::read after recv_timeout");
alt read_result {
- none {
+ none => {
log(debug, ~"tcp::read: timed out..");
let err_data = {
err_name: ~"TIMEOUT",
read_stop_common_impl(socket_data);
result::err(err_data)
}
- some(data_result) {
+ some(data_result) => {
log(debug, ~"tcp::read got data");
read_stop_common_impl(socket_data);
data_result
do iotask::interact((*socket_data).iotask) |loop_ptr| {
log(debug, ~"in interact cb for tcp::read_stop");
alt uv::ll::read_stop(stream_handle_ptr as *uv::ll::uv_stream_t) {
- 0i32 {
+ 0i32 => {
log(debug, ~"successfully called uv_read_stop");
comm::send(stop_ch, none);
}
- _ {
+ _ => {
log(debug, ~"failure in calling uv_read_stop");
let err_data = uv::ll::get_last_err_data(loop_ptr);
comm::send(stop_ch, some(err_data.to_tcp_err()));
}
};
alt comm::recv(stop_po) {
- some(err_data) {
- result::err(err_data.to_tcp_err())
- }
- none {
- result::ok(())
- }
+ some(err_data) => result::err(err_data.to_tcp_err()),
+ none => result::ok(())
}
}
alt uv::ll::read_start(stream_handle_ptr as *uv::ll::uv_stream_t,
on_alloc_cb,
on_tcp_read_cb) {
- 0i32 {
+ 0i32 => {
log(debug, ~"success doing uv_read_start");
comm::send(start_ch, none);
}
- _ {
+ _ => {
log(debug, ~"error attempting uv_read_start");
let err_data = uv::ll::get_last_err_data(loop_ptr);
comm::send(start_ch, some(err_data));
}
};
alt comm::recv(start_po) {
- some(err_data) {
- result::err(err_data.to_tcp_err())
- }
- none {
- result::ok((*socket_data).reader_po)
- }
+ some(err_data) => result::err(err_data.to_tcp_err()),
+ none => result::ok((*socket_data).reader_po)
}
}
stream_handle_ptr,
write_buf_vec_ptr,
tcp_write_complete_cb) {
- 0i32 {
+ 0i32 => {
log(debug, ~"uv_write() invoked successfully");
uv::ll::set_data_for_req(write_req_ptr, write_data_ptr);
}
- _ {
+ _ => {
log(debug, ~"error invoking uv_write()");
let err_data = uv::ll::get_last_err_data(loop_ptr);
comm::send((*write_data_ptr).result_ch,
// ownership of everything to the I/O task and let it deal with the
// aftermath, so we don't have to sit here blocking.
alt comm::recv(result_po) {
- tcp_write_success { result::ok(()) }
- tcp_write_error(err_data) { result::err(err_data.to_tcp_err()) }
+ tcp_write_success => result::ok(()),
+ tcp_write_error(err_data) => result::err(err_data.to_tcp_err())
}
}
let kill_ch = (*server_data_ptr).kill_ch;
if (*server_data_ptr).active {
alt status {
- 0i32 {
- (*server_data_ptr).on_connect_cb(handle);
- }
- _ {
+ 0i32 => (*server_data_ptr).on_connect_cb(handle),
+ _ => {
let loop_ptr = uv::ll::get_loop_for_uv_handle(handle);
comm::send(kill_ch,
some(uv::ll::get_last_err_data(loop_ptr)
as *tcp_socket_data;
alt nread as int {
// incoming err.. probably eof
- -1 {
+ -1 => {
let err_data = uv::ll::get_last_err_data(loop_ptr).to_tcp_err();
log(debug, fmt!{"on_tcp_read_cb: incoming err.. name %? msg %?",
err_data.err_name, err_data.err_msg});
comm::send(reader_ch, result::err(err_data));
}
// do nothing .. unneeded buf
- 0 {}
+ 0 => (),
// have data
- _ {
+ _ => {
// we have data
log(debug, fmt!{"tcp on_read_cb nread: %d", nread as int});
let reader_ch = (*socket_data_ptr).reader_ch;
let tcp_stream_ptr =
uv::ll::get_stream_handle_from_connect_req(connect_req_ptr);
alt status {
- 0i32 {
+ 0i32 => {
log(debug, ~"successful tcp connection!");
comm::send(result_ch, conn_success);
}
- _ {
+ _ => {
log(debug, ~"error in tcp_connect_on_connect_cb");
let loop_ptr = uv::ll::get_loop_for_uv_handle(tcp_stream_ptr);
let err_data = uv::ll::get_last_err_data(loop_ptr);
hl_loop)
};
alt actual_resp_result.get_err() {
- connection_refused {
- }
- _ {
- fail ~"unknown error.. expected connection_refused"
- }
+ connection_refused => (),
+ _ => fail ~"unknown error.. expected connection_refused"
}
}
fn impl_gl_tcp_ipv4_server_address_in_use() {
hl_loop)
};
alt listen_err {
- address_in_use {
+ address_in_use => {
assert true;
}
- _ {
+ _ => {
fail ~"expected address_in_use listen error,"+
- ~"but got a different error varient. check logs.";
+ ~"but got a different error varient. check logs.";
}
}
}
server_port,
hl_loop);
alt listen_err {
- access_denied {
+ access_denied => {
assert true;
}
- _ {
+ _ => {
fail ~"expected address_in_use listen error,"+
~"but got a different error varient. check logs.";
}
~"connection!");
let received_req_bytes = read(sock, 0u);
alt received_req_bytes {
- result::ok(data) {
+ result::ok(data) => {
log(debug, ~"SERVER: got REQ str::from_bytes..");
log(debug, fmt!{"SERVER: REQ data len: %?",
vec::len(data)});
log(debug, ~"SERVER: after write.. die");
comm::send(kill_ch, none);
}
- result::err(err_data) {
+ result::err(err_data) => {
log(debug, fmt!{"SERVER: error recvd: %s %s",
err_data.err_name, err_data.err_msg});
comm::send(kill_ch, some(err_data));
// err check on listen_result
if result::is_err(listen_result) {
alt result::get_err(listen_result) {
- generic_listen_err(name, msg) {
+ generic_listen_err(name, msg) => {
fail fmt!{"SERVER: exited abnormally name %s msg %s",
name, msg};
}
- access_denied {
+ access_denied => {
fail ~"SERVER: exited abnormally, got access denied..";
}
- address_in_use {
+ address_in_use => {
fail ~"SERVER: exited abnormally, got address in use...";
}
}
'A' to 'Z' |
'a' to 'z' |
'0' to '9' |
- '-' | '.' | '_' | '~' {
+ '-' | '.' | '_' | '~' => {
str::push_char(out, ch);
}
- _ {
- if full_url {
+ _ => {
+ if full_url {
match ch {
// gen-delims:
':' | '/' | '?' | '#' | '[' | ']' | '@' |
// sub-delims:
'!' | '$' | '&' | '"' | '(' | ')' | '*' |
- '+' | ',' | ';' | '=' {
+ '+' | ',' | ';' | '=' => {
str::push_char(out, ch);
}
- _ { out += #fmt("%%%X", ch as uint); }
+ _ => out += #fmt("%%%X", ch as uint)
}
} else {
out += #fmt("%%%X", ch as uint);
while !rdr.eof() {
match rdr.read_char() {
- '%' {
+ '%' => {
let bytes = rdr.read_bytes(2u);
let ch = uint::parse_buf(bytes, 16u).get() as char;
// sub-delims:
'!' | '$' | '&' | '"' | '(' | ')' | '*' |
- '+' | ',' | ';' | '=' {
+ '+' | ',' | ';' | '=' => {
str::push_char(out, '%');
str::push_char(out, bytes[0u] as char);
str::push_char(out, bytes[1u] as char);
}
- ch { str::push_char(out, ch); }
+ ch => str::push_char(out, ch)
}
} else {
str::push_char(out, ch);
}
}
- ch { str::push_char(out, ch); }
+ ch => str::push_char(out, ch)
}
}
while !rdr.eof() {
let ch = rdr.read_byte() as char;
match ch {
- 'A' to 'Z' | 'a' to 'z' | '0' to '9' | '_' | '.' | '-' {
+ 'A' to 'Z' | 'a' to 'z' | '0' to '9' | '_' | '.' | '-' => {
str::push_char(out, ch);
}
- ' ' { str::push_char(out, '+'); }
- _ { out += #fmt("%%%X", ch as uint); }
+ ' ' => str::push_char(out, '+'),
+ _ => out += #fmt("%%%X", ch as uint)
}
}
while !rdr.eof() {
match rdr.read_char() {
- '&' | ';' {
+ '&' | ';' => {
if key != ~"" && value != ~"" {
let values = match m.find(key) {
- some(values) { values }
- none {
+ some(values) => values,
+ none => {
let values = @dvec();
m.insert(key, values);
values
key = ~"";
value = ~"";
}
- '=' { parsing_key = false; }
- ch {
+ '=' => parsing_key = false,
+ ch => {
let ch = match ch {
- '%' {
+ '%' => {
uint::parse_buf(rdr.read_bytes(2u), 16u).get() as char
}
- '+' { ' ' }
- ch { ch }
+ '+' => ' ',
+ ch => ch
};
if parsing_key {
if key != ~"" && value != ~"" {
let values = match m.find(key) {
- some(values) { values }
- none {
+ some(values) => values,
+ none => {
let values = @dvec();
m.insert(key, values);
values
fn get_scheme(rawurl: ~str) -> result::result<(~str, ~str), @~str> {
for str::each_chari(rawurl) |i,c| {
match c {
- 'A' to 'Z' | 'a' to 'z' { again; }
- '0' to '9' | '+' | '-' | '.' {
+ 'A' to 'Z' | 'a' to 'z' => again,
+ '0' to '9' | '+' | '-' | '.' => {
if i == 0 {
return result::err(@~"url: Scheme must begin with a letter.");
}
again;
}
- ':' {
+ ':' => {
if i == 0 {
return result::err(@~"url: Scheme cannot be empty.");
} else {
rawurl.slice(i+1,str::len(rawurl))));
}
}
- _ {
+ _ => {
return result::err(@~"url: Invalid character in scheme.");
}
}
// deal with input class first
match c {
- '0' to '9' { }
- 'A' to 'F' | 'a' to 'f' {
+ '0' to '9' => (),
+ 'A' to 'F' | 'a' to 'f' => {
if in == digit {
in = hex;
}
}
'G' to 'Z' | 'g' to 'z' | '-' | '.' | '_' | '~' | '%' |
- '&' |'\'' | '(' | ')' | '+' | '!' | '*' | ',' | ';' | '=' {
+ '&' |'\'' | '(' | ')' | '+' | '!' | '*' | ',' | ';' | '=' => {
in = unreserved;
}
- ':' | '@' | '?' | '#' | '/' {
+ ':' | '@' | '?' | '#' | '/' => {
// separators, don't change anything
}
- _ {
+ _ => {
return result::err(@~"Illegal character in authority");
}
}
// now process states
match c {
- ':' {
+ ':' => {
colon_count += 1;
match st {
- start {
+ start => {
pos = i;
st = pass_host_port;
}
- pass_host_port {
+ pass_host_port => {
// multiple colons means ipv6 address.
if in == unreserved {
return result::err(
}
st = ip6_host;
}
- in_host {
+ in_host => {
pos = i;
// can't be sure whether this is an ipv6 address or a port
if in == unreserved {
}
st = ip6_port;
}
- ip6_port {
+ ip6_port => {
if in == unreserved {
return result::err(@~"Illegal characters in authority.");
}
st = ip6_host;
}
- ip6_host {
+ ip6_host => {
if colon_count > 7 {
host = str::slice(rawurl, begin, i);
pos = i;
st = in_port;
}
}
- _ {
+ _ => {
return result::err(@~"Invalid ':' in authority.");
}
}
in = digit; // reset input class
}
- '@' {
+ '@' => {
in = digit; // reset input class
colon_count = 0; // reset count
match st {
- start {
+ start => {
let user = str::slice(rawurl, begin, i);
userinfo = option::some({user : user,
pass: option::none});
st = in_host;
}
- pass_host_port {
+ pass_host_port => {
let user = str::slice(rawurl, begin, pos);
let pass = str::slice(rawurl, pos+1, i);
userinfo = option::some({user: user,
pass: option::some(pass)});
st = in_host;
}
- _ {
+ _ => {
return result::err(@~"Invalid '@' in authority.");
}
}
begin = i+1;
}
- '?' | '#' | '/' {
+ '?' | '#' | '/' => {
end = i;
break;
}
- _ { }
+ _ => ()
}
end = i;
}
// finish up
match st {
- start {
+ start => {
if host_is_end_plus_one() {
host = str::slice(rawurl, begin, end+1);
} else {
host = str::slice(rawurl, begin, end);
}
}
- pass_host_port | ip6_port {
+ pass_host_port | ip6_port => {
if in != digit {
return result::err(@~"Non-digit characters in port.");
}
host = str::slice(rawurl, begin, pos);
port = option::some(str::slice(rawurl, pos+1, end));
}
- ip6_host | in_host {
+ ip6_host | in_host => {
host = str::slice(rawurl, begin, end);
}
- in_port {
+ in_port => {
if in != digit {
return result::err(@~"Non-digit characters in port.");
}
for str::each_chari(rawurl) |i,c| {
match c {
'A' to 'Z' | 'a' to 'z' | '0' to '9' | '&' |'\'' | '(' | ')' | '.'
- | '@' | ':' | '%' | '/' | '+' | '!' | '*' | ',' | ';' | '=' {
+ | '@' | ':' | '%' | '/' | '+' | '!' | '*' | ',' | ';' | '=' => {
again;
}
- '?' | '#' {
+ '?' | '#' => {
end = i;
break;
}
- _ { return result::err(@~"Invalid character in path.") }
+ _ => return result::err(@~"Invalid character in path.")
}
}
/// Concatenate two ropes
fn append_rope(left: rope, right: rope) -> rope {
alt(left) {
- node::empty { return right; }
- node::content(left_content) {
+ node::empty => return right,
+ node::content(left_content) => {
alt(right) {
- node::empty { return left; }
- node::content(right_content) {
+ node::empty => return left,
+ node::content(right_content) => {
return node::content(node::concat2(left_content, right_content));
- }
+ }
}
}
}
*/
fn bal(rope:rope) -> rope {
alt(rope) {
- node::empty { return rope }
- node::content(x) {
- alt(node::bal(x)) {
- option::none { rope }
- option::some(y) { node::content(y) }
- }
+ node::empty => return rope,
+ node::content(x) => alt(node::bal(x)) {
+ option::none => rope,
+ option::some(y) => node::content(y)
}
}
}
fn sub_chars(rope: rope, char_offset: uint, char_len: uint) -> rope {
if char_len == 0u { return node::empty; }
alt(rope) {
- node::empty { fail }
- node::content(node) {
- if char_len > node::char_len(node) { fail }
- else {
- return node::content(node::sub_chars(node, char_offset, char_len))
- }
+ node::empty => fail,
+ node::content(node) => if char_len > node::char_len(node) {
+ fail
+ } else {
+ return node::content(node::sub_chars(node, char_offset, char_len))
}
}
}
fn sub_bytes(rope: rope, byte_offset: uint, byte_len: uint) -> rope {
if byte_len == 0u { return node::empty; }
alt(rope) {
- node::empty { fail }
- node::content(node) {
- if byte_len > node::byte_len(node) { fail }
- else {
- return node::content(node::sub_bytes(node, byte_offset, byte_len))
- }
+ node::empty => fail,
+ node::content(node) =>if byte_len > node::byte_len(node) {
+ fail
+ } else {
+ return node::content(node::sub_bytes(node, byte_offset, byte_len))
}
}
}
*/
fn cmp(left: rope, right: rope) -> int {
alt((left, right)) {
- (node::empty, node::empty) { return 0; }
- (node::empty, _) { return -1;}
- (_, node::empty) { return 1;}
- (node::content(a), node::content(b)) {
+ (node::empty, node::empty) => return 0,
+ (node::empty, _) => return -1,
+ (_, node::empty) => return 1,
+ (node::content(a), node::content(b)) => {
return node::cmp(a, b);
}
}
*/
fn loop_chars(rope: rope, it: fn(char) -> bool) -> bool {
alt(rope) {
- node::empty { return true }
- node::content(x) { return node::loop_chars(x, it) }
+ node::empty => return true,
+ node::content(x) => return node::loop_chars(x, it)
}
}
*/
fn loop_leaves(rope: rope, it: fn(node::leaf) -> bool) -> bool{
alt(rope) {
- node::empty { return true }
- node::content(x) {return node::loop_leaves(x, it)}
+ node::empty => return true,
+ node::content(x) => return node::loop_leaves(x, it)
}
}
mod leaf {
fn start(rope: rope) -> node::leaf_iterator::t {
alt(rope) {
- node::empty { return node::leaf_iterator::empty() }
- node::content(x) { return node::leaf_iterator::start(x) }
+ node::empty => return node::leaf_iterator::empty(),
+ node::content(x) => return node::leaf_iterator::start(x)
}
}
fn next(it: node::leaf_iterator::t) -> option<node::leaf> {
mod char {
fn start(rope: rope) -> node::char_iterator::t {
alt(rope) {
- node::empty { return node::char_iterator::empty() }
- node::content(x) { return node::char_iterator::start(x) }
+ node::empty => return node::char_iterator::empty(),
+ node::content(x) => return node::char_iterator::start(x)
}
}
fn next(it: node::char_iterator::t) -> option<char> {
*/
fn height(rope: rope) -> uint {
alt(rope) {
- node::empty { return 0u; }
- node::content(x) { return node::height(x); }
+ node::empty => return 0u,
+ node::content(x) => return node::height(x)
}
}
*/
pure fn char_len(rope: rope) -> uint {
alt(rope) {
- node::empty { return 0u; }
- node::content(x) { return node::char_len(x) }
+ node::empty => return 0u,
+ node::content(x) => return node::char_len(x)
}
}
*/
pure fn byte_len(rope: rope) -> uint {
alt(rope) {
- node::empty { return 0u; }
- node::content(x) { return node::byte_len(x) }
+ node::empty => return 0u,
+ node::content(x) => return node::byte_len(x)
}
}
*/
fn char_at(rope: rope, pos: uint) -> char {
alt(rope) {
- node::empty { fail }
- node::content(x) { return node::char_at(x, pos) }
+ node::empty => fail,
+ node::content(x) => return node::char_at(x, pos)
}
}
pure fn byte_len(node: @node) -> uint {
//FIXME (#2744): Could we do this without the pattern-matching?
alt(*node) {
- leaf(y) { return y.byte_len; }
- concat(y){ return y.byte_len; }
+ leaf(y) => return y.byte_len,
+ concat(y) => return y.byte_len
}
}
pure fn char_len(node: @node) -> uint {
alt(*node) {
- leaf(y) { return y.char_len; }
- concat(y) { return y.char_len; }
+ leaf(y) => return y.char_len,
+ concat(y) => return y.char_len
}
}
let it = leaf_iterator::start(node);
loop {
alt(leaf_iterator::next(it)) {
- option::none { break; }
- option::some(x) {
+ option::none => break,
+ option::some(x) => {
//FIXME (#2744): Replace with memcpy or something similar
let mut local_buf: ~[u8] =
unsafe::reinterpret_cast(*x.content);
*/
fn flatten(node: @node) -> @node unsafe {
alt(*node) {
- leaf(_) { return node }
- concat(x) {
+ leaf(_) => return node,
+ concat(x) => {
return @leaf({
byte_offset: 0u,
byte_len: x.byte_len,
let it = leaf_iterator::start(node);
loop {
alt (leaf_iterator::next(it)) {
- option::none { break; }
- option::some(x) { vec::push(forest, @leaf(x)); }
+ option::none => break,
+ option::some(x) => vec::push(forest, @leaf(x))
}
}
//2. Rebuild tree from forest
return node;
}
alt(*node) {
- node::leaf(x) {
+ node::leaf(x) => {
let char_len =
str::count_chars(*x.content, byte_offset, byte_len);
return @leaf({byte_offset: byte_offset,
char_len: char_len,
content: x.content});
}
- node::concat(x) {
+ node::concat(x) => {
let left_len: uint = node::byte_len(x.left);
if byte_offset <= left_len {
if byte_offset + byte_len <= left_len {
let mut char_offset = char_offset;
loop {
alt(*node) {
- node::leaf(x) {
+ node::leaf(x) => {
if char_offset == 0u && char_len == x.char_len {
return node;
}
char_len: char_len,
content: x.content});
}
- node::concat(x) {
+ node::concat(x) => {
if char_offset == 0u && char_len == x.char_len {return node;}
let left_len : uint = node::char_len(x.left);
if char_offset <= left_len {
fn height(node: @node) -> uint {
alt(*node) {
- leaf(_) { return 0u; }
- concat(x) { return x.height; }
+ leaf(_) => return 0u,
+ concat(x) => return x.height
}
}
let mut result = 0;
while result == 0 {
alt((char_iterator::next(ita), char_iterator::next(itb))) {
- (option::none, option::none) {
- break;
- }
- (option::some(chara), option::some(charb)) {
+ (option::none, option::none) => break,
+ (option::some(chara), option::some(charb)) => {
result = char::cmp(chara, charb);
}
- (option::some(_), _) {
+ (option::some(_), _) => {
result = 1;
}
- (_, option::some(_)) {
+ (_, option::some(_)) => {
result = -1;
}
}
let mut current = node;
loop {
alt(*current) {
- leaf(x) {
- return it(x);
- }
- concat(x) {
- if loop_leaves(x.left, it) { //non tail call
- current = x.right; //tail call
- } else {
- return false;
- }
+ leaf(x) => return it(x),
+ concat(x) => if loop_leaves(x.left, it) { //non tail call
+ current = x.right; //tail call
+ } else {
+ return false;
}
}
};
let mut pos = pos;
loop {
alt *node {
- leaf(x) {
- return str::char_at(*x.content, pos);
- }
- concat({left, right, _}) {
+ leaf(x) => return str::char_at(*x.content, pos),
+ concat({left, right, _}) => {
let left_len = char_len(left);
node = if left_len > pos { left }
else { pos -= left_len; right };
let current = it.stack[it.stackpos];
it.stackpos -= 1;
alt(*current) {
- concat(x) {
+ concat(x) => {
it.stackpos += 1;
it.stack[it.stackpos] = x.right;
it.stackpos += 1;
it.stack[it.stackpos] = x.left;
}
- leaf(x) {
- return option::some(x);
- }
+ leaf(x) => return option::some(x)
}
};
}
fn next(it: t) -> option<char> {
loop {
alt(get_current_or_next_leaf(it)) {
- option::none { return option::none; }
- option::some(_) {
+ option::none => return option::none,
+ option::some(_) => {
let next_char = get_next_char_in_leaf(it);
alt(next_char) {
- option::none {
- again;
- }
- option::some(_) {
- return next_char;
- }
+ option::none => again,
+ option::some(_) => return next_char
}
}
}
fn get_current_or_next_leaf(it: t) -> option<leaf> {
alt(it.leaf) {
- option::some(_) { return it.leaf }
- option::none {
+ option::some(_) => return it.leaf,
+ option::none => {
let next = leaf_iterator::next(it.leaf_iterator);
alt(next) {
- option::none { return option::none }
- option::some(_) {
+ option::none => return option::none,
+ option::some(_) => {
it.leaf = next;
it.leaf_byte_pos = 0u;
return next;
fn get_next_char_in_leaf(it: t) -> option<char> {
alt copy it.leaf {
- option::none { return option::none }
- option::some(aleaf) {
+ option::none => return option::none,
+ option::some(aleaf) => {
if it.leaf_byte_pos >= aleaf.byte_len {
//We are actually past the end of the leaf
it.leaf = option::none;
//Utility function, used for sanity check
fn rope_to_string(r: rope) -> ~str {
alt(r) {
- node::empty { return ~"" }
- node::content(x) {
+ node::empty => return ~"",
+ node::content(x) => {
let str = @mut ~"";
fn aux(str: @mut ~str, node: @node::node) unsafe {
alt(*node) {
- node::leaf(x) {
+ node::leaf(x) => {
*str += str::slice(
*x.content, x.byte_offset,
x.byte_offset + x.byte_len);
}
- node::concat(x) {
+ node::concat(x) => {
aux(str, x.left);
aux(str, x.right);
}
let mut equal = true;
while equal {
alt(node::char_iterator::next(rope_iter)) {
- option::none {
+ option::none => {
if string_iter < string_len {
equal = false;
} break; }
- option::some(c) {
+ option::some(c) => {
let {ch, next} = str::char_range_at(*sample, string_iter);
string_iter = next;
if ch != c { equal = false; break; }
let it = iterator::char::start(r);
loop {
alt(node::char_iterator::next(it)) {
- option::none { break; }
- option::some(_) { len += 1u; }
+ option::none => break,
+ option::some(_) => len += 1u
}
}
fn serialize_option<S: serializer,T>(s: S, v: option<T>, st: fn(T)) {
do s.emit_enum(~"option") {
alt v {
- none {
- do s.emit_enum_variant(~"none", 0u, 0u) {
- }
+ none => do s.emit_enum_variant(~"none", 0u, 0u) {
}
- some(v) {
- do s.emit_enum_variant(~"some", 1u, 1u) {
- do s.emit_enum_variant_arg(0u) {
- st(v)
- }
+ some(v) => do s.emit_enum_variant(~"some", 1u, 1u) {
+ do s.emit_enum_variant_arg(0u) {
+ st(v)
}
}
}
do d.read_enum(~"option") {
do d.read_enum_variant |i| {
alt check i {
- 0u { // none
- none
- }
- 1u { // some(v)
- some(d.read_enum_variant_arg(0u, || {
- st()
- }))
- }
+ 0u => none,
+ 1u => some(d.read_enum_variant_arg(0u, || st() ))
}
}
}
*/
pure fn get<T: copy>(self: smallintmap<T>, key: uint) -> T {
alt find(self, key) {
- none { error!{"smallintmap::get(): key not present"}; fail; }
- some(v) { return v; }
+ none => {
+ error!{"smallintmap::get(): key not present"};
+ fail;
+ }
+ some(v) => return v
}
}
fn size() -> uint {
let mut sz = 0u;
for self.v.each |item| {
- alt item { some(_) { sz += 1u; } _ {} }
+ alt item {
+ some(_) => sz += 1u,
+ _ => ()
+ }
}
sz
}
let mut idx = 0u, l = self.v.len();
while idx < l {
alt self.v.get_elt(idx) {
- some(elt) {
- if !it(idx, elt) { break; }
- }
- none { }
+ some(elt) => if !it(idx, elt) { break }
+ none => ()
}
idx += 1u;
}
let mut idx = 0u, l = self.v.len();
while idx < l {
alt self.v.get_elt(idx) {
- some(elt) {
- if !it(&idx, &elt) { break; }
- }
- none { }
+ some(elt) => if !it(&idx, &elt) { break }
+ none => ()
}
idx += 1u;
}
fn test_mkdtemp() {
let r = mkdtemp(~"./", ~"foobar");
alt r {
- some(p) {
+ some(p) => {
os::remove_dir(p);
assert(str::ends_with(p, ~"foobar"));
}
- _ { assert(false); }
+ _ => assert(false)
}
}
let supported_terms = ~[~"xterm-color", ~"xterm",
~"screen-bce", ~"xterm-256color"];
return alt os::getenv(~"TERM") {
- option::some(env) {
+ option::some(env) => {
for vec::each(supported_terms) |term| {
if term == env { return true; }
}
false
}
- option::none { false }
+ option::none => false
};
}
fn test_main(args: ~[~str], tests: ~[test_desc]) {
let opts =
alt parse_opts(args) {
- either::left(o) { o }
- either::right(m) { fail m }
+ either::left(o) => o,
+ either::right(m) => fail m
};
if !run_tests_console(opts, tests) { fail ~"Some tests failed"; }
}
let opts = ~[getopts::optflag(~"ignored"), getopts::optopt(~"logfile")];
let matches =
alt getopts::getopts(args_, opts) {
- ok(m) { m }
- err(f) { return either::right(getopts::fail_str(f)) }
+ ok(m) => m,
+ err(f) => return either::right(getopts::fail_str(f))
};
let filter =
fn callback(event: testevent, st: console_test_state) {
alt event {
- te_filtered(filtered_tests) {
+ te_filtered(filtered_tests) => {
st.total = vec::len(filtered_tests);
let noun = if st.total != 1u { ~"tests" } else { ~"test" };
st.out.write_line(fmt!{"\nrunning %u %s", st.total, noun});
}
- te_wait(test) { st.out.write_str(fmt!{"test %s ... ", test.name}); }
- te_result(test, result) {
+ te_wait(test) => st.out.write_str(fmt!{"test %s ... ", test.name}),
+ te_result(test, result) => {
alt st.log_out {
- some(f) {
- write_log(f, result, test);
- }
- none {}
+ some(f) => write_log(f, result, test),
+ none => ()
}
alt result {
- tr_ok {
+ tr_ok => {
st.passed += 1u;
write_ok(st.out, st.use_color);
st.out.write_line(~"");
}
- tr_failed {
+ tr_failed => {
st.failed += 1u;
write_failed(st.out, st.use_color);
st.out.write_line(~"");
vec::push(st.failures, copy test);
}
- tr_ignored {
+ tr_ignored => {
st.ignored += 1u;
write_ignored(st.out, st.use_color);
st.out.write_line(~"");
}
let log_out = alt opts.logfile {
- some(path) {
- alt io::file_writer(path, ~[io::create, io::truncate]) {
- result::ok(w) { some(w) }
- result::err(s) {
- fail(fmt!{"can't open output file: %s", s})
- }
- }
+ some(path) => alt io::file_writer(path, ~[io::create, io::truncate]) {
+ result::ok(w) => some(w),
+ result::err(s) => {
+ fail(fmt!{"can't open output file: %s", s})
+ }
}
- none { none }
+ none => none
};
let st =
fn write_log(out: io::writer, result: test_result, test: test_desc) {
out.write_line(fmt!{"%s %s",
alt result {
- tr_ok { ~"ok" }
- tr_failed { ~"failed" }
- tr_ignored { ~"ignored" }
+ tr_ok => ~"ok",
+ tr_failed => ~"failed",
+ tr_ignored => ~"ignored"
}, test.name});
}
} else {
let filter_str =
alt opts.filter {
- option::some(f) { f }
- option::none { ~"" }
+ option::some(f) => f,
+ option::none => ~""
};
fn filter_fn(test: test_desc, filter_str: ~str) ->
#[test]
fn first_free_arg_should_be_a_filter() {
let args = ~[~"progname", ~"filter"];
- let opts = alt parse_opts(args) { either::left(o) { o }
- _ { fail ~"Malformed arg in first_free_arg_should_be_a_filter"; } };
+ let opts = alt parse_opts(args) {
+ either::left(o) => o,
+ _ => fail ~"Malformed arg in first_free_arg_should_be_a_filter"
+ };
assert ~"filter" == option::get(opts.filter);
}
#[test]
fn parse_ignored_flag() {
let args = ~[~"progname", ~"filter", ~"--ignored"];
- let opts = alt parse_opts(args) { either::left(o) { o }
- _ { fail ~"Malformed arg in parse_ignored_flag"; } };
+ let opts = alt parse_opts(args) {
+ either::left(o) => o,
+ _ => fail ~"Malformed arg in parse_ignored_flag"
+ };
assert (opts.run_ignored);
}
pos = next;
alt ch {
- '0' to '9' {
+ '0' to '9' => {
value = value * 10_i32 + (ch as i32 - '0' as i32);
}
- ' ' if ws { }
- _ { return none; }
+ ' ' if ws => (),
+ _ => return none
}
i += 1u;
}
fn parse_type(s: ~str, pos: uint, ch: char, tm: tm_mut)
-> result<uint, ~str> {
alt ch {
- 'A' {
- alt match_strs(s, pos, ~[
- (~"Sunday", 0_i32),
- (~"Monday", 1_i32),
- (~"Tuesday", 2_i32),
- (~"Wednesday", 3_i32),
- (~"Thursday", 4_i32),
- (~"Friday", 5_i32),
- (~"Saturday", 6_i32)
- ]) {
- some(item) { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
- none { err(~"Invalid day") }
- }
+ 'A' => alt match_strs(s, pos, ~[
+ (~"Sunday", 0_i32),
+ (~"Monday", 1_i32),
+ (~"Tuesday", 2_i32),
+ (~"Wednesday", 3_i32),
+ (~"Thursday", 4_i32),
+ (~"Friday", 5_i32),
+ (~"Saturday", 6_i32)
+ ]) {
+ some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
+ none => err(~"Invalid day")
}
- 'a' {
- alt match_strs(s, pos, ~[
- (~"Sun", 0_i32),
- (~"Mon", 1_i32),
- (~"Tue", 2_i32),
- (~"Wed", 3_i32),
- (~"Thu", 4_i32),
- (~"Fri", 5_i32),
- (~"Sat", 6_i32)
- ]) {
- some(item) { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
- none { err(~"Invalid day") }
- }
+ 'a' => alt match_strs(s, pos, ~[
+ (~"Sun", 0_i32),
+ (~"Mon", 1_i32),
+ (~"Tue", 2_i32),
+ (~"Wed", 3_i32),
+ (~"Thu", 4_i32),
+ (~"Fri", 5_i32),
+ (~"Sat", 6_i32)
+ ]) {
+ some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
+ none => err(~"Invalid day")
}
- 'B' {
- alt match_strs(s, pos, ~[
- (~"January", 0_i32),
- (~"February", 1_i32),
- (~"March", 2_i32),
- (~"April", 3_i32),
- (~"May", 4_i32),
- (~"June", 5_i32),
- (~"July", 6_i32),
- (~"August", 7_i32),
- (~"September", 8_i32),
- (~"October", 9_i32),
- (~"November", 10_i32),
- (~"December", 11_i32)
- ]) {
- some(item) { let (v, pos) = item; tm.tm_mon = v; ok(pos) }
- none { err(~"Invalid month") }
- }
+ 'B' => alt match_strs(s, pos, ~[
+ (~"January", 0_i32),
+ (~"February", 1_i32),
+ (~"March", 2_i32),
+ (~"April", 3_i32),
+ (~"May", 4_i32),
+ (~"June", 5_i32),
+ (~"July", 6_i32),
+ (~"August", 7_i32),
+ (~"September", 8_i32),
+ (~"October", 9_i32),
+ (~"November", 10_i32),
+ (~"December", 11_i32)
+ ]) {
+ some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) }
+ none => err(~"Invalid month")
}
- 'b' | 'h' {
- alt match_strs(s, pos, ~[
- (~"Jan", 0_i32),
- (~"Feb", 1_i32),
- (~"Mar", 2_i32),
- (~"Apr", 3_i32),
- (~"May", 4_i32),
- (~"Jun", 5_i32),
- (~"Jul", 6_i32),
- (~"Aug", 7_i32),
- (~"Sep", 8_i32),
- (~"Oct", 9_i32),
- (~"Nov", 10_i32),
- (~"Dec", 11_i32)
- ]) {
- some(item) { let (v, pos) = item; tm.tm_mon = v; ok(pos) }
- none { err(~"Invalid month") }
- }
+ 'b' | 'h' => alt match_strs(s, pos, ~[
+ (~"Jan", 0_i32),
+ (~"Feb", 1_i32),
+ (~"Mar", 2_i32),
+ (~"Apr", 3_i32),
+ (~"May", 4_i32),
+ (~"Jun", 5_i32),
+ (~"Jul", 6_i32),
+ (~"Aug", 7_i32),
+ (~"Sep", 8_i32),
+ (~"Oct", 9_i32),
+ (~"Nov", 10_i32),
+ (~"Dec", 11_i32)
+ ]) {
+ some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) }
+ none => err(~"Invalid month")
}
- 'C' {
- alt match_digits(s, pos, 2u, false) {
- some(item) {
+ 'C' => alt match_digits(s, pos, 2u, false) {
+ some(item) => {
let (v, pos) = item;
- tm.tm_year += (v * 100_i32) - 1900_i32;
- ok(pos)
+ tm.tm_year += (v * 100_i32) - 1900_i32;
+ ok(pos)
}
- none { err(~"Invalid year") }
- }
+ none => err(~"Invalid year")
}
- 'c' {
+ 'c' => {
parse_type(s, pos, 'a', tm)
.chain(|pos| parse_char(s, pos, ' '))
.chain(|pos| parse_type(s, pos, 'b', tm))
.chain(|pos| parse_char(s, pos, ' '))
.chain(|pos| parse_type(s, pos, 'Y', tm))
}
- 'D' | 'x' {
+ 'D' | 'x' => {
parse_type(s, pos, 'm', tm)
.chain(|pos| parse_char(s, pos, '/'))
.chain(|pos| parse_type(s, pos, 'd', tm))
.chain(|pos| parse_char(s, pos, '/'))
.chain(|pos| parse_type(s, pos, 'y', tm))
}
- 'd' {
- alt match_digits(s, pos, 2u, false) {
- some(item) { let (v, pos) = item; tm.tm_mday = v; ok(pos) }
- none { err(~"Invalid day of the month") }
- }
+ 'd' => alt match_digits(s, pos, 2u, false) {
+ some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) }
+ none => err(~"Invalid day of the month")
}
- 'e' {
- alt match_digits(s, pos, 2u, true) {
- some(item) { let (v, pos) = item; tm.tm_mday = v; ok(pos) }
- none { err(~"Invalid day of the month") }
- }
+ 'e' => alt match_digits(s, pos, 2u, true) {
+ some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) }
+ none => err(~"Invalid day of the month")
}
- 'F' {
+ 'F' => {
parse_type(s, pos, 'Y', tm)
.chain(|pos| parse_char(s, pos, '-'))
.chain(|pos| parse_type(s, pos, 'm', tm))
.chain(|pos| parse_char(s, pos, '-'))
.chain(|pos| parse_type(s, pos, 'd', tm))
}
- 'H' {
+ 'H' => {
// FIXME (#2350): range check.
alt match_digits(s, pos, 2u, false) {
- some(item) { let (v, pos) = item; tm.tm_hour = v; ok(pos) }
- none { err(~"Invalid hour") }
+ some(item) => { let (v, pos) = item; tm.tm_hour = v; ok(pos) }
+ none => err(~"Invalid hour")
}
}
- 'I' {
+ 'I' => {
// FIXME (#2350): range check.
alt match_digits(s, pos, 2u, false) {
- some(item) {
+ some(item) => {
let (v, pos) = item;
tm.tm_hour = if v == 12_i32 { 0_i32 } else { v };
ok(pos)
}
- none { err(~"Invalid hour") }
+ none => err(~"Invalid hour")
}
}
- 'j' {
+ 'j' => {
// FIXME (#2350): range check.
alt match_digits(s, pos, 3u, false) {
- some(item) {
+ some(item) => {
let (v, pos) = item;
tm.tm_yday = v - 1_i32;
ok(pos)
}
- none { err(~"Invalid year") }
+ none => err(~"Invalid year")
}
}
- 'k' {
+ 'k' => {
// FIXME (#2350): range check.
alt match_digits(s, pos, 2u, true) {
- some(item) { let (v, pos) = item; tm.tm_hour = v; ok(pos) }
- none { err(~"Invalid hour") }
+ some(item) => { let (v, pos) = item; tm.tm_hour = v; ok(pos) }
+ none => err(~"Invalid hour")
}
}
- 'l' {
+ 'l' => {
// FIXME (#2350): range check.
alt match_digits(s, pos, 2u, true) {
- some(item) {
+ some(item) => {
let (v, pos) = item;
tm.tm_hour = if v == 12_i32 { 0_i32 } else { v };
ok(pos)
}
- none { err(~"Invalid hour") }
+ none => err(~"Invalid hour")
}
}
- 'M' {
+ 'M' => {
// FIXME (#2350): range check.
alt match_digits(s, pos, 2u, false) {
- some(item) { let (v, pos) = item; tm.tm_min = v; ok(pos) }
- none { err(~"Invalid minute") }
+ some(item) => { let (v, pos) = item; tm.tm_min = v; ok(pos) }
+ none => err(~"Invalid minute")
}
}
- 'm' {
+ 'm' => {
// FIXME (#2350): range check.
alt match_digits(s, pos, 2u, false) {
- some(item) {
+ some(item) => {
let (v, pos) = item;
tm.tm_mon = v - 1_i32;
ok(pos)
}
- none { err(~"Invalid month") }
+ none => err(~"Invalid month")
}
}
- 'n' { parse_char(s, pos, '\n') }
- 'P' {
- alt match_strs(s, pos, ~[(~"am", 0_i32), (~"pm", 12_i32)]) {
- some(item) { let (v, pos) = item; tm.tm_hour += v; ok(pos) }
- none { err(~"Invalid hour") }
- }
+ 'n' => parse_char(s, pos, '\n'),
+ 'P' => alt match_strs(s, pos, ~[(~"am", 0_i32), (~"pm", 12_i32)]) {
+ some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) }
+ none => err(~"Invalid hour")
}
- 'p' {
- alt match_strs(s, pos, ~[(~"AM", 0_i32), (~"PM", 12_i32)]) {
- some(item) { let (v, pos) = item; tm.tm_hour += v; ok(pos) }
- none { err(~"Invalid hour") }
- }
+ 'p' => alt match_strs(s, pos, ~[(~"AM", 0_i32), (~"PM", 12_i32)]) {
+ some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) }
+ none => err(~"Invalid hour")
}
- 'R' {
+ 'R' => {
parse_type(s, pos, 'H', tm)
.chain(|pos| parse_char(s, pos, ':'))
.chain(|pos| parse_type(s, pos, 'M', tm))
}
- 'r' {
+ 'r' => {
parse_type(s, pos, 'I', tm)
.chain(|pos| parse_char(s, pos, ':'))
.chain(|pos| parse_type(s, pos, 'M', tm))
.chain(|pos| parse_char(s, pos, ' '))
.chain(|pos| parse_type(s, pos, 'p', tm))
}
- 'S' {
+ 'S' => {
// FIXME (#2350): range check.
alt match_digits(s, pos, 2u, false) {
- some(item) {
+ some(item) => {
let (v, pos) = item;
tm.tm_sec = v;
ok(pos)
}
- none { err(~"Invalid second") }
+ none => err(~"Invalid second")
}
}
//'s' {}
- 'T' | 'X' {
+ 'T' | 'X' => {
parse_type(s, pos, 'H', tm)
.chain(|pos| parse_char(s, pos, ':'))
.chain(|pos| parse_type(s, pos, 'M', tm))
.chain(|pos| parse_char(s, pos, ':'))
.chain(|pos| parse_type(s, pos, 'S', tm))
}
- 't' { parse_char(s, pos, '\t') }
- 'u' {
+ 't' => parse_char(s, pos, '\t'),
+ 'u' => {
// FIXME (#2350): range check.
alt match_digits(s, pos, 1u, false) {
- some(item) {
+ some(item) => {
let (v, pos) = item;
tm.tm_wday = v;
ok(pos)
}
- none { err(~"Invalid weekday") }
+ none => err(~"Invalid weekday")
}
}
- 'v' {
+ 'v' => {
parse_type(s, pos, 'e', tm)
.chain(|pos| parse_char(s, pos, '-'))
.chain(|pos| parse_type(s, pos, 'b', tm))
.chain(|pos| parse_type(s, pos, 'Y', tm))
}
//'W' {}
- 'w' {
+ 'w' => {
// FIXME (#2350): range check.
alt match_digits(s, pos, 1u, false) {
- some(item) { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
- none { err(~"Invalid weekday") }
+ some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
+ none => err(~"Invalid weekday")
}
}
//'X' {}
//'x' {}
- 'Y' {
+ 'Y' => {
// FIXME (#2350): range check.
alt match_digits(s, pos, 4u, false) {
- some(item) {
+ some(item) => {
let (v, pos) = item;
tm.tm_year = v - 1900_i32;
ok(pos)
}
- none { err(~"Invalid weekday") }
+ none => err(~"Invalid weekday")
}
}
- 'y' {
+ 'y' => {
// FIXME (#2350): range check.
alt match_digits(s, pos, 2u, false) {
- some(item) {
+ some(item) => {
let (v, pos) = item;
tm.tm_year = v - 1900_i32;
ok(pos)
}
- none { err(~"Invalid weekday") }
+ none => err(~"Invalid weekday")
}
}
- 'Z' {
+ 'Z' => {
if match_str(s, pos, ~"UTC") || match_str(s, pos, ~"GMT") {
tm.tm_gmtoff = 0_i32;
tm.tm_zone = ~"UTC";
ok(pos)
}
}
- 'z' {
+ 'z' => {
let {ch, next} = str::char_range_at(s, pos);
if ch == '+' || ch == '-' {
alt match_digits(s, next, 4u, false) {
- some(item) {
+ some(item) => {
let (v, pos) = item;
if v == 0_i32 {
tm.tm_gmtoff = 0_i32;
ok(pos)
}
- none { err(~"Invalid zone offset") }
+ none => err(~"Invalid zone offset")
}
} else {
err(~"Invalid zone offset")
}
}
- '%' { parse_char(s, pos, '%') }
- ch {
+ '%' => parse_char(s, pos, '%'),
+ ch => {
err(fmt!{"unknown formatting type: %?", str::from_char(ch)})
}
}
let {ch, next} = str::char_range_at(s, pos);
alt rdr.read_char() {
- '%' {
- alt parse_type(s, pos, rdr.read_char(), tm) {
- ok(next) { pos = next; }
- err(e) { result = err(e); break; }
- }
+ '%' => alt parse_type(s, pos, rdr.read_char(), tm) {
+ ok(next) => pos = next,
+ err(e) => { result = err(e); break; }
}
- c {
+ c => {
if c != ch { break }
pos = next;
}
fn parse_type(ch: char, tm: tm) -> ~str {
//FIXME (#2350): Implement missing types.
alt check ch {
- 'A' {
- alt check tm.tm_wday as int {
- 0 { ~"Sunday" }
- 1 { ~"Monday" }
- 2 { ~"Tuesday" }
- 3 { ~"Wednesday" }
- 4 { ~"Thursday" }
- 5 { ~"Friday" }
- 6 { ~"Saturday" }
- }
+ 'A' => alt check tm.tm_wday as int {
+ 0 => ~"Sunday",
+ 1 => ~"Monday",
+ 2 => ~"Tuesday",
+ 3 => ~"Wednesday",
+ 4 => ~"Thursday",
+ 5 => ~"Friday",
+ 6 => ~"Saturday"
}
- 'a' {
- alt check tm.tm_wday as int {
- 0 { ~"Sun" }
- 1 { ~"Mon" }
- 2 { ~"Tue" }
- 3 { ~"Wed" }
- 4 { ~"Thu" }
- 5 { ~"Fri" }
- 6 { ~"Sat" }
- }
+ 'a' => alt check tm.tm_wday as int {
+ 0 => ~"Sun",
+ 1 => ~"Mon",
+ 2 => ~"Tue",
+ 3 => ~"Wed",
+ 4 => ~"Thu",
+ 5 => ~"Fri",
+ 6 => ~"Sat"
}
- 'B' {
- alt check tm.tm_mon as int {
- 0 { ~"January" }
- 1 { ~"February" }
- 2 { ~"March" }
- 3 { ~"April" }
- 4 { ~"May" }
- 5 { ~"June" }
- 6 { ~"July" }
- 7 { ~"August" }
- 8 { ~"September" }
- 9 { ~"October" }
- 10 { ~"November" }
- 11 { ~"December" }
- }
+ 'B' => alt check tm.tm_mon as int {
+ 0 => ~"January",
+ 1 => ~"February",
+ 2 => ~"March",
+ 3 => ~"April",
+ 4 => ~"May",
+ 5 => ~"June",
+ 6 => ~"July",
+ 7 => ~"August",
+ 8 => ~"September",
+ 9 => ~"October",
+ 10 => ~"November",
+ 11 => ~"December"
}
- 'b' | 'h' {
- alt check tm.tm_mon as int {
- 0 { ~"Jan" }
- 1 { ~"Feb" }
- 2 { ~"Mar" }
- 3 { ~"Apr" }
- 4 { ~"May" }
- 5 { ~"Jun" }
- 6 { ~"Jul" }
- 7 { ~"Aug" }
- 8 { ~"Sep" }
- 9 { ~"Oct" }
- 10 { ~"Nov" }
- 11 { ~"Dec" }
- }
+ 'b' | 'h' => alt check tm.tm_mon as int {
+ 0 => ~"Jan",
+ 1 => ~"Feb",
+ 2 => ~"Mar",
+ 3 => ~"Apr",
+ 4 => ~"May",
+ 5 => ~"Jun",
+ 6 => ~"Jul",
+ 7 => ~"Aug",
+ 8 => ~"Sep",
+ 9 => ~"Oct",
+ 10 => ~"Nov",
+ 11 => ~"Dec",
}
- 'C' { fmt!{"%02d", (tm.tm_year as int + 1900) / 100} }
- 'c' {
+ 'C' => fmt!{"%02d", (tm.tm_year as int + 1900) / 100},
+ 'c' => {
fmt!{"%s %s %s %s %s",
parse_type('a', tm),
parse_type('b', tm),
parse_type('T', tm),
parse_type('Y', tm)}
}
- 'D' | 'x' {
+ 'D' | 'x' => {
fmt!{"%s/%s/%s",
parse_type('m', tm),
parse_type('d', tm),
parse_type('y', tm)}
}
- 'd' { fmt!{"%02d", tm.tm_mday as int} }
- 'e' { fmt!{"%2d", tm.tm_mday as int} }
- 'F' {
+ 'd' => fmt!{"%02d", tm.tm_mday as int},
+ 'e' => fmt!{"%2d", tm.tm_mday as int},
+ 'F' => {
fmt!{"%s-%s-%s",
parse_type('Y', tm),
parse_type('m', tm),
}
//'G' {}
//'g' {}
- 'H' { fmt!{"%02d", tm.tm_hour as int} }
- 'I' {
+ 'H' => fmt!{"%02d", tm.tm_hour as int},
+ 'I' => {
let mut h = tm.tm_hour as int;
if h == 0 { h = 12 }
if h > 12 { h -= 12 }
fmt!{"%02d", h}
}
- 'j' { fmt!{"%03d", tm.tm_yday as int + 1} }
- 'k' { fmt!{"%2d", tm.tm_hour as int} }
- 'l' {
+ 'j' => fmt!{"%03d", tm.tm_yday as int + 1},
+ 'k' => fmt!{"%2d", tm.tm_hour as int},
+ 'l' => {
let mut h = tm.tm_hour as int;
if h == 0 { h = 12 }
if h > 12 { h -= 12 }
fmt!{"%2d", h}
}
- 'M' { fmt!{"%02d", tm.tm_min as int} }
- 'm' { fmt!{"%02d", tm.tm_mon as int + 1} }
- 'n' { ~"\n" }
- 'P' { if tm.tm_hour as int < 12 { ~"am" } else { ~"pm" } }
- 'p' { if tm.tm_hour as int < 12 { ~"AM" } else { ~"PM" } }
- 'R' {
+ 'M' => fmt!{"%02d", tm.tm_min as int},
+ 'm' => fmt!{"%02d", tm.tm_mon as int + 1},
+ 'n' => ~"\n",
+ 'P' => if tm.tm_hour as int < 12 { ~"am" } else { ~"pm" }
+ 'p' => if tm.tm_hour as int < 12 { ~"AM" } else { ~"PM" }
+ 'R' => {
fmt!{"%s:%s",
parse_type('H', tm),
parse_type('M', tm)}
}
- 'r' {
+ 'r' => {
fmt!{"%s:%s:%s %s",
parse_type('I', tm),
parse_type('M', tm),
parse_type('S', tm),
parse_type('p', tm)}
}
- 'S' { fmt!{"%02d", tm.tm_sec as int} }
- 's' { fmt!{"%d", tm.to_timespec().sec as int} }
- 'T' | 'X' {
+ 'S' => fmt!{"%02d", tm.tm_sec as int},
+ 's' => fmt!{"%d", tm.to_timespec().sec as int},
+ 'T' | 'X' => {
fmt!{"%s:%s:%s",
parse_type('H', tm),
parse_type('M', tm),
parse_type('S', tm)}
}
- 't' { ~"\t" }
+ 't' => ~"\t",
//'U' {}
- 'u' {
+ 'u' => {
let i = tm.tm_wday as int;
int::str(if i == 0 { 7 } else { i })
}
//'V' {}
- 'v' {
+ 'v' => {
fmt!{"%s-%s-%s",
parse_type('e', tm),
parse_type('b', tm),
parse_type('Y', tm)}
}
//'W' {}
- 'w' { int::str(tm.tm_wday as int) }
+ 'w' => int::str(tm.tm_wday as int),
//'X' {}
//'x' {}
- 'Y' { int::str(tm.tm_year as int + 1900) }
- 'y' { fmt!{"%02d", (tm.tm_year as int + 1900) % 100} }
- 'Z' { tm.tm_zone }
- 'z' {
+ 'Y' => int::str(tm.tm_year as int + 1900),
+ 'y' => fmt!{"%02d", (tm.tm_year as int + 1900) % 100},
+ 'Z' => tm.tm_zone,
+ 'z' => {
let sign = if tm.tm_gmtoff > 0_i32 { '+' } else { '-' };
let mut m = i32::abs(tm.tm_gmtoff) / 60_i32;
let h = m / 60_i32;
fmt!{"%c%02d%02d", sign, h as int, m as int}
}
//'+' {}
- '%' { ~"%" }
+ '%' => ~"%"
}
}
do io::with_str_reader(format) |rdr| {
while !rdr.eof() {
alt rdr.read_char() {
- '%' { buf += parse_type(rdr.read_char(), tm); }
- ch { str::push_char(buf, ch); }
+ '%' => buf += parse_type(rdr.read_char(), tm),
+ ch => str::push_char(buf, ch)
}
}
}
tzset();
alt strptime(~"", ~"") {
- ok(tm) {
+ ok(tm) => {
assert tm.tm_sec == 0_i32;
assert tm.tm_min == 0_i32;
assert tm.tm_hour == 0_i32;
assert tm.tm_zone == ~"";
assert tm.tm_nsec == 0_i32;
}
- err(_) {}
+ err(_) => ()
}
let format = ~"%a %b %e %T %Y";
== err(~"Invalid time");
alt strptime(~"Fri Feb 13 15:31:30 2009", format) {
- err(e) { fail e }
- ok(tm) {
+ err(e) => fail e,
+ ok(tm) => {
assert tm.tm_sec == 30_i32;
assert tm.tm_min == 31_i32;
assert tm.tm_hour == 15_i32;
fn test(s: ~str, format: ~str) -> bool {
alt strptime(s, format) {
- ok(tm) { tm.strftime(format) == s }
- err(e) { fail e }
+ ok(tm) => tm.strftime(format) == s,
+ err(e) => fail e
}
}
};
alt recv_timeout(hl_loop, 10u, test_po) {
- some(val) { assert val == expected; successes += 1; }
- _ { failures += 1; }
+ some(val) => {
+ assert val == expected;
+ successes += 1;
+ }
+ _ => failures += 1
};
}
};
alt recv_timeout(hl_loop, 1u, test_po) {
- none { successes += 1; }
- _ { failures += 1; }
+ none => successes += 1,
+ _ => failures += 1
};
}
/// Insert a value into the map
fn insert<K: copy, V: copy>(m: &mut tree_edge<K, V>, k: K, v: V) {
alt copy *m {
- none {
+ none => {
*m = some(@tree_node({key: k,
mut value: v,
mut left: none,
mut right: none}));
return;
}
- some(node) {
+ some(node) => {
if k == node.key {
node.value = v;
} else if k < node.key {
/// Find a value based on the key
fn find<K: copy, V: copy>(m: &const tree_edge<K, V>, k: K) -> option<V> {
alt copy *m {
- none { none }
+ none => none,
// FIXME (#2808): was that an optimization?
- some(node) {
+ some(node) => {
if k == node.key {
some(node.value)
} else if k < node.key {
/// Visit all pairs in the map in order.
fn traverse<K, V: copy>(m: &const tree_edge<K, V>, f: fn(K, V)) {
alt copy *m {
- none { }
- some(node) {
+ none => (),
+ some(node) => {
traverse(&const node.left, f);
// copy of value is req'd as f() requires an immutable ptr
f(node.key, copy node.value);
loop {
debug!{"in outer_loop..."};
alt select2(weak_exit_po, msg_po) {
- left(weak_exit) {
+ left(weak_exit) => {
// all normal tasks have ended, tell the
// libuv loop to tear_down, then exit
debug!{"weak_exit_po recv'd msg: %?", weak_exit};
iotask::exit(hl_loop);
break;
}
- right(fetch_ch) {
+ right(fetch_ch) => {
debug!{"hl_loop req recv'd: %?", fetch_ch};
fetch_ch.send(hl_loop);
}
while msg_po.peek() {
alt msg_po.recv() {
- interaction(cb) {
- cb(loop_ptr);
- }
- teardown_loop {
- begin_teardown(data);
- }
+ interaction(cb) => cb(loop_ptr),
+ teardown_loop => begin_teardown(data)
}
}
}
let result = rustrt::rust_uv_ip6_name(src_unsafe_ptr,
dst_buf, size as libc::size_t);
alt result {
- 0i32 {
- str::unsafe::from_buf(dst_buf)
- }
- _ {
- ~""
- }
+ 0i32 => str::unsafe::from_buf(dst_buf),
+ _ => ~""
}
}
}
pure fn is_blockish(p: ast::proto) -> bool {
alt p {
- proto_block { true }
- proto_bare | proto_uniq | proto_box { false }
+ proto_block => true,
+ proto_bare | proto_uniq | proto_box => false
}
}
fn path_to_str_with_sep(p: path, sep: ~str) -> ~str {
let strs = do vec::map(p) |e| {
alt e {
- path_mod(s) { /* FIXME (#2543) */ copy *s }
- path_name(s) { /* FIXME (#2543) */ copy *s }
+ path_mod(s) => /* FIXME (#2543) */ copy *s,
+ path_name(s) => /* FIXME (#2543) */ copy *s
}
};
str::connect(strs, sep)
// don't decode and instantiate the impl, but just the method, we have to
// add it to the table now:
alt ii {
- ii_item(*) | ii_ctor(*) | ii_dtor(*) { /* fallthrough */ }
- ii_foreign(i) {
+ ii_item(*) | ii_ctor(*) | ii_dtor(*) => { /* fallthrough */ }
+ ii_foreign(i) => {
cx.map.insert(i.id, node_foreign_item(i, foreign_abi_rust_intrinsic,
@path));
}
- ii_method(impl_did, m) {
+ ii_method(impl_did, m) => {
map_method(impl_did, @path, m, cx);
}
}
cx.local_id += 1u;
}
alt fk {
- visit::fk_ctor(nm, attrs, tps, self_id, parent_id) {
+ visit::fk_ctor(nm, attrs, tps, self_id, parent_id) => {
let ct = @{node: {id: id,
attrs: attrs,
self_id: self_id,
ct, parent_id,
@/* FIXME (#2543) */ copy cx.path));
}
- visit::fk_dtor(tps, attrs, self_id, parent_id) {
+ visit::fk_dtor(tps, attrs, self_id, parent_id) => {
let dt = @{node: {id: id, attrs: attrs, self_id: self_id,
body: /* FIXME (#2543) */ copy body}, span: sp};
cx.map.insert(id, node_dtor(/* FIXME (#2543) */ copy tps, dt,
parent_id,
@/* FIXME (#2543) */ copy cx.path));
}
- _ {}
+ _ => ()
}
visit::visit_fn(fk, decl, body, sp, id, cx, v);
}
fn number_pat(cx: ctx, pat: @pat) {
do ast_util::walk_pat(pat) |p| {
alt p.node {
- pat_ident(*) {
+ pat_ident(*) => {
cx.map.insert(p.id, node_local(cx.local_id));
cx.local_id += 1u;
}
- _ {}
+ _ => ()
}
};
}
let item_path = @/* FIXME (#2543) */ copy cx.path;
cx.map.insert(i.id, node_item(i, item_path));
alt i.node {
- item_impl(_, opt_ir, _, ms) {
+ item_impl(_, opt_ir, _, ms) => {
let impl_did = ast_util::local_def(i.id);
for ms.each |m| {
map_method(impl_did, extend(cx, i.ident), m,
cx);
}
}
- item_enum(vs, _) {
+ item_enum(vs, _) => {
for vs.each |v| {
cx.map.insert(v.node.id, node_variant(
/* FIXME (#2543) */ copy v, i,
extend(cx, i.ident)));
}
}
- item_foreign_mod(nm) {
+ item_foreign_mod(nm) => {
let abi = alt attr::foreign_abi(i.attrs) {
- either::left(msg) { cx.diag.span_fatal(i.span, msg); }
- either::right(abi) { abi }
+ either::left(msg) => cx.diag.span_fatal(i.span, msg),
+ either::right(abi) => abi
};
for nm.items.each |nitem| {
cx.map.insert(nitem.id,
extend(cx, i.ident)));
}
}
- item_class(tps, traits, items, ctor, dtor) {
+ item_class(tps, traits, items, ctor, dtor) => {
let (_, ms) = ast_util::split_class_items(items);
// Map trait refs to their parent classes. This is
// so we can find the self_ty
// only need to handle methods
do vec::iter(ms) |m| { map_method(d_id, p, m, cx); }
}
- item_trait(tps, traits, methods) {
+ item_trait(tps, traits, methods) => {
// Map trait refs to their parent classes. This is
// so we can find the self_ty
for traits.each |p| {
cx.map.insert(id, node_trait_method(@tm, d_id, item_path));
}
}
- _ { }
+ _ => ()
}
alt i.node {
- item_mod(_) | item_foreign_mod(_) {
+ item_mod(_) | item_foreign_mod(_) => {
vec::push(cx.path, path_mod(i.ident));
}
- _ { vec::push(cx.path, path_name(i.ident)); }
+ _ => vec::push(cx.path, path_name(i.ident))
}
visit::visit_item(i, cx, v);
vec::pop(cx.path);
fn map_view_item(vi: @view_item, cx: ctx, _v: vt) {
alt vi.node {
- view_item_export(vps) {
- for vps.each |vp| {
- let (id, name) = alt vp.node {
- view_path_simple(nm, _, id) {
- (id, /* FIXME (#2543) */ copy nm)
- }
- view_path_glob(pth, id) | view_path_list(pth, _, id) {
- (id, path_to_ident(pth))
- }
- };
- cx.map.insert(id, node_export(vp, extend(cx, name)));
- }
+ view_item_export(vps) => for vps.each |vp| {
+ let (id, name) = alt vp.node {
+ view_path_simple(nm, _, id) => {
+ (id, /* FIXME (#2543) */ copy nm)
+ }
+ view_path_glob(pth, id) | view_path_list(pth, _, id) => {
+ (id, path_to_ident(pth))
+ }
+ };
+ cx.map.insert(id, node_export(vp, extend(cx, name)));
}
- _ {}
+ _ => ()
}
}
fn node_id_to_str(map: map, id: node_id) -> ~str {
alt map.find(id) {
- none {
+ none => {
fmt!{"unknown node (id=%d)", id}
}
- some(node_item(item, path)) {
+ some(node_item(item, path)) => {
fmt!{"item %s (id=%?)", path_ident_to_str(*path, item.ident), id}
}
- some(node_foreign_item(item, abi, path)) {
+ some(node_foreign_item(item, abi, path)) => {
fmt!{"foreign item %s with abi %? (id=%?)",
path_ident_to_str(*path, item.ident), abi, id}
}
- some(node_method(m, impl_did, path)) {
+ some(node_method(m, impl_did, path)) => {
fmt!{"method %s in %s (id=%?)",
*m.ident, path_to_str(*path), id}
}
- some(node_trait_method(tm, impl_did, path)) {
+ some(node_trait_method(tm, impl_did, path)) => {
let m = ast_util::trait_method_to_ty_method(*tm);
fmt!{"method %s in %s (id=%?)",
*m.ident, path_to_str(*path), id}
}
- some(node_variant(variant, def_id, path)) {
+ some(node_variant(variant, def_id, path)) => {
fmt!{"variant %s in %s (id=%?)",
*variant.node.name, path_to_str(*path), id}
}
- some(node_expr(expr)) {
+ some(node_expr(expr)) => {
fmt!{"expr %s (id=%?)",
pprust::expr_to_str(expr), id}
}
// FIXMEs are as per #2410
- some(node_export(_, path)) {
+ some(node_export(_, path)) => {
fmt!{"export %s (id=%?)", // add more info here
path_to_str(*path), id}
}
- some(node_arg(_, _)) { // add more info here
+ some(node_arg(_, _)) => { // add more info here
fmt!{"arg (id=%?)", id}
}
- some(node_local(_)) { // add more info here
+ some(node_local(_)) => { // add more info here
fmt!{"local (id=%?)", id}
}
- some(node_ctor(*)) { // add more info here
+ some(node_ctor(*)) => { // add more info here
fmt!{"node_ctor (id=%?)", id}
}
- some(node_dtor(*)) { // add more info here
+ some(node_dtor(*)) => { // add more info here
fmt!{"node_dtor (id=%?)", id}
}
- some(node_block(_)) {
+ some(node_block(_)) => {
fmt!{"block"}
}
}
pure fn stmt_id(s: stmt) -> node_id {
alt s.node {
- stmt_decl(_, id) { id }
- stmt_expr(_, id) { id }
- stmt_semi(_, id) { id }
+ stmt_decl(_, id) => id,
+ stmt_expr(_, id) => id,
+ stmt_semi(_, id) => id
}
}
fn variant_def_ids(d: def) -> {enm: def_id, var: def_id} {
- alt d { def_variant(enum_id, var_id) {
- return {enm: enum_id, var: var_id}; }
- _ { fail ~"non-variant in variant_def_ids"; } }
+ alt d {
+ def_variant(enum_id, var_id) => {
+ return {enm: enum_id, var: var_id}
+ }
+ _ => fail ~"non-variant in variant_def_ids"
+ }
}
pure fn def_id_of_def(d: def) -> def_id {
def_fn(id, _) | def_mod(id) |
def_foreign_mod(id) | def_const(id) |
def_variant(_, id) | def_ty(id) | def_ty_param(id, _) |
- def_use(id) | def_class(id, _) { id }
+ def_use(id) | def_class(id, _) => {
+ id
+ }
def_arg(id, _) | def_local(id, _) | def_self(id) |
def_upvar(id, _, _) | def_binding(id, _) | def_region(id)
- | def_typaram_binder(id) {
+ | def_typaram_binder(id) => {
local_def(id)
}
- def_prim_ty(_) { fail; }
+ def_prim_ty(_) => fail
}
}
pure fn binop_to_str(op: binop) -> ~str {
alt op {
- add { return ~"+"; }
- subtract { return ~"-"; }
- mul { return ~"*"; }
- div { return ~"/"; }
- rem { return ~"%"; }
- and { return ~"&&"; }
- or { return ~"||"; }
- bitxor { return ~"^"; }
- bitand { return ~"&"; }
- bitor { return ~"|"; }
- shl { return ~"<<"; }
- shr { return ~">>"; }
- eq { return ~"=="; }
- lt { return ~"<"; }
- le { return ~"<="; }
- ne { return ~"!="; }
- ge { return ~">="; }
- gt { return ~">"; }
+ add => return ~"+",
+ subtract => return ~"-",
+ mul => return ~"*",
+ div => return ~"/",
+ rem => return ~"%",
+ and => return ~"&&",
+ or => return ~"||",
+ bitxor => return ~"^",
+ bitand => return ~"&",
+ bitor => return ~"|",
+ shl => return ~"<<",
+ shr => return ~">>",
+ eq => return ~"==",
+ lt => return ~"<",
+ le => return ~"<=",
+ ne => return ~"!=",
+ ge => return ~">=",
+ gt => return ~">"
}
}
pure fn binop_to_method_name(op: binop) -> option<~str> {
alt op {
- add { return some(~"add"); }
- subtract { return some(~"sub"); }
- mul { return some(~"mul"); }
- div { return some(~"div"); }
- rem { return some(~"modulo"); }
- bitxor { return some(~"bitxor"); }
- bitand { return some(~"bitand"); }
- bitor { return some(~"bitor"); }
- shl { return some(~"shl"); }
- shr { return some(~"shr"); }
- and | or | eq | lt | le | ne | ge | gt { return none; }
+ add => return some(~"add"),
+ subtract => return some(~"sub"),
+ mul => return some(~"mul"),
+ div => return some(~"div"),
+ rem => return some(~"modulo"),
+ bitxor => return some(~"bitxor"),
+ bitand => return some(~"bitand"),
+ bitor => return some(~"bitor"),
+ shl => return some(~"shl"),
+ shr => return some(~"shr"),
+ and | or | eq | lt | le | ne | ge | gt => return none
}
}
pure fn lazy_binop(b: binop) -> bool {
- alt b { and { true } or { true } _ { false } }
+ alt b {
+ and => true,
+ or => true,
+ _ => false
+ }
}
pure fn is_shift_binop(b: binop) -> bool {
alt b {
- shl { true }
- shr { true }
- _ { false }
+ shl => true,
+ shr => true,
+ _ => false
}
}
pure fn unop_to_str(op: unop) -> ~str {
alt op {
- box(mt) { if mt == m_mutbl { ~"@mut " } else { ~"@" } }
- uniq(mt) { if mt == m_mutbl { ~"~mut " } else { ~"~" } }
- deref { ~"*" }
- not { ~"!" }
- neg { ~"-" }
+ box(mt) => if mt == m_mutbl { ~"@mut " } else { ~"@" },
+ uniq(mt) => if mt == m_mutbl { ~"~mut " } else { ~"~" },
+ deref => ~"*",
+ not => ~"!",
+ neg => ~"-"
}
}
pure fn is_path(e: @expr) -> bool {
- return alt e.node { expr_path(_) { true } _ { false } };
+ return alt e.node { expr_path(_) => true, _ => false };
}
pure fn int_ty_to_str(t: int_ty) -> ~str {
alt t {
- ty_char { ~"u8" } // ???
- ty_i { ~"" } ty_i8 { ~"i8" } ty_i16 { ~"i16" }
- ty_i32 { ~"i32" } ty_i64 { ~"i64" }
+ ty_char => ~"u8", // ???
+ ty_i => ~"",
+ ty_i8 => ~"i8",
+ ty_i16 => ~"i16",
+ ty_i32 => ~"i32",
+ ty_i64 => ~"i64"
}
}
pure fn int_ty_max(t: int_ty) -> u64 {
alt t {
- ty_i8 { 0x80u64 }
- ty_i16 { 0x8000u64 }
- ty_i | ty_char | ty_i32 { 0x80000000u64 } // actually ni about ty_i
- ty_i64 { 0x8000000000000000u64 }
+ ty_i8 => 0x80u64,
+ ty_i16 => 0x8000u64,
+ ty_i | ty_char | ty_i32 => 0x80000000u64, // actually ni about ty_i
+ ty_i64 => 0x8000000000000000u64
}
}
pure fn uint_ty_to_str(t: uint_ty) -> ~str {
alt t {
- ty_u { ~"u" } ty_u8 { ~"u8" } ty_u16 { ~"u16" }
- ty_u32 { ~"u32" } ty_u64 { ~"u64" }
+ ty_u => ~"u",
+ ty_u8 => ~"u8",
+ ty_u16 => ~"u16",
+ ty_u32 => ~"u32",
+ ty_u64 => ~"u64"
}
}
pure fn uint_ty_max(t: uint_ty) -> u64 {
alt t {
- ty_u8 { 0xffu64 }
- ty_u16 { 0xffffu64 }
- ty_u | ty_u32 { 0xffffffffu64 } // actually ni about ty_u
- ty_u64 { 0xffffffffffffffffu64 }
+ ty_u8 => 0xffu64,
+ ty_u16 => 0xffffu64,
+ ty_u | ty_u32 => 0xffffffffu64, // actually ni about ty_u
+ ty_u64 => 0xffffffffffffffffu64
}
}
pure fn float_ty_to_str(t: float_ty) -> ~str {
- alt t { ty_f { ~"f" } ty_f32 { ~"f32" } ty_f64 { ~"f64" } }
+ alt t { ty_f => ~"f", ty_f32 => ~"f32", ty_f64 => ~"f64" }
}
fn is_exported(i: ident, m: _mod) -> bool {
for m.items.each |it| {
if it.ident == i { local = true; }
alt it.node {
- item_enum(variants, _) {
- for variants.each |v| {
- if v.node.name == i {
- local = true;
- parent_enum = some(/* FIXME (#2543) */ copy it.ident);
- }
+ item_enum(variants, _) => for variants.each |v| {
+ if v.node.name == i {
+ local = true;
+ parent_enum = some(/* FIXME (#2543) */ copy it.ident);
}
}
- _ { }
+ _ => ()
}
if local { break; }
}
let mut has_explicit_exports = false;
for m.view_items.each |vi| {
alt vi.node {
- view_item_export(vps) {
+ view_item_export(vps) => {
has_explicit_exports = true;
for vps.each |vp| {
alt vp.node {
- ast::view_path_simple(id, _, _) {
+ ast::view_path_simple(id, _, _) => {
if id == i { return true; }
alt parent_enum {
- some(parent_enum_id) {
+ some(parent_enum_id) => {
if id == parent_enum_id { return true; }
}
- _ {}
+ _ => ()
}
}
- ast::view_path_list(path, ids, _) {
+ ast::view_path_list(path, ids, _) => {
if vec::len(path.idents) == 1u {
if i == path.idents[0] { return true; }
for ids.each |id| {
}
// FIXME: glob-exports aren't supported yet. (#2006)
- _ {}
+ _ => ()
}
}
}
- _ {}
+ _ => ()
}
}
// If there are no declared exports then
}
pure fn is_call_expr(e: @expr) -> bool {
- alt e.node { expr_call(_, _, _) { true } _ { false } }
+ alt e.node { expr_call(_, _, _) => true, _ => false }
}
pure fn eq_ty(a: &@ty, b: &@ty) -> bool { box::ptr_eq(*a, *b) }
pure fn is_unguarded(&&a: arm) -> bool {
alt a.guard {
- none { true }
- _ { false }
+ none => true,
+ _ => false
}
}
pure fn class_item_ident(ci: @class_member) -> ident {
alt ci.node {
- instance_var(i,_,_,_,_) { /* FIXME (#2543) */ copy i }
- class_method(it) { /* FIXME (#2543) */ copy it.ident }
+ instance_var(i,_,_,_,_) => /* FIXME (#2543) */ copy i,
+ class_method(it) => /* FIXME (#2543) */ copy it.ident
}
}
fn public_methods(ms: ~[@method]) -> ~[@method] {
vec::filter(ms,
|m| alt m.vis {
- public { true }
- _ { false }
+ public => true,
+ _ => false
})
}
let mut vs = ~[], ms = ~[];
for cs.each |c| {
alt c.node {
- instance_var(i, t, cm, id, vis) {
+ instance_var(i, t, cm, id, vis) => {
vec::push(vs, {ident: /* FIXME (#2543) */ copy i,
ty: t,
cm: cm,
id: id,
vis: vis});
}
- class_method(m) { vec::push(ms, m); }
+ class_method(m) => vec::push(ms, m)
}
};
(vs, ms)
// a default, pull out the useful fields to make a ty_method
fn trait_method_to_ty_method(method: trait_method) -> ty_method {
alt method {
- required(m) { m }
- provided(m) {
+ required(m) => m,
+ provided(m) => {
{ident: m.ident, attrs: m.attrs,
decl: m.decl, tps: m.tps, self_ty: m.self_ty,
id: m.id, span: m.span}
let mut reqd = ~[], provd = ~[];
for trait_methods.each |trt_method| {
alt trt_method {
- required(tm) { vec::push(reqd, tm); }
- provided(m) { vec::push(provd, m); }
+ required(tm) => vec::push(reqd, tm),
+ provided(m) => vec::push(provd, m)
}
};
(reqd, provd)
pure fn class_member_visibility(ci: @class_member) -> visibility {
alt ci.node {
- instance_var(_, _, _, _, vis) { vis }
- class_method(m) { m.vis }
+ instance_var(_, _, _, _, vis) => vis,
+ class_method(m) => m.vis
}
}
impl inlined_item_methods of inlined_item_utils for inlined_item {
fn ident() -> ident {
alt self {
- ii_item(i) { /* FIXME (#2543) */ copy i.ident }
- ii_foreign(i) { /* FIXME (#2543) */ copy i.ident }
- ii_method(_, m) { /* FIXME (#2543) */ copy m.ident }
- ii_ctor(_, nm, _, _) { /* FIXME (#2543) */ copy nm }
- ii_dtor(_, nm, _, _) { /* FIXME (#2543) */ copy nm }
+ ii_item(i) => /* FIXME (#2543) */ copy i.ident,
+ ii_foreign(i) => /* FIXME (#2543) */ copy i.ident,
+ ii_method(_, m) => /* FIXME (#2543) */ copy m.ident,
+ ii_ctor(_, nm, _, _) => /* FIXME (#2543) */ copy nm,
+ ii_dtor(_, nm, _, _) => /* FIXME (#2543) */ copy nm
}
}
fn id() -> ast::node_id {
alt self {
- ii_item(i) { i.id }
- ii_foreign(i) { i.id }
- ii_method(_, m) { m.id }
- ii_ctor(ctor, _, _, _) { ctor.node.id }
- ii_dtor(dtor, _, _, _) { dtor.node.id }
+ ii_item(i) => i.id,
+ ii_foreign(i) => i.id,
+ ii_method(_, m) => m.id,
+ ii_ctor(ctor, _, _, _) => ctor.node.id,
+ ii_dtor(dtor, _, _, _) => dtor.node.id
}
}
fn accept<E>(e: E, v: visit::vt<E>) {
alt self {
- ii_item(i) { v.visit_item(i, e, v) }
- ii_foreign(i) { v.visit_foreign_item(i, e, v) }
- ii_method(_, m) { visit::visit_method_helper(m, e, v) }
- ii_ctor(ctor, nm, tps, parent_id) {
+ ii_item(i) => v.visit_item(i, e, v),
+ ii_foreign(i) => v.visit_foreign_item(i, e, v),
+ ii_method(_, m) => visit::visit_method_helper(m, e, v),
+ ii_ctor(ctor, nm, tps, parent_id) => {
visit::visit_class_ctor_helper(ctor, nm, tps, parent_id, e, v);
}
- ii_dtor(dtor, nm, tps, parent_id) {
+ ii_dtor(dtor, nm, tps, parent_id) => {
visit::visit_class_dtor_helper(dtor, tps, parent_id, e, v);
}
}
referring to a def_self */
fn is_self(d: ast::def) -> bool {
alt d {
- def_self(_) { true }
- def_upvar(_, d, _) { is_self(*d) }
- _ { false }
+ def_self(_) => true,
+ def_upvar(_, d, _) => is_self(*d),
+ _ => false
}
}
/// Maps a binary operator to its precedence
fn operator_prec(op: ast::binop) -> uint {
alt op {
- mul | div | rem { 12u }
+ mul | div | rem => 12u,
// 'as' sits between here with 11
- add | subtract { 10u }
- shl | shr { 9u }
- bitand { 8u }
- bitxor { 7u }
- bitor { 6u }
- lt | le | ge | gt { 4u }
- eq | ne { 3u }
- and { 2u }
- or { 1u }
+ add | subtract => 10u,
+ shl | shr => 9u,
+ bitand => 8u,
+ bitxor => 7u,
+ bitor => 6u,
+ lt | le | ge | gt => 4u,
+ eq | ne => 3u,
+ and => 2u,
+ or => 1u
}
}
visit_view_item: fn@(vi: @view_item) {
alt vi.node {
- view_item_use(_, _, id) { vfn(id) }
- view_item_import(vps) | view_item_export(vps) {
+ view_item_use(_, _, id) => vfn(id),
+ view_item_import(vps) | view_item_export(vps) => {
do vec::iter(vps) |vp| {
alt vp.node {
- view_path_simple(_, _, id) { vfn(id) }
- view_path_glob(_, id) { vfn(id) }
- view_path_list(_, _, id) { vfn(id) }
+ view_path_simple(_, _, id) => vfn(id),
+ view_path_glob(_, id) => vfn(id),
+ view_path_list(_, _, id) => vfn(id)
}
}
}
visit_item: fn@(i: @item) {
vfn(i.id);
alt i.node {
- item_enum(vs, _) { for vs.each |v| { vfn(v.node.id); } }
- _ {}
+ item_enum(vs, _) => for vs.each |v| { vfn(v.node.id); }
+ _ => ()
}
},
visit_ty: fn@(t: @ty) {
alt t.node {
- ty_path(_, id) {
- vfn(id)
- }
- _ { /* fall through */ }
+ ty_path(_, id) => vfn(id),
+ _ => { /* fall through */ }
}
},
vfn(id);
alt fk {
- visit::fk_ctor(nm, _, tps, self_id, parent_id) {
+ visit::fk_ctor(nm, _, tps, self_id, parent_id) => {
vec::iter(tps, |tp| vfn(tp.id));
vfn(id);
vfn(self_id);
vfn(parent_id.node);
}
- visit::fk_dtor(tps, _, self_id, parent_id) {
+ visit::fk_dtor(tps, _, self_id, parent_id) => {
vec::iter(tps, |tp| vfn(tp.id));
vfn(id);
vfn(self_id);
vfn(parent_id.node);
}
- visit::fk_item_fn(_, tps) {
+ visit::fk_item_fn(_, tps) => {
vec::iter(tps, |tp| vfn(tp.id));
}
- visit::fk_method(_, tps, m) {
+ visit::fk_method(_, tps, m) => {
vfn(m.self_id);
vec::iter(tps, |tp| vfn(tp.id));
}
visit::fk_anon(_, capture_clause)
- | visit::fk_fn_block(capture_clause) {
+ | visit::fk_fn_block(capture_clause) => {
for vec::each(*capture_clause) |clause| {
vfn(clause.id);
}
visit_class_item: fn@(c: @class_member) {
alt c.node {
- instance_var(_, _, _, id,_) {
- vfn(id)
- }
- class_method(_) {
- }
+ instance_var(_, _, _, id,_) => vfn(id),
+ class_method(_) => ()
}
}
})
pure fn is_item_impl(item: @ast::item) -> bool {
alt item.node {
- item_impl(*) { true }
- _ { false }
+ item_impl(*) => true,
+ _ => false
}
}
fn walk_pat(pat: @pat, it: fn(@pat)) {
it(pat);
alt pat.node {
- pat_ident(_, pth, some(p)) { walk_pat(p, it); }
- pat_rec(fields, _) {
- for fields.each |f| { walk_pat(f.pat, it); }
- }
- pat_enum(_, some(s)) | pat_tup(s) {
- for s.each |p| { walk_pat(p, it); }
+ pat_ident(_, pth, some(p)) => walk_pat(p, it),
+ pat_rec(fields, _) => for fields.each |f| { walk_pat(f.pat, it) }
+ pat_enum(_, some(s)) | pat_tup(s) => for s.each |p| {
+ walk_pat(p, it)
}
- pat_box(s) | pat_uniq(s) { walk_pat(s, it); }
+ pat_box(s) | pat_uniq(s) => walk_pat(s, it),
pat_wild | pat_lit(_) | pat_range(_, _) | pat_ident(_, _, _)
- | pat_enum(_, _) {}
+ | pat_enum(_, _) => ()
}
}
fn view_path_id(p: @view_path) -> node_id {
alt p.node {
view_path_simple(_, _, id) | view_path_glob(_, id) |
- view_path_list(_, _, id) { id }
+ view_path_list(_, _, id) => id
}
}
// All "bad" FIXME copies are as per #2543
fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident {
alt meta.node {
- ast::meta_word(n) { /* FIXME (#2543) */ copy n }
- ast::meta_name_value(n, _) { /* FIXME (#2543) */ copy n }
- ast::meta_list(n, _) { /* FIXME (#2543) */ copy n }
+ ast::meta_word(n) => /* FIXME (#2543) */ copy n,
+ ast::meta_name_value(n, _) => /* FIXME (#2543) */ copy n,
+ ast::meta_list(n, _) => /* FIXME (#2543) */ copy n
}
}
*/
fn get_meta_item_value_str(meta: @ast::meta_item) -> option<@~str> {
alt meta.node {
- ast::meta_name_value(_, v) {
- alt v.node {
- ast::lit_str(s) {
- option::some(s)
- }
- _ {
- option::none
- }
- }
+ ast::meta_name_value(_, v) => alt v.node {
+ ast::lit_str(s) => option::some(s),
+ _ => option::none
}
- _ { option::none }
+ _ => option::none
}
}
/// Gets a list of inner meta items from a list meta_item type
fn get_meta_item_list(meta: @ast::meta_item) -> option<~[@ast::meta_item]> {
alt meta.node {
- ast::meta_list(_, l) { option::some(/* FIXME (#2543) */ copy l) }
- _ { option::none }
+ ast::meta_list(_, l) => option::some(/* FIXME (#2543) */ copy l),
+ _ => option::none
}
}
item: @ast::meta_item
) -> option<(ast::ident, @~str)> {
alt attr::get_meta_item_value_str(item) {
- some(value) {
+ some(value) => {
let name = attr::get_meta_item_name(item);
some((name, value))
}
- none { none }
+ none => none
}
}
fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
return alt a.node {
- ast::meta_word(na) {
- alt b.node { ast::meta_word(nb) { na == nb } _ { false } }
+ ast::meta_word(na) => alt b.node {
+ ast::meta_word(nb) => na == nb,
+ _ => false
}
- ast::meta_name_value(na, va) {
- alt b.node {
- ast::meta_name_value(nb, vb) { na == nb && va.node == vb.node }
- _ { false }
- }
+ ast::meta_name_value(na, va) => alt b.node {
+ ast::meta_name_value(nb, vb) => na == nb && va.node == vb.node,
+ _ => false
}
- ast::meta_list(na, la) {
+ ast::meta_list(na, la) => {
// ~[Fixme-sorting]
// FIXME (#607): Needs implementing
+name: ~str
) -> option<@~str> {
alt last_meta_item_by_name(items, name) {
- some(item) {
- alt attr::get_meta_item_value_str(item) {
- some(value) { some(value) }
- none { none }
- }
+ some(item) => alt attr::get_meta_item_value_str(item) {
+ some(value) => some(value),
+ none => none
}
- none { none }
+ none => none
}
}
+name: ~str
) -> option<~[@ast::meta_item]> {
alt last_meta_item_by_name(items, name) {
- some(item) {
- attr::get_meta_item_list(item)
- }
- none { none }
+ some(item) => attr::get_meta_item_list(item),
+ none => none
}
}
pure fn lteq(ma: &@ast::meta_item, mb: &@ast::meta_item) -> bool {
pure fn key(m: &ast::meta_item) -> ast::ident {
alt m.node {
- ast::meta_word(name) { /* FIXME (#2543) */ copy name }
- ast::meta_name_value(name, _) { /* FIXME (#2543) */ copy name }
- ast::meta_list(name, _) { /* FIXME (#2543) */ copy name }
+ ast::meta_word(name) => /* FIXME (#2543) */ copy name,
+ ast::meta_name_value(name, _) => /* FIXME (#2543) */ copy name,
+ ast::meta_list(name, _) => /* FIXME (#2543) */ copy name
}
}
key(*ma) <= key(*mb)
let mut found = ~[];
for find_attrs_by_name(attrs, ~"link").each |attr| {
alt attr.node.value.node {
- ast::meta_list(_, _) { vec::push(found, attr) }
- _ { debug!{"ignoring link attribute that has incorrect type"}; }
+ ast::meta_list(_, _) => vec::push(found, attr),
+ _ => debug!{"ignoring link attribute that has incorrect type"}
}
}
return found;
fn find_linkage_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] {
do find_linkage_attrs(attrs).flat_map |attr| {
alt check attr.node.value.node {
- ast::meta_list(_, items) { /* FIXME (#2543) */ copy items }
+ ast::meta_list(_, items) => /* FIXME (#2543) */ copy items
}
}
}
fn foreign_abi(attrs: ~[ast::attribute]) -> either<~str, ast::foreign_abi> {
return alt attr::first_attr_value_str_by_name(attrs, ~"abi") {
- option::none {
+ option::none => {
either::right(ast::foreign_abi_cdecl)
}
- option::some(@~"rust-intrinsic") {
+ option::some(@~"rust-intrinsic") => {
either::right(ast::foreign_abi_rust_intrinsic)
}
- option::some(@~"cdecl") {
+ option::some(@~"cdecl") => {
either::right(ast::foreign_abi_cdecl)
}
- option::some(@~"stdcall") {
+ option::some(@~"stdcall") => {
either::right(ast::foreign_abi_stdcall)
}
- option::some(t) {
+ option::some(t) => {
either::left(~"unsupported abi: " + *t)
}
};
// FIXME (#2809)---validate the usage of #[inline] and #[inline(always)]
do vec::foldl(ia_none, attrs) |ia,attr| {
alt attr.node.value.node {
- ast::meta_word(@~"inline") { ia_hint }
- ast::meta_list(@~"inline", items) {
+ ast::meta_word(@~"inline") => ia_hint,
+ ast::meta_list(@~"inline", items) => {
if !vec::is_empty(find_meta_items_by_name(items, ~"always")) {
ia_always
} else if !vec::is_empty(
ia_hint
}
}
- _ { ia }
+ _ => ia
}
}
}
{
let loc = lookup_char_pos(map, pos);
alt (loc.file.substr) {
- fss_none {
+ fss_none => {
{filename: /* FIXME (#2543) */ copy loc.file.name,
line: loc.line,
col: loc.col,
file: some(loc.file)}
}
- fss_internal(sp) {
+ fss_internal(sp) => {
lookup_char_pos_adj(map, sp.lo + (pos - loc.file.start_pos.ch))
}
- fss_external(eloc) {
+ fss_external(eloc) => {
{filename: /* FIXME (#2543) */ copy eloc.filename,
line: eloc.line + loc.line - 1u,
col: if loc.line == 1u {eloc.col + loc.col} else {loc.col},
pure fn lookup(pos: file_pos) -> uint { return pos.ch; }
let line = lookup_line(map, sp.lo, lookup);
alt (line.fm.substr) {
- fss_none {sp}
- fss_internal(s) {
+ fss_none => sp,
+ fss_internal(s) => {
adjust_span(map, {lo: s.lo + (sp.lo - line.fm.start_pos.ch),
hi: s.lo + (sp.hi - line.fm.start_pos.ch),
expn_info: sp.expn_info})}
- fss_external(_) {sp}
+ fss_external(_) => sp
}
}
fn get_line(fm: filemap, line: int) -> ~str unsafe {
let begin: uint = fm.lines[line].byte - fm.start_pos.byte;
let end = alt str::find_char_from(*fm.src, '\n', begin) {
- some(e) { e }
- none { str::len(*fm.src) }
+ some(e) => e,
+ none => str::len(*fm.src)
};
str::slice(*fm.src, begin, end)
}
fn abort_if_errors() {
let s;
alt self.err_count {
- 0u { return; }
- 1u { s = ~"aborting due to previous error"; }
- _ { s = fmt!{"aborting due to %u previous errors",
- self.err_count}; }
+ 0u => return,
+ 1u => s = ~"aborting due to previous error",
+ _ => {
+ s = fmt!{"aborting due to %u previous errors",
+ self.err_count};
+ }
}
self.fatal(s);
}
fn mk_handler(emitter: option<emitter>) -> handler {
let emit = alt emitter {
- some(e) { e }
- none {
+ some(e) => e,
+ none => {
let f = fn@(cmsp: option<(codemap::codemap, span)>,
msg: ~str, t: level) {
emit(cmsp, msg, t);
fn diagnosticstr(lvl: level) -> ~str {
alt lvl {
- fatal { ~"error" }
- error { ~"error" }
- warning { ~"warning" }
- note { ~"note" }
+ fatal => ~"error",
+ error => ~"error",
+ warning => ~"warning",
+ note => ~"note"
}
}
fn diagnosticcolor(lvl: level) -> u8 {
alt lvl {
- fatal { term::color_bright_red }
- error { term::color_bright_red }
- warning { term::color_bright_yellow }
- note { term::color_bright_green }
+ fatal => term::color_bright_red,
+ error => term::color_bright_red,
+ warning => term::color_bright_yellow,
+ note => term::color_bright_green
}
}
fn emit(cmsp: option<(codemap::codemap, span)>,
msg: ~str, lvl: level) {
alt cmsp {
- some((cm, sp)) {
+ some((cm, sp)) => {
let sp = codemap::adjust_span(cm,sp);
let ss = codemap::span_to_str(sp, cm);
let lines = codemap::span_to_lines(sp, cm);
highlight_lines(cm, sp, lines);
print_macro_backtrace(cm, sp);
}
- none {
+ none => {
print_diagnostic(~"", lvl, msg);
}
}
fn expect<T: copy>(diag: span_handler,
opt: option<T>, msg: fn() -> ~str) -> T {
alt opt {
- some(t) { t }
- none { diag.handler().bug(msg()); }
+ some(t) => t,
+ none => diag.handler().bug(msg())
}
}
do vec::flat_map(in_items) |in_item| {
alt in_item.node {
- ast::item_ty(ty, tps) {
+ ast::item_ty(ty, tps) => {
vec::append(~[filter_attrs(in_item)],
ty_fns(cx, in_item.ident, ty, tps))
}
- ast::item_enum(variants, tps) {
+ ast::item_enum(variants, tps) => {
vec::append(~[filter_attrs(in_item)],
enum_fns(cx, in_item.ident,
in_item.span, variants, tps))
}
- _ {
+ _ => {
cx.span_err(span, ~"#[auto_serialize] can only be \
applied to type and enum \
definitions");
fn is_vec_or_str(ty: @ast::ty) -> bool {
alt ty.node {
- ast::ty_vec(_) { true }
+ ast::ty_vec(_) => true,
// This may be wrong if the user has shadowed (!) str
ast::ty_path(@{span: _, global: _, idents: ids,
rp: none, types: _}, _)
- if ids == ~[@~"str"] { true }
- _ { false }
+ if ids == ~[@~"str"] => true,
+ _ => false
}
}
let ext_cx = cx; // required for #ast{}
alt ty.node {
- ast::ty_nil {
+ ast::ty_nil => {
~[#ast[stmt]{$(s).emit_nil()}]
}
- ast::ty_bot {
+ ast::ty_bot => {
cx.span_err(
ty.span, fmt!{"Cannot serialize bottom type"});
~[]
}
- ast::ty_box(mt) {
+ ast::ty_box(mt) => {
let l = ser_lambda(cx, tps, mt.ty, cx.clone(s), #ast{ *$(v) });
~[#ast[stmt]{$(s).emit_box($(l));}]
}
// For unique evecs/estrs, just pass through to underlying vec or str
- ast::ty_uniq(mt) if is_vec_or_str(mt.ty) {
+ ast::ty_uniq(mt) if is_vec_or_str(mt.ty) => {
ser_ty(cx, tps, mt.ty, s, v)
}
- ast::ty_uniq(mt) {
+ ast::ty_uniq(mt) => {
let l = ser_lambda(cx, tps, mt.ty, cx.clone(s), #ast{ *$(v) });
~[#ast[stmt]{$(s).emit_uniq($(l));}]
}
- ast::ty_ptr(_) | ast::ty_rptr(_, _) {
+ ast::ty_ptr(_) | ast::ty_rptr(_, _) => {
cx.span_err(ty.span, ~"cannot serialize pointer types");
~[]
}
- ast::ty_rec(flds) {
+ ast::ty_rec(flds) => {
let fld_stmts = do vec::from_fn(vec::len(flds)) |fidx| {
let fld = flds[fidx];
let vf = cx.expr(fld.span,
~[#ast[stmt]{$(s).emit_rec($(fld_lambda));}]
}
- ast::ty_fn(_, _) {
+ ast::ty_fn(_, _) => {
cx.span_err(ty.span, ~"cannot serialize function types");
~[]
}
- ast::ty_tup(tys) {
+ ast::ty_tup(tys) => {
// Generate code like
//
// alt v {
~[cx.alt_stmt(arms, ty.span, v)]
}
- ast::ty_path(path, _) {
+ ast::ty_path(path, _) => {
if vec::len(path.idents) == 1u &&
vec::is_empty(path.types) {
let ident = path.idents[0];
alt tps.find(*ident) {
- some(f) { f(v) }
- none { ser_path(cx, tps, path, s, v) }
+ some(f) => f(v),
+ none => ser_path(cx, tps, path, s, v)
}
} else {
ser_path(cx, tps, path, s, v)
}
}
- ast::ty_mac(_) {
+ ast::ty_mac(_) => {
cx.span_err(ty.span, ~"cannot serialize macro types");
~[]
}
- ast::ty_infer {
+ ast::ty_infer => {
cx.span_err(ty.span, ~"cannot serialize inferred types");
~[]
}
- ast::ty_vec(mt) {
+ ast::ty_vec(mt) => {
let ser_e =
cx.expr(
ty.span,
}]
}
- ast::ty_fixed_length(_, _) {
+ ast::ty_fixed_length(_, _) => {
cx.span_unimpl(ty.span, ~"serialization for fixed length types");
}
}
let ext_cx = cx; // required for #ast{}
alt ty.node {
- ast::ty_nil {
+ ast::ty_nil => {
#ast{ $(d).read_nil() }
}
- ast::ty_bot {
+ ast::ty_bot => {
#ast{ fail }
}
- ast::ty_box(mt) {
+ ast::ty_box(mt) => {
let l = deser_lambda(cx, tps, mt.ty, cx.clone(d));
#ast{ @$(d).read_box($(l)) }
}
// For unique evecs/estrs, just pass through to underlying vec or str
- ast::ty_uniq(mt) if is_vec_or_str(mt.ty) {
+ ast::ty_uniq(mt) if is_vec_or_str(mt.ty) => {
deser_ty(cx, tps, mt.ty, d)
}
- ast::ty_uniq(mt) {
+ ast::ty_uniq(mt) => {
let l = deser_lambda(cx, tps, mt.ty, cx.clone(d));
#ast{ ~$(d).read_uniq($(l)) }
}
- ast::ty_ptr(_) | ast::ty_rptr(_, _) {
+ ast::ty_ptr(_) | ast::ty_rptr(_, _) => {
#ast{ fail }
}
- ast::ty_rec(flds) {
+ ast::ty_rec(flds) => {
let fields = do vec::from_fn(vec::len(flds)) |fidx| {
let fld = flds[fidx];
let d = cx.clone(d);
#ast{ $(d).read_rec($(fld_lambda)) }
}
- ast::ty_fn(_, _) {
+ ast::ty_fn(_, _) => {
#ast{ fail }
}
- ast::ty_tup(tys) {
+ ast::ty_tup(tys) => {
// Generate code like
//
// d.read_tup(3u) {||
#ast{ $(d).read_tup($(sz), $(body)) }
}
- ast::ty_path(path, _) {
+ ast::ty_path(path, _) => {
if vec::len(path.idents) == 1u &&
vec::is_empty(path.types) {
let ident = path.idents[0];
alt tps.find(*ident) {
- some(f) { f() }
- none { deser_path(cx, tps, path, d) }
+ some(f) => f(),
+ none => deser_path(cx, tps, path, d)
}
} else {
deser_path(cx, tps, path, d)
}
}
- ast::ty_mac(_) {
+ ast::ty_mac(_) => {
#ast{ fail }
}
- ast::ty_infer {
+ ast::ty_infer => {
#ast{ fail }
}
- ast::ty_vec(mt) {
+ ast::ty_vec(mt) => {
let l = deser_lambda(cx, tps, mt.ty, cx.clone(d));
#ast{ std::serialization::read_to_vec($(d), $(l)) }
}
- ast::ty_fixed_length(_, _) {
+ ast::ty_fixed_length(_, _) => {
cx.span_unimpl(ty.span, ~"deserialization for fixed length types");
}
}
fn mod_path() -> ~[ast::ident] { return self.mod_path; }
fn bt_push(ei: codemap::expn_info_) {
alt ei {
- expanded_from({call_site: cs, callie: callie}) {
+ expanded_from({call_site: cs, callie: callie}) => {
self.backtrace =
some(@expanded_from({
call_site: {lo: cs.lo, hi: cs.hi,
}
fn bt_pop() {
alt self.backtrace {
- some(@expanded_from({call_site: {expn_info: prev, _}, _})) {
+ some(@expanded_from({call_site: {expn_info: prev, _}, _})) => {
self.backtrace = prev
}
- _ { self.bug(~"tried to pop without a push"); }
+ _ => self.bug(~"tried to pop without a push")
}
}
fn span_fatal(sp: span, msg: ~str) -> ! {
fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ~str {
alt expr.node {
- ast::expr_lit(l) {
- alt l.node {
- ast::lit_str(s) { return *s; }
- _ { cx.span_fatal(l.span, error); }
- }
+ ast::expr_lit(l) => alt l.node {
+ ast::lit_str(s) => return *s,
+ _ => cx.span_fatal(l.span, error)
}
- _ { cx.span_fatal(expr.span, error); }
+ _ => cx.span_fatal(expr.span, error)
}
}
fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ast::ident {
alt expr.node {
- ast::expr_path(p) {
+ ast::expr_path(p) => {
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u {
cx.span_fatal(expr.span, error);
} else { return p.idents[0]; }
}
- _ { cx.span_fatal(expr.span, error); }
+ _ => cx.span_fatal(expr.span, error)
}
}
fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
min: uint, max: option<uint>, name: ~str) -> ~[@ast::expr] {
alt arg {
- some(expr) {
- alt expr.node {
- ast::expr_vec(elts, _) {
+ some(expr) => alt expr.node {
+ ast::expr_vec(elts, _) => {
let elts_len = vec::len(elts);
- alt max {
- some(max) if ! (min <= elts_len && elts_len <= max) {
- cx.span_fatal(sp,
- fmt!{"#%s takes between %u and %u arguments.",
- name, min, max});
- }
- none if ! (min <= elts_len) {
- cx.span_fatal(sp, fmt!{"#%s needs at least %u arguments.",
- name, min});
+ alt max {
+ some(max) if ! (min <= elts_len && elts_len <= max) => {
+ cx.span_fatal(sp,
+ fmt!{"#%s takes between %u and %u arguments.",
+ name, min, max});
+ }
+ none if ! (min <= elts_len) => {
+ cx.span_fatal(sp, fmt!{"#%s needs at least %u arguments.",
+ name, min});
+ }
+ _ => return elts /* we're good */
}
- _ { return elts; /* we're good */}
- }
}
- _ {
+ _ => {
cx.span_fatal(sp, fmt!{"#%s: malformed invocation", name})
}
- }
}
- none {cx.span_fatal(sp, fmt!{"#%s: missing arguments", name})}
+ none => cx.span_fatal(sp, fmt!{"#%s: missing arguments", name})
}
}
-> ast::mac_body_
{
alt (args) {
- some(body) {body}
- none {cx.span_fatal(sp, ~"missing macro body")}
+ some(body) => body,
+ none => cx.span_fatal(sp, ~"missing macro body")
}
}
let args =
alt parse_or_else(cx.parse_sess(), cx.cfg(), arg_reader as reader,
argument_gram).get(@~"arg") {
- @matched_seq(s, _) {
- do s.map() |lf| {
- alt lf {
- @matched_nonterminal(parse::token::nt_expr(arg)) {
- arg /* whew! list of exprs, here we come! */
- }
- _ { fail ~"badly-structured parse result"; }
- }
+ @matched_seq(s, _) => do s.map() |lf| {
+ alt lf {
+ @matched_nonterminal(parse::token::nt_expr(arg)) => {
+ arg /* whew! list of exprs, here we come! */
+ }
+ _ => fail ~"badly-structured parse result"
}
}
- _ { fail ~"badly-structured parse result"; }
+ _ => fail ~"badly-structured parse result"
};
return some(@{id: parse::next_node_id(cx.parse_sess()),
let var = expr_to_str(cx, args[0], ~"#env requires a string");
alt os::getenv(var) {
- option::none { return mk_uniq_str(cx, sp, ~""); }
- option::some(s) { return mk_uniq_str(cx, sp, s); }
+ option::none => return mk_uniq_str(cx, sp, ~""),
+ option::some(s) => return mk_uniq_str(cx, sp, s)
}
}
return alt e {
// expr_mac should really be expr_ext or something; it's the
// entry-point for all syntax extensions.
- expr_mac(mac) {
+ expr_mac(mac) => {
// Old-style macros, for compatibility, will erase this whole
// block once we've transitioned.
alt mac.node {
- mac_invoc(pth, args, body) {
+ mac_invoc(pth, args, body) => {
assert (vec::len(pth.idents) > 0u);
let extname = pth.idents[0];
alt exts.find(*extname) {
- none {
+ none => {
cx.span_fatal(pth.span,
fmt!{"macro undefined: '%s'", *extname})
}
- some(item_decorator(_)) {
+ some(item_decorator(_)) => {
cx.span_fatal(
pth.span,
fmt!{"%s can only be used as a decorator", *extname});
}
- some(normal({expander: exp, span: exp_sp})) {
+ some(normal({expander: exp, span: exp_sp})) => {
let expanded = exp(cx, mac.span, args, body);
cx.bt_push(expanded_from({call_site: s,
(fully_expanded, s)
}
- some(macro_defining(ext)) {
+ some(macro_defining(ext)) => {
let named_extension = ext(cx, mac.span, args, body);
exts.insert(*named_extension.ident, named_extension.ext);
(ast::expr_rec(~[], none), s)
}
- some(expr_tt(_)) {
+ some(expr_tt(_)) => {
cx.span_fatal(pth.span,
fmt!{"this tt-style macro should be \
invoked '%s!{...}'", *extname})
}
- some(item_tt(*)) {
+ some(item_tt(*)) => {
cx.span_fatal(pth.span,
~"cannot use item macros in this context");
}
// Token-tree macros, these will be the only case when we're
// finished transitioning.
- mac_invoc_tt(pth, tts) {
+ mac_invoc_tt(pth, tts) => {
assert (vec::len(pth.idents) == 1u);
let extname = pth.idents[0];
alt exts.find(*extname) {
- none {
+ none => {
cx.span_fatal(pth.span,
fmt!{"macro undefined: '%s'", *extname})
}
- some(expr_tt({expander: exp, span: exp_sp})) {
+ some(expr_tt({expander: exp, span: exp_sp})) => {
let expanded = alt exp(cx, mac.span, tts) {
- mr_expr(e) { e }
- _ { cx.span_fatal(
+ mr_expr(e) => e,
+ _ => cx.span_fatal(
pth.span, fmt!{"non-expr macro in expr pos: %s",
- *extname}) }
+ *extname})
};
cx.bt_push(expanded_from({call_site: s,
(fully_expanded, s)
}
- some(normal({expander: exp, span: exp_sp})) {
+ some(normal({expander: exp, span: exp_sp})) => {
//convert the new-style invoc for the old-style macro
let arg = base::tt_args_to_original_flavor(cx, pth.span,
tts);
(fully_expanded, s)
}
- _ {
+ _ => {
cx.span_fatal(pth.span,
fmt!{"'%s' is not a tt-style macro",
*extname})
}
}
- _ { cx.span_bug(mac.span, ~"naked syntactic bit") }
+ _ => cx.span_bug(mac.span, ~"naked syntactic bit")
}
}
- _ { orig(e, s, fld) }
+ _ => orig(e, s, fld)
};
}
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 }
- ast::meta_name_value(n, _) { n }
- ast::meta_list(n, _) { n }
+ ast::meta_word(n) => n,
+ ast::meta_name_value(n, _) => n,
+ ast::meta_list(n, _) => n
};
alt exts.find(*mname) {
none | some(normal(_)) | some(macro_defining(_))
- | some(expr_tt(_)) | some(item_tt(*)) {
- items
- }
-
- some(item_decorator(dec_fn)) {
+ | some(expr_tt(_)) | some(item_tt(*)) => items,
+ some(item_decorator(dec_fn)) => {
dec_fn(cx, attr.span, attr.node.value, items)
}
}
-> option<@ast::item>
{
let is_mod = alt it.node {
- ast::item_mod(_) | ast::item_foreign_mod(_) {true}
- _ {false}
+ ast::item_mod(_) | ast::item_foreign_mod(_) => true,
+ _ => false
};
let maybe_it = alt it.node {
- ast::item_mac(*) {
- expand_item_mac(exts, cx, it, fld)
- }
- _ { some(it) }
+ ast::item_mac(*) => expand_item_mac(exts, cx, it, fld),
+ _ => some(it)
};
alt maybe_it {
- some(it) {
+ some(it) => {
if is_mod { cx.mod_push(it.ident); }
let ret_val = orig(it, fld);
if is_mod { cx.mod_pop(); }
return ret_val;
}
- none { return none; }
+ none => return none
}
}
cx: ext_ctxt, &&it: @ast::item,
fld: ast_fold) -> option<@ast::item> {
alt it.node {
- item_mac({node: mac_invoc_tt(pth, tts), span}) {
+ item_mac({node: mac_invoc_tt(pth, tts), span}) => {
let extname = pth.idents[0];
alt exts.find(*extname) {
- none {
+ none => {
cx.span_fatal(pth.span,
fmt!{"macro undefined: '%s'", *extname})
}
- some(item_tt(expand)) {
+ some(item_tt(expand)) => {
let expanded = expand.expander(cx, it.span, it.ident, tts);
cx.bt_push(expanded_from({call_site: it.span,
callie: {name: *extname,
span: expand.span}}));
let maybe_it = alt expanded {
- mr_item(it) { fld.fold_item(it) }
- mr_expr(e) { cx.span_fatal(pth.span,
+ mr_item(it) => fld.fold_item(it),
+ mr_expr(e) => cx.span_fatal(pth.span,
~"expr macro in item position: " +
- *extname) }
- mr_def(mdef) {
+ *extname),
+ mr_def(mdef) => {
exts.insert(*mdef.ident, mdef.ext);
none
}
cx.bt_pop();
return maybe_it
}
- _ { cx.span_fatal(it.span,
- fmt!{"%s is not a legal here", *extname}) }
+ _ => cx.span_fatal(it.span,
+ fmt!{"%s is not a legal here", *extname})
}
}
- _ {
- cx.span_bug(it.span, ~"invalid item macro invocation");
- }
+ _ => cx.span_bug(it.span, ~"invalid item macro invocation")
}
}
let mut tmp_expr = make_rt_path_expr(cx, sp, @~"flag_none");
for flags.each |f| {
let fstr = alt f {
- flag_left_justify { ~"flag_left_justify" }
- flag_left_zero_pad { ~"flag_left_zero_pad" }
- flag_space_for_sign { ~"flag_space_for_sign" }
- flag_sign_always { ~"flag_sign_always" }
- flag_alternate { ~"flag_alternate" }
+ flag_left_justify => ~"flag_left_justify",
+ flag_left_zero_pad => ~"flag_left_zero_pad",
+ flag_space_for_sign => ~"flag_space_for_sign",
+ flag_sign_always => ~"flag_sign_always",
+ flag_alternate => ~"flag_alternate"
};
tmp_expr = mk_binary(cx, sp, ast::bitor, tmp_expr,
make_rt_path_expr(cx, sp, @fstr));
}
fn make_count(cx: ext_ctxt, sp: span, cnt: count) -> @ast::expr {
alt cnt {
- count_implied {
+ count_implied => {
return make_rt_path_expr(cx, sp, @~"count_implied");
}
- count_is(c) {
+ count_is(c) => {
let count_lit = mk_int(cx, sp, c);
let count_is_path = make_path_vec(cx, @~"count_is");
let count_is_args = ~[count_lit];
return mk_call(cx, sp, count_is_path, count_is_args);
}
- _ { cx.span_unimpl(sp, ~"unimplemented #fmt conversion"); }
+ _ => cx.span_unimpl(sp, ~"unimplemented #fmt conversion")
}
}
fn make_ty(cx: ext_ctxt, sp: span, t: ty) -> @ast::expr {
let mut rt_type;
alt t {
- ty_hex(c) {
- alt c {
- case_upper { rt_type = ~"ty_hex_upper"; }
- case_lower { rt_type = ~"ty_hex_lower"; }
- }
+ ty_hex(c) => alt c {
+ case_upper => rt_type = ~"ty_hex_upper",
+ case_lower => rt_type = ~"ty_hex_lower"
}
- ty_bits { rt_type = ~"ty_bits"; }
- ty_octal { rt_type = ~"ty_octal"; }
- _ { rt_type = ~"ty_default"; }
+ ty_bits => rt_type = ~"ty_bits",
+ ty_octal => rt_type = ~"ty_octal",
+ _ => rt_type = ~"ty_default"
}
return make_rt_path_expr(cx, sp, @rt_type);
}
fn is_signed_type(cnv: conv) -> bool {
alt cnv.ty {
- ty_int(s) {
- alt s { signed { return true; } unsigned { return false; } }
+ ty_int(s) => alt s {
+ signed => return true,
+ unsigned => return false
}
- ty_float { return true; }
- _ { return false; }
+ ty_float => return true,
+ _ => return false
}
}
let unsupported = ~"conversion not supported in #fmt string";
alt cnv.param {
- option::none { }
- _ { cx.span_unimpl(sp, unsupported); }
+ option::none => (),
+ _ => cx.span_unimpl(sp, unsupported)
}
for cnv.flags.each |f| {
alt f {
- flag_left_justify { }
- flag_sign_always {
+ flag_left_justify => (),
+ flag_sign_always => {
if !is_signed_type(cnv) {
cx.span_fatal(sp,
~"+ flag only valid in " +
~"signed #fmt conversion");
}
}
- flag_space_for_sign {
+ flag_space_for_sign => {
if !is_signed_type(cnv) {
cx.span_fatal(sp,
~"space flag only valid in " +
~"signed #fmt conversions");
}
}
- flag_left_zero_pad { }
- _ { cx.span_unimpl(sp, unsupported); }
+ flag_left_zero_pad => (),
+ _ => cx.span_unimpl(sp, unsupported)
}
}
alt cnv.width {
- count_implied { }
- count_is(_) { }
- _ { cx.span_unimpl(sp, unsupported); }
+ count_implied => (),
+ count_is(_) => (),
+ _ => cx.span_unimpl(sp, unsupported)
}
alt cnv.precision {
- count_implied { }
- count_is(_) { }
- _ { cx.span_unimpl(sp, unsupported); }
+ count_implied => (),
+ count_is(_) => (),
+ _ => cx.span_unimpl(sp, unsupported)
}
alt cnv.ty {
- ty_str { return make_conv_call(cx, arg.span, ~"str", cnv, arg); }
- ty_int(sign) {
- alt sign {
- signed {
- return make_conv_call(cx, arg.span, ~"int", cnv, arg);
- }
- unsigned {
- return make_conv_call(cx, arg.span, ~"uint", cnv, arg);
- }
+ ty_str => return make_conv_call(cx, arg.span, ~"str", cnv, arg),
+ ty_int(sign) => alt sign {
+ signed => return make_conv_call(cx, arg.span, ~"int", cnv, arg),
+ unsigned => {
+ return make_conv_call(cx, arg.span, ~"uint", cnv, arg)
}
}
- ty_bool { return make_conv_call(cx, arg.span, ~"bool", cnv, arg); }
- ty_char { return make_conv_call(cx, arg.span, ~"char", cnv, arg); }
- ty_hex(_) {
+ ty_bool => return make_conv_call(cx, arg.span, ~"bool", cnv, arg),
+ ty_char => return make_conv_call(cx, arg.span, ~"char", cnv, arg),
+ ty_hex(_) => {
return make_conv_call(cx, arg.span, ~"uint", cnv, arg);
}
- ty_bits { return make_conv_call(cx, arg.span, ~"uint", cnv, arg); }
- ty_octal { return make_conv_call(cx, arg.span, ~"uint", cnv, arg); }
- ty_float {
+ ty_bits => return make_conv_call(cx, arg.span, ~"uint", cnv, arg),
+ ty_octal => return make_conv_call(cx, arg.span, ~"uint", cnv, arg),
+ ty_float => {
return make_conv_call(cx, arg.span, ~"float", cnv, arg);
}
- ty_poly { return make_conv_call(cx, arg.span, ~"poly", cnv, arg); }
+ ty_poly => return make_conv_call(cx, arg.span, ~"poly", cnv, arg)
}
}
fn log_conv(c: conv) {
alt c.param {
- some(p) { log(debug, ~"param: " + int::to_str(p, 10u)); }
- _ { debug!{"param: none"}; }
+ some(p) => { log(debug, ~"param: " + int::to_str(p, 10u)); }
+ _ => debug!{"param: none"}
}
for c.flags.each |f| {
alt f {
- flag_left_justify { debug!{"flag: left justify"}; }
- flag_left_zero_pad { debug!{"flag: left zero pad"}; }
- flag_space_for_sign { debug!{"flag: left space pad"}; }
- flag_sign_always { debug!{"flag: sign always"}; }
- flag_alternate { debug!{"flag: alternate"}; }
+ flag_left_justify => debug!{"flag: left justify"},
+ flag_left_zero_pad => debug!{"flag: left zero pad"},
+ flag_space_for_sign => debug!{"flag: left space pad"},
+ flag_sign_always => debug!{"flag: sign always"},
+ flag_alternate => debug!{"flag: alternate"}
}
}
alt c.width {
- count_is(i) { log(debug,
- ~"width: count is " + int::to_str(i, 10u)); }
- count_is_param(i) {
- log(debug,
- ~"width: count is param " + int::to_str(i, 10u));
- }
- count_is_next_param { debug!{"width: count is next param"}; }
- count_implied { debug!{"width: count is implied"}; }
+ count_is(i) => log(
+ debug, ~"width: count is " + int::to_str(i, 10u)),
+ count_is_param(i) => log(
+ debug, ~"width: count is param " + int::to_str(i, 10u)),
+ count_is_next_param => debug!{"width: count is next param"},
+ count_implied => debug!{"width: count is implied"}
}
alt c.precision {
- count_is(i) { log(debug,
- ~"prec: count is " + int::to_str(i, 10u)); }
- count_is_param(i) {
- log(debug,
- ~"prec: count is param " + int::to_str(i, 10u));
- }
- count_is_next_param { debug!{"prec: count is next param"}; }
- count_implied { debug!{"prec: count is implied"}; }
+ count_is(i) => log(
+ debug, ~"prec: count is " + int::to_str(i, 10u)),
+ count_is_param(i) => log(
+ debug, ~"prec: count is param " + int::to_str(i, 10u)),
+ count_is_next_param => debug!{"prec: count is next param"},
+ count_implied => debug!{"prec: count is implied"}
}
alt c.ty {
- ty_bool { debug!{"type: bool"}; }
- ty_str { debug!{"type: str"}; }
- ty_char { debug!{"type: char"}; }
- ty_int(s) {
- alt s {
- signed { debug!{"type: signed"}; }
- unsigned { debug!{"type: unsigned"}; }
- }
+ ty_bool => debug!{"type: bool"},
+ ty_str => debug!{"type: str"},
+ ty_char => debug!{"type: char"},
+ ty_int(s) => alt s {
+ signed => debug!{"type: signed"},
+ unsigned => debug!{"type: unsigned"}
}
- ty_bits { debug!{"type: bits"}; }
- ty_hex(cs) {
- alt cs {
- case_upper { debug!{"type: uhex"}; }
- case_lower { debug!{"type: lhex"}; }
- }
+ ty_bits => debug!{"type: bits"},
+ ty_hex(cs) => alt cs {
+ case_upper => debug!{"type: uhex"},
+ case_lower => debug!{"type: lhex"},
}
- ty_octal { debug!{"type: octal"}; }
- ty_float { debug!{"type: float"}; }
- ty_poly { debug!{"type: poly"}; }
+ ty_octal => debug!{"type: octal"},
+ ty_float => debug!{"type: float"},
+ ty_poly => debug!{"type: poly"}
}
}
let fmt_sp = args[0].span;
let nargs = args.len();
for pieces.each |pc| {
alt pc {
- piece_string(s) {
- vec::push(piece_exprs, mk_uniq_str(cx, fmt_sp, s));
+ piece_string(s) => {
+ vec::push(piece_exprs, mk_uniq_str(cx, fmt_sp, s))
}
- piece_conv(conv) {
+ piece_conv(conv) => {
n += 1u;
if n >= nargs {
cx.span_fatal(sp,
fn visit_message(name: ident, _span: span, _tys: &[@ast::ty],
this: state, next: next_state) {
alt next {
- some({state: next, tys: next_tys}) {
+ some({state: next, tys: next_tys}) => {
let proto = this.proto;
if !proto.has_state(next) {
// This should be a span fatal, but then we need to
}
}
}
- none { }
+ none => ()
}
}
}
\ No newline at end of file
let id = self.parse_ident();
self.expect(token::COLON);
let dir = alt copy self.token {
- token::IDENT(n, _) {
- self.get_str(n)
- }
- _ { fail }
+ token::IDENT(n, _) => self.get_str(n),
+ _ => fail
};
self.bump();
let dir = alt dir {
- @~"send" { send }
- @~"recv" { recv }
- _ { fail }
+ @~"send" => send,
+ @~"recv" => recv,
+ _ => fail
};
let typarms = if self.token == token::LT {
self.expect(token::RARROW);
let next = alt copy self.token {
- token::IDENT(_, _) {
+ token::IDENT(_, _) => {
let name = self.parse_ident();
let ntys = if self.token == token::LT {
self.parse_unspanned_seq(token::LT,
else { ~[] };
some({state: name, tys: ntys})
}
- token::NOT {
+ token::NOT => {
// -> !
self.bump();
none
}
- _ { self.fatal(~"invalid next state") }
+ _ => self.fatal(~"invalid next state")
};
state.add_message(mname, copy self.span, args, next);
fn gen_send(cx: ext_ctxt) -> @ast::item {
debug!{"pipec: gen_send"};
alt self {
- message(id, span, tys, this, some({state: next, tys: next_tys})) {
+ message(id, span, tys, this,
+ some({state: next, tys: next_tys})) => {
debug!{"pipec: next state exists"};
let next = this.proto.get_state(next);
assert next_tys.len() == next.ty_params.len();
if this.proto.is_bounded() {
let (sp, rp) = alt (this.dir, next.dir) {
- (send, send) { (~"c", ~"s") }
- (send, recv) { (~"s", ~"c") }
- (recv, send) { (~"s", ~"c") }
- (recv, recv) { (~"c", ~"s") }
+ (send, send) => (~"c", ~"s"),
+ (send, recv) => (~"s", ~"c"),
+ (recv, send) => (~"s", ~"c"),
+ (recv, recv) => (~"c", ~"s")
};
body += ~"let b = pipe.reuse_buffer();\n";
}
else {
let pat = alt (this.dir, next.dir) {
- (send, send) { ~"(c, s)" }
- (send, recv) { ~"(s, c)" }
- (recv, send) { ~"(s, c)" }
- (recv, recv) { ~"(c, s)" }
+ (send, send) => ~"(c, s)",
+ (send, recv) => ~"(s, c)",
+ (recv, send) => ~"(s, c)",
+ (recv, recv) => ~"(c, s)"
};
body += fmt!{"let %s = pipes::entangle();\n", pat};
cx.expr_block(body))
}
- message(id, span, tys, this, none) {
+ message(id, span, tys, this, none) => {
debug!{"pipec: no next state"};
let arg_names = tys.mapi(|i, _ty| @(~"x_" + i.to_str()));
let message(name, _span, tys, this, next) = m;
let tys = alt next {
- some({state: next, tys: next_tys}) {
+ some({state: next, tys: next_tys}) => {
let next = this.proto.get_state(next);
let next_name = next.data_name();
let dir = alt this.dir {
- send { @~"server" }
- recv { @~"client" }
+ send => @~"server",
+ recv => @~"client"
};
vec::append_one(tys,
cx.ty_path_ast_builder((dir + next_name)
.add_tys(next_tys)))
}
- none { tys }
+ none => tys
};
let v = cx.variant(name, tys);
fn to_endpoint_decls(cx: ext_ctxt, dir: direction) -> ~[@ast::item] {
debug!{"pipec: to_endpoint_decls"};
let dir = alt dir {
- send { (*self).dir }
- recv { (*self).dir.reverse() }
+ send => (*self).dir,
+ recv => (*self).dir.reverse()
};
let mut items = ~[];
for self.messages.each |m| {
let body = if !self.is_bounded() {
alt start_state.dir {
- send { #ast { pipes::entangle() } }
- recv {
+ send => #ast { pipes::entangle() },
+ recv => {
#ast {{
let (s, c) = pipes::entangle();
(c, s)
else {
let body = self.gen_init_bounded(ext_cx);
alt start_state.dir {
- send { body }
- recv {
+ send => body,
+ recv => {
#ast {{
let (s, c) = $(body);
(c, s)
for (copy self.states).each |s| {
for s.ty_params.each |tp| {
alt params.find(|tpp| *tp.ident == *tpp.ident) {
- none { vec::push(params, tp) }
- _ { }
+ none => vec::push(params, tp),
+ _ => ()
}
}
}
let fields = do (copy self.states).map_to_vec |s| {
for s.ty_params.each |tp| {
alt params.find(|tpp| *tp.ident == *tpp.ident) {
- none { vec::push(params, tp) }
- _ { }
+ none => vec::push(params, tp),
+ _ => ()
}
}
let ty = s.to_ty(cx);
~[],
self.parse_sess());
alt res {
- some(ast) { ast }
- none {
+ some(ast) => ast,
+ none => {
error!{"Parse error with ```\n%s\n```", s};
fail
}
impl of to_str for direction {
fn to_str() -> ~str {
alt self {
- send { ~"send" }
- recv { ~"recv" }
+ send => ~"send",
+ recv => ~"recv"
}
}
}
impl methods for direction {
fn reverse() -> direction {
alt self {
- send { recv }
- recv { send }
+ send => recv,
+ recv => send
}
}
}
impl methods for message {
fn name() -> ident {
alt self {
- message(id, _, _, _, _) {
- id
- }
+ message(id, _, _, _, _) => id
}
}
fn span() -> span {
alt self {
- message(_, span, _, _, _) {
- span
- }
+ message(_, span, _, _, _) => span
}
}
/// Return the type parameters actually used by this message
fn get_params() -> ~[ast::ty_param] {
alt self {
- message(_, _, _, this, _) {
- this.ty_params
- }
+ message(_, _, _, this, _) => this.ty_params
}
}
}
fn reachable(f: fn(state) -> bool) {
for self.messages.each |m| {
alt m {
- message(_, _, _, _, some({state: id, _})) {
+ message(_, _, _, _, some({state: id, _})) => {
let state = self.proto.get_state(id);
if !f(state) { break }
}
- _ { }
+ _ => ()
}
}
}
fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_expr(self, cx, v);}
fn extract_mac() -> option<ast::mac_> {
alt (self.node) {
- ast::expr_mac({node: mac, _}) {some(mac)}
- _ {none}
+ ast::expr_mac({node: mac, _}) => some(mac),
+ _ => none
}
}
fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr {
fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_ty(self, cx, v);}
fn extract_mac() -> option<ast::mac_> {
alt (self.node) {
- ast::ty_mac({node: mac, _}) {some(mac)}
- _ {none}
+ ast::ty_mac({node: mac, _}) => some(mac),
+ _ => none
}
}
fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr {
fn visit_aq<T:qq_helper>(node: T, constr: ~str, &&cx: aq_ctxt, v: vt<aq_ctxt>)
{
alt (node.extract_mac()) {
- some(mac_aq(sp, e)) {
+ some(mac_aq(sp, e)) => {
cx.gather.push(gather_item {
lo: sp.lo - cx.lo,
hi: sp.hi - cx.lo,
e: e,
constr: constr});
}
- _ {node.visit(cx, v);}
+ _ => node.visit(cx, v)
}
}
do option::iter(arg) |arg| {
let args: ~[@ast::expr] =
alt arg.node {
- ast::expr_vec(elts, _) { elts }
- _ {
+ ast::expr_vec(elts, _) => elts,
+ _ => {
ecx.span_fatal
(_sp, ~"#ast requires arguments of the form `~[...]`.")
}
}
alt (args[0].node) {
ast::expr_path(@{idents: id, _}) if vec::len(id) == 1u
- {what = *id[0]}
- _ {ecx.span_fatal(args[0].span, ~"expected an identifier");}
+ => what = *id[0],
+ _ => ecx.span_fatal(args[0].span, ~"expected an identifier")
}
}
let body = get_mac_body(ecx,_sp,body);
return alt what {
- ~"crate" {finish(ecx, body, parse_crate)}
- ~"expr" {finish(ecx, body, parse_expr)}
- ~"ty" {finish(ecx, body, parse_ty)}
- ~"item" {finish(ecx, body, parse_item)}
- ~"stmt" {finish(ecx, body, parse_stmt)}
- ~"pat" {finish(ecx, body, parse_pat)}
- _ {ecx.span_fatal(_sp, ~"unsupported ast type")}
+ ~"crate" => finish(ecx, body, parse_crate),
+ ~"expr" => finish(ecx, body, parse_expr),
+ ~"ty" => finish(ecx, body, parse_ty),
+ ~"item" => finish(ecx, body, parse_item),
+ ~"stmt" => finish(ecx, body, parse_stmt),
+ ~"pat" => finish(ecx, body, parse_pat),
+ _ => ecx.span_fatal(_sp, ~"unsupported ast type")
};
}
fn parse_item(p: parser) -> @ast::item {
alt p.parse_item(~[]) {
- some(item) { item }
- none { fail ~"parse_item: parsing an item failed"; }
+ some(item) => item,
+ none => fail ~"parse_item: parsing an item failed"
}
}
str2 += repl;
}
alt copy state {
- active {str::push_char(str2, ch);}
- skip(1u) {state = blank;}
- skip(sk) {state = skip (sk-1u);}
- blank if is_space(ch) {str::push_char(str2, ch);}
- blank {str::push_char(str2, ' ');}
+ active => str::push_char(str2, ch),
+ skip(1u) => state = blank,
+ skip(sk) => state = skip (sk-1u),
+ blank if is_space(ch) => str::push_char(str2, ch),
+ blank => str::push_char(str2, ' ')
}
i += 1u;
if (j < g_len && i == cx.gather[j].hi) {
-> (ast::expr_, span)
{
alt e {
- ast::expr_mac({node: mac_var(i), _}) {
- alt (repls[i]) {
- from_expr(r) {(r.node, r.span)}
- _ {fail /* fixme error message */}}}
- _ {orig(e,s,fld)}
+ ast::expr_mac({node: mac_var(i), _}) => alt (repls[i]) {
+ from_expr(r) => (r.node, r.span),
+ _ => fail /* fixme error message */
+ }
+ _ => orig(e,s,fld)
}
}
-> (ast::ty_, span)
{
alt e {
- ast::ty_mac({node: mac_var(i), _}) {
- alt (repls[i]) {
- from_ty(r) {(r.node, r.span)}
- _ {fail /* fixme error message */}}}
- _ {orig(e,s,fld)}
+ ast::ty_mac({node: mac_var(i), _}) => alt (repls[i]) {
+ from_ty(r) => (r.node, r.span),
+ _ => fail /* fixme error message */
+ }
+ _ => orig(e,s,fld)
}
}
/* for when given an incompatible bit of AST */
fn match_error(cx: ext_ctxt, m: matchable, expected: ~str) -> ! {
alt m {
- match_expr(x) {
- cx.span_fatal(x.span,
- ~"this argument is an expr, expected " + expected);
- }
- match_path(x) {
- cx.span_fatal(x.span,
- ~"this argument is a path, expected " + expected);
- }
- match_ident(x) {
- cx.span_fatal(x.span,
- ~"this argument is an ident, expected " + expected);
- }
- match_ty(x) {
- cx.span_fatal(x.span,
- ~"this argument is a type, expected " + expected);
- }
- match_block(x) {
- cx.span_fatal(x.span,
- ~"this argument is a block, expected " + expected);
- }
- match_exact { cx.bug(~"what is a match_exact doing in a bindings?"); }
+ match_expr(x) => cx.span_fatal(
+ x.span, ~"this argument is an expr, expected " + expected),
+ match_path(x) => cx.span_fatal(
+ x.span, ~"this argument is a path, expected " + expected),
+ match_ident(x) => cx.span_fatal(
+ x.span, ~"this argument is an ident, expected " + expected),
+ match_ty(x) => cx.span_fatal(
+ x.span, ~"this argument is a type, expected " + expected),
+ match_block(x) => cx.span_fatal(
+ x.span, ~"this argument is a block, expected " + expected),
+ match_exact => cx.bug(~"what is a match_exact doing in a bindings?")
}
}
let mut res = none;
for elts.each |elt| {
alt elt.node {
- expr_mac(m) {
- alt m.node {
- ast::mac_ellipsis {
+ expr_mac(m) => alt m.node {
+ ast::mac_ellipsis => {
if res != none {
cx.span_fatal(m.span, ~"only one ellipsis allowed");
}
some({pre: vec::slice(elts, 0u, idx - 1u),
rep: some(elts[idx - 1u]),
post: vec::slice(elts, idx + 1u, vec::len(elts))});
- }
- _ { }
}
+ _ => ()
}
- _ { }
+ _ => ()
}
idx += 1u;
}
return alt res {
- some(val) { val }
- none { {pre: elts, rep: none, post: ~[]} }
- }
+ some(val) => val,
+ none => {pre: elts, rep: none, post: ~[]}
+ }
}
fn option_flatten_map<T: copy, U: copy>(f: fn@(T) -> option<U>, v: ~[T]) ->
option<~[U]> {
let mut res = ~[];
for v.each |elem| {
- alt f(elem) { none { return none; } some(fv) { vec::push(res, fv); } }
+ alt f(elem) {
+ none => return none,
+ some(fv) => vec::push(res, fv)
+ }
}
return some(res);
}
fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result {
alt ad {
- leaf(x) { return f(x); }
- seq(ads, span) {
- alt option_flatten_map(|x| a_d_map(x, f), *ads) {
- none { return none; }
- some(ts) { return some(seq(@ts, span)); }
- }
+ leaf(x) => return f(x),
+ seq(ads, span) => alt option_flatten_map(|x| a_d_map(x, f), *ads) {
+ none => return none,
+ some(ts) => return some(seq(@ts, span))
}
}
}
fn compose_sels(s1: selector, s2: selector) -> selector {
fn scomp(s1: selector, s2: selector, m: matchable) -> match_result {
return alt s1(m) {
- none { none }
- some(matches) { a_d_map(matches, s2) }
+ none => none,
+ some(matches) => a_d_map(matches, s2)
}
}
return { |x| scomp(s1, s2, x) };
let res = box_str_hash::<arb_depth<matchable>>();
//need to do this first, to check vec lengths.
for b.literal_ast_matchers.each |sel| {
- alt sel(match_expr(e)) { none { return none; } _ { } }
+ alt sel(match_expr(e)) { none => return none, _ => () }
}
let mut never_mind: bool = false;
for b.real_binders.each |key, val| {
alt val(match_expr(e)) {
- none { never_mind = true; }
- some(mtc) { res.insert(key, mtc); }
+ none => never_mind = true,
+ some(mtc) => { res.insert(key, mtc); }
}
};
//HACK: `ret` doesn't work in `for each`
let mut res: arb_depth<matchable> = m;
for vec::each(*idx_path) |idx| {
res = alt res {
- leaf(_) { return res;/* end of the line */ }
- seq(new_ms, _) { new_ms[idx] }
+ leaf(_) => return res,/* end of the line */
+ seq(new_ms, _) => new_ms[idx]
}
}
return res;
fn follow_for_trans(cx: ext_ctxt, mmaybe: option<arb_depth<matchable>>,
idx_path: @mut ~[uint]) -> option<matchable> {
alt mmaybe {
- none { return none }
- some(m) {
+ none => return none,
+ some(m) => {
return alt follow(m, idx_path) {
- seq(_, sp) {
+ seq(_, sp) => {
cx.span_fatal(sp,
~"syntax matched under ... but not " +
~"used that way.")
}
- leaf(m) { return some(m) }
+ leaf(m) => return some(m)
}
}
}
recur: fn@(&&@expr) -> @expr,
exprs: ~[@expr]) -> ~[@expr] {
alt elts_to_ell(cx, exprs) {
- {pre: pre, rep: repeat_me_maybe, post: post} {
+ {pre: pre, rep: repeat_me_maybe, post: post} => {
let mut res = vec::map(pre, recur);
alt repeat_me_maybe {
- none { }
- some(repeat_me) {
+ none => (),
+ some(repeat_me) => {
let mut repeat: option<{rep_count: uint, name: ident}> = none;
/* we need to walk over all the free vars in lockstep, except for
the leaves, which are just duplicated */
do free_vars(b, repeat_me) |fv| {
let cur_pos = follow(b.get(fv), idx_path);
alt cur_pos {
- leaf(_) { }
- seq(ms, _) {
+ leaf(_) => (),
+ seq(ms, _) => {
alt repeat {
- none {
+ none => {
repeat = some({rep_count: vec::len(*ms), name: fv});
}
- some({rep_count: old_len, name: old_name}) {
+ some({rep_count: old_len, name: old_name}) => {
let len = vec::len(*ms);
if old_len != len {
let msg =
}
};
alt repeat {
- none {
+ none => {
cx.span_fatal(repeat_me.span,
~"'...' surrounds an expression without any" +
~" repeating syntax variables");
}
- some({rep_count: rc, _}) {
+ some({rep_count: rc, _}) => {
/* Whew, we now know how how many times to repeat */
let mut idx: uint = 0u;
while idx < rc {
fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
&&i: ident, _fld: ast_fold) -> ident {
return alt follow_for_trans(cx, b.find(i), idx_path) {
- some(match_ident(a_id)) { a_id.node }
- some(m) { match_error(cx, m, ~"an identifier") }
- none { i }
+ some(match_ident(a_id)) => a_id.node,
+ some(m) => match_error(cx, m, ~"an identifier"),
+ none => i
}
}
// Don't substitute into qualified names.
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { return p; }
alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) {
- some(match_ident(id)) {
+ some(match_ident(id)) => {
{span: id.span, global: false, idents: ~[id.node],
rp: none, types: ~[]}
}
- some(match_path(a_pth)) { *a_pth }
- some(m) { match_error(cx, m, ~"a path") }
- none { p }
+ some(match_path(a_pth)) => *a_pth,
+ some(m) => match_error(cx, m, ~"a path"),
+ none => p
}
}
-> (ast::expr_, span)
{
return alt e {
- expr_path(p) {
+ expr_path(p) => {
// Don't substitute into qualified names.
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u {
(e, s);
}
alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) {
- some(match_ident(id)) {
+ some(match_ident(id)) => {
(expr_path(@{span: id.span,
global: false,
idents: ~[id.node],
rp: none,
types: ~[]}), id.span)
}
- some(match_path(a_pth)) { (expr_path(a_pth), s) }
- some(match_expr(a_exp)) { (a_exp.node, a_exp.span) }
- some(m) { match_error(cx, m, ~"an expression") }
- none { orig(e, s, fld) }
+ some(match_path(a_pth)) => (expr_path(a_pth), s),
+ some(match_expr(a_exp)) => (a_exp.node, a_exp.span),
+ some(m) => match_error(cx, m, ~"an expression"),
+ none => orig(e, s, fld)
}
}
- _ { orig(e, s, fld) }
+ _ => orig(e, s, fld)
}
}
-> (ast::ty_, span)
{
return alt t {
- ast::ty_path(pth, _) {
+ ast::ty_path(pth, _) => {
alt path_to_ident(pth) {
- some(id) {
+ some(id) => {
alt follow_for_trans(cx, b.find(id), idx_path) {
- some(match_ty(ty)) { (ty.node, ty.span) }
- some(m) { match_error(cx, m, ~"a type") }
- none { orig(t, s, fld) }
+ some(match_ty(ty)) => (ty.node, ty.span),
+ some(m) => match_error(cx, m, ~"a type"),
+ none => orig(t, s, fld)
}
}
- none { orig(t, s, fld) }
+ none => orig(t, s, fld)
}
}
- _ { orig(t, s, fld) }
+ _ => orig(t, s, fld)
}
}
-> (blk_, span)
{
return alt block_to_ident(blk) {
- some(id) {
+ some(id) => {
alt follow_for_trans(cx, b.find(id), idx_path) {
- some(match_block(new_blk)) { (new_blk.node, new_blk.span) }
-
-
-
-
+ some(match_block(new_blk)) => (new_blk.node, new_blk.span),
// possibly allow promotion of ident/path/expr to blocks?
- some(m) {
- match_error(cx, m, ~"a block")
- }
- none { orig(blk, s, fld) }
+ some(m) => match_error(cx, m, ~"a block"),
+ none => orig(blk, s, fld)
}
}
- none { orig(blk, s, fld) }
+ none => orig(blk, s, fld)
}
}
//it might be possible to traverse only exprs, not matchables
alt m {
- match_expr(e) {
+ match_expr(e) => {
alt e.node {
- expr_path(p_pth) { p_t_s_r_path(cx, p_pth, s, b); }
- expr_vec(p_elts, _) {
+ expr_path(p_pth) => p_t_s_r_path(cx, p_pth, s, b),
+ expr_vec(p_elts, _) => {
alt elts_to_ell(cx, p_elts) {
- {pre: pre, rep: some(repeat_me), post: post} {
+ {pre: pre, rep: some(repeat_me), post: post} => {
p_t_s_r_length(cx, vec::len(pre) + vec::len(post), true, s,
b);
if vec::len(pre) > 0u {
~"matching after `...` not yet supported");
}
}
- {pre: pre, rep: none, post: post} {
+ {pre: pre, rep: none, post: post} => {
if post != ~[] {
cx.bug(~"elts_to_ell provided an invalid result");
}
}
}
/* FIXME (#2251): handle embedded types and blocks, at least */
- expr_mac(mac) {
+ expr_mac(mac) => {
p_t_s_r_mac(cx, mac, s, b);
}
- _ {
+ _ => {
fn select(cx: ext_ctxt, m: matchable, pat: @expr) ->
match_result {
return alt m {
- match_expr(e) {
+ match_expr(e) => {
if e == pat { some(leaf(match_exact)) } else { none }
}
- _ { cx.bug(~"broken traversal in p_t_s_r") }
+ _ => cx.bug(~"broken traversal in p_t_s_r")
}
}
b.literal_ast_matchers.push(|x| select(cx, x, e));
}
}
}
- _ {
- cx.bug(~"undocumented invariant in p_t_s_rec");
- }
+ _ => cx.bug(~"undocumented invariant in p_t_s_rec")
}
}
/* make a match more precise */
fn specialize_match(m: matchable) -> matchable {
return alt m {
- match_expr(e) {
+ match_expr(e) => {
alt e.node {
- expr_path(pth) {
+ expr_path(pth) => {
alt path_to_ident(pth) {
- some(id) { match_ident(respan(pth.span, id)) }
- none { match_path(pth) }
+ some(id) => match_ident(respan(pth.span, id)),
+ none => match_path(pth)
}
}
- _ { m }
+ _ => m
}
}
- _ { m }
+ _ => m
}
}
/* pattern_to_selectors helper functions */
fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) {
alt path_to_ident(p) {
- some(p_id) {
+ some(p_id) => {
fn select(cx: ext_ctxt, m: matchable) -> match_result {
return alt m {
- match_expr(e) { some(leaf(specialize_match(m))) }
- _ { cx.bug(~"broken traversal in p_t_s_r") }
+ match_expr(e) => some(leaf(specialize_match(m))),
+ _ => cx.bug(~"broken traversal in p_t_s_r")
}
}
if b.real_binders.contains_key(p_id) {
}
b.real_binders.insert(p_id, compose_sels(s, |x| select(cx, x)));
}
- none { }
+ none => ()
}
}
fn block_to_ident(blk: blk_) -> option<ident> {
if vec::len(blk.stmts) != 0u { return none; }
return alt blk.expr {
- some(expr) {
- alt expr.node { expr_path(pth) { path_to_ident(pth) } _ { none } }
+ some(expr) => alt expr.node {
+ expr_path(pth) => path_to_ident(pth),
+ _ => none
}
- none { none }
+ none => none
}
}
fn select_pt_1(cx: ext_ctxt, m: matchable,
fn_m: fn(ast::mac) -> match_result) -> match_result {
return alt m {
- match_expr(e) {
- alt e.node { expr_mac(mac) { fn_m(mac) } _ { none } }
+ match_expr(e) => alt e.node {
+ expr_mac(mac) => fn_m(mac),
+ _ => none
}
- _ { cx.bug(~"broken traversal in p_t_s_r") }
+ _ => cx.bug(~"broken traversal in p_t_s_r")
}
}
fn no_des(cx: ext_ctxt, sp: span, syn: ~str) -> ! {
cx.span_fatal(sp, ~"destructuring " + syn + ~" is not yet supported");
}
alt mac.node {
- ast::mac_ellipsis { cx.span_fatal(mac.span, ~"misused `...`"); }
- ast::mac_invoc(_, _, _) { no_des(cx, mac.span, ~"macro calls"); }
- ast::mac_invoc_tt(_, _) { no_des(cx, mac.span, ~"macro calls"); }
- ast::mac_aq(_,_) { no_des(cx, mac.span, ~"antiquotes"); }
- ast::mac_var(_) { no_des(cx, mac.span, ~"antiquote variables"); }
+ ast::mac_ellipsis => cx.span_fatal(mac.span, ~"misused `...`"),
+ ast::mac_invoc(_, _, _) => no_des(cx, mac.span, ~"macro calls"),
+ ast::mac_invoc_tt(_, _) => no_des(cx, mac.span, ~"macro calls"),
+ ast::mac_aq(_,_) => no_des(cx, mac.span, ~"antiquotes"),
+ ast::mac_var(_) => no_des(cx, mac.span, ~"antiquote variables")
}
}
fn select(cx: ext_ctxt, repeat_me: @expr, offset: uint, m: matchable) ->
match_result {
return alt m {
- match_expr(e) {
+ match_expr(e) => {
alt e.node {
- expr_vec(arg_elts, _) {
+ expr_vec(arg_elts, _) => {
let mut elts = ~[];
let mut idx = offset;
while idx < vec::len(arg_elts) {
// error we want to report is one in the macro def
some(seq(@elts, repeat_me.span))
}
- _ { none }
+ _ => none
}
}
- _ { cx.bug(~"broken traversal in p_t_s_r") }
+ _ => cx.bug(~"broken traversal in p_t_s_r")
}
}
p_t_s_rec(cx, match_expr(repeat_me),
fn len_select(_cx: ext_ctxt, m: matchable, at_least: bool, len: uint) ->
match_result {
return alt m {
- match_expr(e) {
+ match_expr(e) => {
alt e.node {
- expr_vec(arg_elts, _) {
+ expr_vec(arg_elts, _) => {
let actual_len = vec::len(arg_elts);
if at_least && actual_len >= len || actual_len == len {
some(leaf(match_exact))
} else { none }
}
- _ { none }
+ _ => none
}
}
- _ { none }
+ _ => none
}
}
b.literal_ast_matchers.push(
while idx < vec::len(elts) {
fn select(cx: ext_ctxt, m: matchable, idx: uint) -> match_result {
return alt m {
- match_expr(e) {
+ match_expr(e) => {
alt e.node {
- expr_vec(arg_elts, _) {
+ expr_vec(arg_elts, _) => {
some(leaf(match_expr(arg_elts[idx])))
}
- _ { none }
+ _ => none
}
}
- _ { cx.bug(~"broken traversal in p_t_s_r") }
+ _ => cx.bug(~"broken traversal in p_t_s_r")
}
}
p_t_s_rec(cx, match_expr(elts[idx]),
let mut clauses: ~[@clause] = ~[];
for args.each |arg| {
alt arg.node {
- expr_vec(elts, mutbl) {
+ expr_vec(elts, mutbl) => {
if vec::len(elts) != 2u {
cx.span_fatal((*arg).span,
~"extension clause must consist of ~[" +
alt elts[0u].node {
- expr_mac(mac) {
+ expr_mac(mac) => {
alt mac.node {
- mac_invoc(pth, invoc_arg, body) {
+ mac_invoc(pth, invoc_arg, body) => {
alt path_to_ident(pth) {
- some(id) {
- alt macro_name {
- none { macro_name = some(id); }
- some(other_id) {
- if id != other_id {
- cx.span_fatal(pth.span,
- ~"macro name must be " +
- ~"consistent");
- }
- }
+ some(id) => alt macro_name {
+ none => macro_name = some(id),
+ some(other_id) => if id != other_id {
+ cx.span_fatal(pth.span,
+ ~"macro name must be " +
+ ~"consistent");
}
}
- none {
- cx.span_fatal(pth.span,
- ~"macro name must not be a path");
- }
+ none => cx.span_fatal(pth.span,
+ ~"macro name must not be a path")
}
let arg = alt invoc_arg {
- some(arg) { arg }
- none { cx.span_fatal(mac.span,
- ~"macro must have arguments")}
+ some(arg) => arg,
+ none => cx.span_fatal(mac.span,
+ ~"macro must have arguments")
};
vec::push(clauses,
@{params: pattern_to_selectors(cx, arg),
// FIXME (#2251): check duplicates (or just simplify
// the macro arg situation)
}
- _ {
+ _ => {
cx.span_bug(mac.span, ~"undocumented invariant in \
add_extension");
}
}
}
- _ {
+ _ => {
cx.span_fatal(elts[0u].span,
~"extension clause must" +
~" start with a macro invocation.");
}
}
}
- _ {
+ _ => {
cx.span_fatal((*arg).span,
~"extension must be ~[clause, " + ~" ...]");
}
return {ident:
alt macro_name {
- some(id) { id }
- none {
- cx.span_fatal(sp, ~"macro definition must have " +
- ~"at least one clause")
- }
+ some(id) => id,
+ none => cx.span_fatal(sp, ~"macro definition must have " +
+ ~"at least one clause")
},
ext: normal({expander: ext, span: some(option::get(arg).span)})};
_body: ast::mac_body,
clauses: ~[@clause]) -> @expr {
let arg = alt arg {
- some(arg) { arg }
- none { cx.span_fatal(sp, ~"macro must have arguments")}
+ some(arg) => arg,
+ none => cx.span_fatal(sp, ~"macro must have arguments")
};
for clauses.each |c| {
alt use_selectors_to_bind(c.params, arg) {
- some(bindings) { return transcribe(cx, bindings, c.body); }
- none { again; }
+ some(bindings) => return transcribe(cx, bindings, c.body),
+ none => again
}
}
cx.span_fatal(sp, ~"no clauses match macro invocation");
let res = io::read_whole_file_str(res_rel_file(cx, sp, file));
alt res {
- result::ok(_) { /* Continue. */ }
- result::err(e) {
+ result::ok(_) => { /* Continue. */ }
+ result::err(e) => {
cx.parse_sess().span_diagnostic.handler().fatal(e);
}
}
let file = expr_to_str(cx, args[0], ~"#include_bin requires a string");
alt io::read_whole_file(res_rel_file(cx, sp, file)) {
- result::ok(src) {
+ result::ok(src) => {
let u8_exprs = vec::map(src, |char: u8| {
mk_u8(cx, sp, char)
});
return mk_uniq_vec_e(cx, sp, u8_exprs);
}
- result::err(e) {
+ result::err(e) => {
cx.parse_sess().span_diagnostic.handler().fatal(e)
}
}
fn is_some(&&mpu: matcher_pos_up) -> bool {
alt mpu {
- matcher_pos_up(none) { false }
- _ { true }
+ matcher_pos_up(none) => false,
+ _ => true
}
}
fn copy_up(&& mpu: matcher_pos_up) -> matcher_pos {
alt mpu {
- matcher_pos_up(some(mp)) { copy mp }
- _ { fail }
+ matcher_pos_up(some(mp)) => copy mp,
+ _ => fail
}
}
fn count_names(ms: &[matcher]) -> uint {
vec::foldl(0u, ms, |ct, m| {
ct + alt m.node {
- match_tok(_) { 0u }
- match_seq(more_ms, _, _, _, _) { count_names(more_ms) }
- match_nonterminal(_,_,_) { 1u }
+ match_tok(_) => 0u,
+ match_seq(more_ms, _, _, _, _) => count_names(more_ms),
+ match_nonterminal(_,_,_) => 1u
}})
}
let mut match_idx_hi = 0u;
for ms.each() |elt| {
alt elt.node {
- match_tok(_) {}
- match_seq(_,_,_,_,hi) {
+ match_tok(_) => (),
+ match_seq(_,_,_,_,hi) => {
match_idx_hi = hi; // it is monotonic...
}
- match_nonterminal(_,_,pos) {
+ match_nonterminal(_,_,pos) => {
match_idx_hi = pos+1u; // ...so latest is highest
}
}
fn n_rec(p_s: parse_sess, m: matcher, res: ~[@named_match],
ret_val: hashmap<ident, @named_match>) {
alt m {
- {node: match_tok(_), span: _} { }
- {node: match_seq(more_ms, _, _, _, _), span: _} {
+ {node: match_tok(_), span: _} => (),
+ {node: match_seq(more_ms, _, _, _, _), span: _} => {
for more_ms.each() |next_m| { n_rec(p_s, next_m, res, ret_val) };
}
- {node: match_nonterminal(bind_name, _, idx), span: sp} {
+ {node: match_nonterminal(bind_name, _, idx), span: sp} => {
if ret_val.contains_key(bind_name) {
p_s.span_diagnostic.span_fatal(sp, ~"Duplicated bind name: "
+ *bind_name)
fn parse_or_else(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader,
ms: ~[matcher]) -> hashmap<ident, @named_match> {
alt parse(sess, cfg, rdr, ms) {
- success(m) { m }
- failure(sp, str) {
- sess.span_diagnostic.span_fatal(sp, str);
- }
+ success(m) => m,
+ failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str)
}
}
// the *_t vars are workarounds for the lack of unary move
alt copy ei.sep {
- some(t) if idx == len { // we need a separator
+ some(t) if idx == len => { // we need a separator
if tok == t { //pass the separator
let ei_t <- ei;
ei_t.idx += 1u;
vec::push(next_eis, ei_t);
}
}
- _ { // we don't need a separator
+ _ => { // we don't need a separator
let ei_t <- ei;
ei_t.idx = 0u;
vec::push(cur_eis, ei_t);
alt copy ei.elts[idx].node {
/* need to descend into sequence */
match_seq(matchers, sep, zero_ok,
- match_idx_lo, match_idx_hi){
+ match_idx_lo, match_idx_hi) => {
if zero_ok {
let new_ei = copy ei;
new_ei.idx += 1u;
sp_lo: sp.lo
});
}
- match_nonterminal(_,_,_) { vec::push(bb_eis, ei) }
- match_tok(t) {
+ match_nonterminal(_,_,_) => { vec::push(bb_eis, ei) }
+ match_tok(t) => {
let ei_t <- ei;
if t == tok { ei_t.idx += 1u; vec::push(next_eis, ei_t)}
}
|| bb_eis.len() > 1u {
let nts = str::connect(vec::map(bb_eis, |ei| {
alt ei.elts[ei.idx].node {
- match_nonterminal(bind,name,_) {
+ match_nonterminal(bind,name,_) => {
fmt!{"%s ('%s')", *name, *bind}
}
- _ { fail; } } }), ~" or ");
+ _ => fail
+ } }), ~" or ");
return failure(sp, fmt!{
"Local ambiguity: multiple parsing options: \
built-in NTs %s or %u other options.",
let ei = vec::pop(bb_eis);
alt ei.elts[ei.idx].node {
- match_nonterminal(_, name, idx) {
+ match_nonterminal(_, name, idx) => {
ei.matches[idx].push(@matched_nonterminal(
parse_nt(rust_parser, *name)));
ei.idx += 1u;
}
- _ { fail; }
+ _ => fail
}
vec::push(cur_eis,ei);
fn parse_nt(p: parser, name: ~str) -> nonterminal {
alt name {
- ~"item" { alt p.parse_item(~[]) {
- some(i) { token::nt_item(i) }
- none { p.fatal(~"expected an item keyword") }
- }}
- ~"block" { token::nt_block(p.parse_block()) }
- ~"stmt" { token::nt_stmt(p.parse_stmt(~[])) }
- ~"pat" { token::nt_pat(p.parse_pat(true)) }
- ~"expr" { token::nt_expr(p.parse_expr()) }
- ~"ty" { token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)) }
+ ~"item" => alt p.parse_item(~[]) {
+ some(i) => token::nt_item(i),
+ none => p.fatal(~"expected an item keyword")
+ }
+ ~"block" => token::nt_block(p.parse_block()),
+ ~"stmt" => token::nt_stmt(p.parse_stmt(~[])),
+ ~"pat" => token::nt_pat(p.parse_pat(true)),
+ ~"expr" => token::nt_expr(p.parse_expr()),
+ ~"ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)),
// this could be handled like a token, since it is one
- ~"ident" { alt copy p.token {
- token::IDENT(sn,b) { p.bump(); token::nt_ident(sn,b) }
- _ { p.fatal(~"expected ident, found "
- + token::to_str(*p.reader.interner(), copy p.token)) }
- } }
- ~"path" { token::nt_path(p.parse_path_with_tps(false)) }
- ~"tt" {
+ ~"ident" => alt copy p.token {
+ token::IDENT(sn,b) => { p.bump(); token::nt_ident(sn,b) }
+ _ => p.fatal(~"expected ident, found "
+ + token::to_str(*p.reader.interner(), copy p.token))
+ }
+ ~"path" => token::nt_path(p.parse_path_with_tps(false)),
+ ~"tt" => {
p.quote_depth += 1u; //but in theory, non-quoted tts might be useful
let res = token::nt_tt(@p.parse_token_tree());
p.quote_depth -= 1u;
res
}
- ~"matchers" { token::nt_matchers(p.parse_matchers()) }
- _ { p.fatal(~"Unsupported builtin nonterminal parser: " + name)}
+ ~"matchers" => token::nt_matchers(p.parse_matchers()),
+ _ => p.fatal(~"Unsupported builtin nonterminal parser: " + name)
}
}
// Extract the arguments:
let lhses:~[@named_match] = alt argument_map.get(@~"lhs") {
- @matched_seq(s, sp) { s }
- _ { cx.span_bug(sp, ~"wrong-structured lhs") }
+ @matched_seq(s, sp) => s,
+ _ => cx.span_bug(sp, ~"wrong-structured lhs")
};
let rhses:~[@named_match] = alt argument_map.get(@~"rhs") {
- @matched_seq(s, sp) { s }
- _ { cx.span_bug(sp, ~"wrong-structured rhs") }
+ @matched_seq(s, sp) => s,
+ _ => cx.span_bug(sp, ~"wrong-structured rhs")
};
// Given `lhses` and `rhses`, this is the new macro we create
for lhses.eachi() |i, lhs| { // try each arm's matchers
alt lhs {
- @matched_nonterminal(nt_matchers(mtcs)) {
+ @matched_nonterminal(nt_matchers(mtcs)) => {
// `none` is because we're not interpolating
let arg_rdr = new_tt_reader(s_d, itr, none, arg) as reader;
alt parse(cx.parse_sess(), cx.cfg(), arg_rdr, mtcs) {
- success(named_matches) {
+ success(named_matches) => {
let rhs = alt rhses[i] { // okay, what's your transcriber?
- @matched_nonterminal(nt_tt(@tt)) { tt }
- _ { cx.span_bug(sp, ~"bad thing in rhs") }
+ @matched_nonterminal(nt_tt(@tt)) => tt,
+ _ => cx.span_bug(sp, ~"bad thing in rhs")
};
// rhs has holes ( `$id` and `$(...)` that need filled)
let trncbr = new_tt_reader(s_d, itr, some(named_matches),
trncbr as reader, SOURCE_FILE);
return mr_expr(p.parse_expr());
}
- failure(sp, msg) {
- if sp.lo >= best_fail_spot.lo {
- best_fail_spot = sp; best_fail_msg = msg;
- }
+ failure(sp, msg) => if sp.lo >= best_fail_spot.lo {
+ best_fail_spot = sp;
+ best_fail_msg = msg;
}
}
}
- _ { cx.bug(~"non-matcher found in parsed lhses"); }
+ _ => cx.bug(~"non-matcher found in parsed lhses")
}
}
cx.span_fatal(best_fail_spot, best_fail_msg);
mut cur: @{readme: src, mut idx: 0u, dotdotdoted: false,
sep: none, up: tt_frame_up(option::none)},
interpolations: alt interp { /* just a convienience */
- none { std::map::box_str_hash::<@named_match>() }
- some(x) { x }
+ none => std::map::box_str_hash::<@named_match>(),
+ some(x) => x
},
mut repeat_idx: ~[mut], mut repeat_len: ~[],
/* dummy values, never read: */
pure fn dup_tt_frame(&&f: tt_frame) -> tt_frame {
@{readme: f.readme, mut idx: f.idx, dotdotdoted: f.dotdotdoted,
sep: f.sep, up: alt f.up {
- tt_frame_up(some(up_frame)) {
+ tt_frame_up(some(up_frame)) => {
tt_frame_up(some(dup_tt_frame(up_frame)))
}
- tt_frame_up(none) { tt_frame_up(none) }
+ tt_frame_up(none) => tt_frame_up(none)
}
}
}
start: @named_match) -> @named_match {
pure fn red(&&ad: @named_match, &&idx: uint) -> @named_match {
alt *ad {
- matched_nonterminal(_) {
+ matched_nonterminal(_) => {
// end of the line; duplicate henceforth
ad
}
- matched_seq(ads, _) { ads[idx] }
+ matched_seq(ads, _) => ads[idx]
}
}
vec::foldl(start, r.repeat_idx, red)
fn lockstep_iter_size(&&t: token_tree, &&r: tt_reader) -> lis {
fn lis_merge(lhs: lis, rhs: lis) -> lis {
alt lhs {
- lis_unconstrained { rhs }
- lis_contradiction(_) { lhs }
- lis_constraint(l_len, l_id) {
- alt rhs {
- lis_unconstrained { lhs }
- lis_contradiction(_) { rhs }
- lis_constraint(r_len, _) if l_len == r_len { lhs }
- lis_constraint(r_len, r_id) {
+ lis_unconstrained => rhs,
+ lis_contradiction(_) => lhs,
+ lis_constraint(l_len, l_id) => alt rhs {
+ lis_unconstrained => lhs,
+ lis_contradiction(_) => rhs,
+ lis_constraint(r_len, _) if l_len == r_len => lhs,
+ lis_constraint(r_len, r_id) => {
lis_contradiction(fmt!{"Inconsistent lockstep iteration: \
- '%s' has %u items, but '%s' has %u",
- *l_id, l_len, *r_id, r_len})
- }
+ '%s' has %u items, but '%s' has %u",
+ *l_id, l_len, *r_id, r_len})
}
}
}
}
alt t {
- tt_delim(tts) | tt_seq(_, tts, _, _) {
+ tt_delim(tts) | tt_seq(_, tts, _, _) => {
vec::foldl(lis_unconstrained, tts, {|lis, tt|
lis_merge(lis, lockstep_iter_size(tt, r)) })
}
- tt_tok(*) { lis_unconstrained }
- tt_nonterminal(_, name) {
- alt *lookup_cur_matched(r, name) {
- matched_nonterminal(_) { lis_unconstrained }
- matched_seq(ads, _) { lis_constraint(ads.len(), name) }
- }
+ tt_tok(*) => lis_unconstrained,
+ tt_nonterminal(_, name) => alt *lookup_cur_matched(r, name) {
+ matched_nonterminal(_) => lis_unconstrained,
+ matched_seq(ads, _) => lis_constraint(ads.len(), name)
}
}
}
|| r.repeat_idx.last() == r.repeat_len.last() - 1 {
alt r.cur.up {
- tt_frame_up(none) {
+ tt_frame_up(none) => {
r.cur_tok = EOF;
return ret_val;
}
- tt_frame_up(some(tt_f)) {
+ tt_frame_up(some(tt_f)) => {
if r.cur.dotdotdoted {
vec::pop(r.repeat_idx); vec::pop(r.repeat_len);
}
r.cur.idx = 0u;
r.repeat_idx[r.repeat_idx.len() - 1u] += 1u;
alt r.cur.sep {
- some(tk) {
+ some(tk) => {
r.cur_tok = tk; /* repeat same span, I guess */
return ret_val;
}
- none {}
+ none => ()
}
}
}
loop { /* because it's easiest, this handles `tt_delim` not starting
with a `tt_tok`, even though it won't happen */
alt r.cur.readme[r.cur.idx] {
- tt_delim(tts) {
+ tt_delim(tts) => {
r.cur = @{readme: tts, mut idx: 0u, dotdotdoted: false,
sep: none, up: tt_frame_up(option::some(r.cur)) };
// if this could be 0-length, we'd need to potentially recur here
}
- tt_tok(sp, tok) {
+ tt_tok(sp, tok) => {
r.cur_span = sp; r.cur_tok = tok;
r.cur.idx += 1u;
return ret_val;
}
- tt_seq(sp, tts, sep, zerok) {
+ tt_seq(sp, tts, sep, zerok) => {
alt lockstep_iter_size(tt_seq(sp, tts, sep, zerok), r) {
- lis_unconstrained {
+ lis_unconstrained => {
r.sp_diag.span_fatal(
sp, /* blame macro writer */
~"attempted to repeat an expression containing no syntax \
variables matched as repeating at this depth");
}
- lis_contradiction(msg) { /* FIXME #2887 blame macro invoker
+ lis_contradiction(msg) => { /* FIXME #2887 blame macro invoker
instead*/
r.sp_diag.span_fatal(sp, msg);
}
- lis_constraint(len, _) {
+ lis_constraint(len, _) => {
if len == 0 {
if !zerok {
r.sp_diag.span_fatal(sp, /* FIXME #2887 blame invoker
}
}
// FIXME #2887: think about span stuff here
- tt_nonterminal(sp, ident) {
+ tt_nonterminal(sp, ident) => {
alt *lookup_cur_matched(r, ident) {
/* sidestep the interpolation tricks for ident because
(a) idents can be in lots of places, so it'd be a pain
(b) we actually can, since it's a token. */
- matched_nonterminal(nt_ident(sn,b)) {
+ matched_nonterminal(nt_ident(sn,b)) => {
r.cur_span = sp; r.cur_tok = IDENT(sn,b);
r.cur.idx += 1u;
return ret_val;
}
- matched_nonterminal(other_whole_nt) {
+ matched_nonterminal(other_whole_nt) => {
r.cur_span = sp; r.cur_tok = INTERPOLATED(other_whole_nt);
r.cur.idx += 1u;
return ret_val;
}
- matched_seq(*) {
+ matched_seq(*) => {
r.sp_diag.span_fatal(
copy r.cur_span, /* blame the macro writer */
fmt!{"variable '%s' is still repeating at this depth",
fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
return @{node:
alt mi.node {
- meta_word(id) { meta_word(fld.fold_ident(id)) }
- meta_list(id, mis) {
+ meta_word(id) => meta_word(fld.fold_ident(id)),
+ meta_list(id, mis) => {
let fold_meta_item = |x|fold_meta_item_(x, fld);
meta_list(/* FIXME: (#2543) */ copy id,
vec::map(mis, fold_meta_item))
}
- meta_name_value(id, s) {
+ meta_name_value(id, s) => {
meta_name_value(fld.fold_ident(id),
/* FIXME (#2543) */ copy s)
}
fn fold_mac_(m: mac, fld: ast_fold) -> mac {
return {node:
alt m.node {
- mac_invoc(pth, arg, body) {
+ mac_invoc(pth, arg, body) => {
mac_invoc(fld.fold_path(pth),
option::map(arg, |x| fld.fold_expr(x)), body)
}
- mac_invoc_tt(pth, tt) { m.node }
- mac_ellipsis { mac_ellipsis }
- mac_aq(_,_) { /* FIXME (#2543) */ copy m.node }
- mac_var(_) { /* FIXME (#2543) */ copy m.node }
+ mac_invoc_tt(pth, tt) => m.node,
+ mac_ellipsis => mac_ellipsis,
+ mac_aq(_,_) => /* FIXME (#2543) */ copy m.node,
+ mac_var(_) => /* FIXME (#2543) */ copy m.node,
},
span: fld.new_span(m.span)};
}
fn fold_ty_param_bound(tpb: ty_param_bound, fld: ast_fold) -> ty_param_bound {
alt tpb {
- bound_copy | bound_send | bound_const | bound_owned { tpb }
- bound_trait(ty) { bound_trait(fld.fold_ty(ty)) }
+ bound_copy | bound_send | bound_const | bound_owned => tpb,
+ bound_trait(ty) => bound_trait(fld.fold_ty(ty))
}
}
fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) ->
crate_directive_ {
return alt cd {
- cdir_src_mod(id, attrs) {
+ cdir_src_mod(id, attrs) => {
cdir_src_mod(fld.fold_ident(id), /* FIXME (#2543) */ copy attrs)
}
- cdir_dir_mod(id, cds, attrs) {
+ cdir_dir_mod(id, cds, attrs) => {
cdir_dir_mod(fld.fold_ident(id),
vec::map(cds, |x| fld.fold_crate_directive(x)),
/* FIXME (#2543) */ copy attrs)
}
- cdir_view_item(vi) { cdir_view_item(fld.fold_view_item(vi)) }
- cdir_syntax(_) { copy cd }
+ cdir_view_item(vi) => cdir_view_item(fld.fold_view_item(vi)),
+ cdir_syntax(_) => copy cd
}
}
attrs: vec::map(ni.attrs, fold_attribute),
node:
alt ni.node {
- foreign_item_fn(fdec, typms) {
+ foreign_item_fn(fdec, typms) => {
foreign_item_fn({inputs: vec::map(fdec.inputs, fold_arg),
output: fld.fold_ty(fdec.output),
purity: fdec.purity,
fn noop_fold_class_item(&&ci: @class_member, fld: ast_fold)
-> @class_member {
@{node: alt ci.node {
- instance_var(ident, t, cm, id, p) {
+ instance_var(ident, t, cm, id, p) => {
instance_var(/* FIXME (#2543) */ copy ident,
fld.fold_ty(t), cm, id, p)
}
- class_method(m) { class_method(fld.fold_method(m)) }
+ class_method(m) => class_method(fld.fold_method(m))
},
span: ci.span}
}
fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
return alt i {
- item_const(t, e) { item_const(fld.fold_ty(t), fld.fold_expr(e)) }
- item_fn(decl, typms, body) {
+ item_const(t, e) => item_const(fld.fold_ty(t), fld.fold_expr(e)),
+ item_fn(decl, typms, body) => {
item_fn(fold_fn_decl(decl, fld),
fold_ty_params(typms, fld),
fld.fold_block(body))
}
- item_mod(m) { item_mod(fld.fold_mod(m)) }
- item_foreign_mod(nm) { item_foreign_mod(fld.fold_foreign_mod(nm)) }
- item_ty(t, typms) { item_ty(fld.fold_ty(t),
- fold_ty_params(typms, fld)) }
- item_enum(variants, typms) {
+ item_mod(m) => item_mod(fld.fold_mod(m)),
+ item_foreign_mod(nm) => item_foreign_mod(fld.fold_foreign_mod(nm)),
+ item_ty(t, typms) => item_ty(fld.fold_ty(t),
+ fold_ty_params(typms, fld)),
+ item_enum(variants, typms) => {
item_enum(vec::map(variants, |x| fld.fold_variant(x)),
fold_ty_params(typms, fld))
}
- item_class(typms, traits, items, m_ctor, m_dtor) {
+ item_class(typms, traits, items, m_ctor, m_dtor) => {
let resulting_optional_constructor;
alt m_ctor {
none => {
resulting_optional_constructor,
dtor)
}
- item_impl(tps, ifce, ty, methods) {
+ item_impl(tps, ifce, ty, methods) => {
item_impl(fold_ty_params(tps, fld),
ifce.map(|p| fold_trait_ref(p, fld)),
fld.fold_ty(ty),
vec::map(methods, |x| fld.fold_method(x)))
}
- item_trait(tps, traits, methods) {
+ item_trait(tps, traits, methods) => {
item_trait(fold_ty_params(tps, fld),
vec::map(traits, |p| fold_trait_ref(p, fld)),
/* FIXME (#2543) */ copy methods)
}
- item_mac(m) {
+ item_mac(m) => {
// FIXME #2888: we might actually want to do something here.
item_mac(m)
}
fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
return alt s {
- stmt_decl(d, nid) { stmt_decl(fld.fold_decl(d), fld.new_id(nid)) }
- stmt_expr(e, nid) { stmt_expr(fld.fold_expr(e), fld.new_id(nid)) }
- stmt_semi(e, nid) { stmt_semi(fld.fold_expr(e), fld.new_id(nid)) }
+ stmt_decl(d, nid) => stmt_decl(fld.fold_decl(d), fld.new_id(nid)),
+ stmt_expr(e, nid) => stmt_expr(fld.fold_expr(e), fld.new_id(nid)),
+ stmt_semi(e, nid) => stmt_semi(fld.fold_expr(e), fld.new_id(nid))
};
}
fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
return alt p {
- pat_wild { pat_wild }
- pat_ident(binding_mode, pth, sub) {
+ pat_wild => pat_wild,
+ pat_ident(binding_mode, pth, sub) => {
pat_ident(binding_mode,
fld.fold_path(pth),
option::map(sub, |x| fld.fold_pat(x)))
}
- pat_lit(e) { pat_lit(fld.fold_expr(e)) }
- pat_enum(pth, pats) {
+ pat_lit(e) => pat_lit(fld.fold_expr(e)),
+ pat_enum(pth, pats) => {
pat_enum(fld.fold_path(pth), option::map(pats,
|pats| vec::map(pats, |x| fld.fold_pat(x))))
}
- pat_rec(fields, etc) {
+ pat_rec(fields, etc) => {
let mut fs = ~[];
for fields.each |f| {
vec::push(fs,
}
pat_rec(fs, etc)
}
- pat_tup(elts) { pat_tup(vec::map(elts, |x| fld.fold_pat(x))) }
- pat_box(inner) { pat_box(fld.fold_pat(inner)) }
- pat_uniq(inner) { pat_uniq(fld.fold_pat(inner)) }
- pat_range(e1, e2) {
+ pat_tup(elts) => pat_tup(vec::map(elts, |x| fld.fold_pat(x))),
+ pat_box(inner) => pat_box(fld.fold_pat(inner)),
+ pat_uniq(inner) => pat_uniq(fld.fold_pat(inner)),
+ pat_range(e1, e2) => {
pat_range(fld.fold_expr(e1), fld.fold_expr(e2))
}
};
fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ {
alt d {
- decl_local(ls) { decl_local(vec::map(ls, |x| fld.fold_local(x))) }
- decl_item(it) {
- alt fld.fold_item(it) {
- some(it_folded) { decl_item(it_folded) }
- none { decl_local(~[]) }
- }
+ decl_local(ls) => decl_local(vec::map(ls, |x| fld.fold_local(x))),
+ decl_item(it) => alt fld.fold_item(it) {
+ some(it_folded) => decl_item(it_folded),
+ none => decl_local(~[])
}
}
}
let fold_mac = |x| fold_mac_(x, fld);
return alt e {
- expr_vstore(e, v) {
+ expr_vstore(e, v) => {
expr_vstore(fld.fold_expr(e), v)
}
- expr_vec(exprs, mutt) {
+ expr_vec(exprs, mutt) => {
expr_vec(fld.map_exprs(|x| fld.fold_expr(x), exprs), mutt)
}
expr_repeat(expr, count, mutt) =>
expr_repeat(fld.fold_expr(expr), fld.fold_expr(count), mutt),
- expr_rec(fields, maybe_expr) {
+ expr_rec(fields, maybe_expr) => {
expr_rec(vec::map(fields, fold_field),
option::map(maybe_expr, |x| fld.fold_expr(x)))
}
- expr_tup(elts) { expr_tup(vec::map(elts, |x| fld.fold_expr(x))) }
- expr_call(f, args, blk) {
+ expr_tup(elts) => expr_tup(vec::map(elts, |x| fld.fold_expr(x))),
+ expr_call(f, args, blk) => {
expr_call(fld.fold_expr(f),
fld.map_exprs(|x| fld.fold_expr(x), args),
blk)
}
- expr_binary(binop, lhs, rhs) {
+ expr_binary(binop, lhs, rhs) => {
expr_binary(binop, fld.fold_expr(lhs), fld.fold_expr(rhs))
}
- expr_unary(binop, ohs) { expr_unary(binop, fld.fold_expr(ohs)) }
- expr_loop_body(f) { expr_loop_body(fld.fold_expr(f)) }
- expr_do_body(f) { expr_do_body(fld.fold_expr(f)) }
- expr_lit(_) { copy e }
- expr_cast(expr, ty) { expr_cast(fld.fold_expr(expr), ty) }
- expr_addr_of(m, ohs) { expr_addr_of(m, fld.fold_expr(ohs)) }
- expr_if(cond, tr, fl) {
+ expr_unary(binop, ohs) => expr_unary(binop, fld.fold_expr(ohs)),
+ expr_loop_body(f) => expr_loop_body(fld.fold_expr(f)),
+ expr_do_body(f) => expr_do_body(fld.fold_expr(f)),
+ expr_lit(_) => copy e,
+ expr_cast(expr, ty) => expr_cast(fld.fold_expr(expr), ty),
+ expr_addr_of(m, ohs) => expr_addr_of(m, fld.fold_expr(ohs)),
+ expr_if(cond, tr, fl) => {
expr_if(fld.fold_expr(cond), fld.fold_block(tr),
option::map(fl, |x| fld.fold_expr(x)))
}
- expr_while(cond, body) {
+ expr_while(cond, body) => {
expr_while(fld.fold_expr(cond), fld.fold_block(body))
}
- expr_loop(body) {
+ expr_loop(body) => {
expr_loop(fld.fold_block(body))
}
- expr_alt(expr, arms, mode) {
+ expr_alt(expr, arms, mode) => {
expr_alt(fld.fold_expr(expr),
vec::map(arms, |x| fld.fold_arm(x)), mode)
}
- expr_fn(proto, decl, body, captures) {
+ expr_fn(proto, decl, body, captures) => {
expr_fn(proto, fold_fn_decl(decl, fld),
fld.fold_block(body),
@((*captures).map(|cap_item| {
@({id: fld.new_id((*cap_item).id)
with *cap_item})})))
}
- expr_fn_block(decl, body, captures) {
+ expr_fn_block(decl, body, captures) => {
expr_fn_block(fold_fn_decl(decl, fld), fld.fold_block(body),
@((*captures).map(|cap_item| {
@({id: fld.new_id((*cap_item).id)
with *cap_item})})))
}
- expr_block(blk) { expr_block(fld.fold_block(blk)) }
- expr_move(el, er) {
+ expr_block(blk) => expr_block(fld.fold_block(blk)),
+ expr_move(el, er) => {
expr_move(fld.fold_expr(el), fld.fold_expr(er))
}
- expr_copy(e) { expr_copy(fld.fold_expr(e)) }
- expr_unary_move(e) { expr_unary_move(fld.fold_expr(e)) }
- expr_assign(el, er) {
+ expr_copy(e) => expr_copy(fld.fold_expr(e)),
+ expr_unary_move(e) => expr_unary_move(fld.fold_expr(e)),
+ expr_assign(el, er) => {
expr_assign(fld.fold_expr(el), fld.fold_expr(er))
}
- expr_swap(el, er) {
+ expr_swap(el, er) => {
expr_swap(fld.fold_expr(el), fld.fold_expr(er))
}
- expr_assign_op(op, el, er) {
+ expr_assign_op(op, el, er) => {
expr_assign_op(op, fld.fold_expr(el), fld.fold_expr(er))
}
- expr_field(el, id, tys) {
+ expr_field(el, id, tys) => {
expr_field(fld.fold_expr(el), fld.fold_ident(id),
vec::map(tys, |x| fld.fold_ty(x)))
}
- expr_index(el, er) {
+ expr_index(el, er) => {
expr_index(fld.fold_expr(el), fld.fold_expr(er))
}
- expr_path(pth) { expr_path(fld.fold_path(pth)) }
- expr_fail(e) { expr_fail(option::map(e, |x| fld.fold_expr(x))) }
- expr_break | expr_again { copy e }
- expr_ret(e) { expr_ret(option::map(e, |x| fld.fold_expr(x))) }
- expr_log(i, lv, e) { expr_log(i, fld.fold_expr(lv),
- fld.fold_expr(e)) }
- expr_assert(e) { expr_assert(fld.fold_expr(e)) }
- expr_mac(mac) { expr_mac(fold_mac(mac)) }
- expr_struct(path, fields) {
+ expr_path(pth) => expr_path(fld.fold_path(pth)),
+ expr_fail(e) => expr_fail(option::map(e, |x| fld.fold_expr(x))),
+ expr_break | expr_again => copy e,
+ expr_ret(e) => expr_ret(option::map(e, |x| fld.fold_expr(x))),
+ expr_log(i, lv, e) => expr_log(i, fld.fold_expr(lv),
+ fld.fold_expr(e)),
+ expr_assert(e) => expr_assert(fld.fold_expr(e)),
+ expr_mac(mac) => expr_mac(fold_mac(mac)),
+ expr_struct(path, fields) => {
expr_struct(fld.fold_path(path), vec::map(fields, fold_field))
}
}
span: fld.new_span(f.span)}
}
alt t {
- ty_nil | ty_bot | ty_infer {copy t}
- ty_box(mt) {ty_box(fold_mt(mt, fld))}
- ty_uniq(mt) {ty_uniq(fold_mt(mt, fld))}
- ty_vec(mt) {ty_vec(fold_mt(mt, fld))}
- ty_ptr(mt) {ty_ptr(fold_mt(mt, fld))}
- ty_rptr(region, mt) {ty_rptr(region, fold_mt(mt, fld))}
- ty_rec(fields) {ty_rec(vec::map(fields, |f| fold_field(f, fld)))}
- ty_fn(proto, decl) {ty_fn(proto, fold_fn_decl(decl, fld))}
- ty_tup(tys) {ty_tup(vec::map(tys, |ty| fld.fold_ty(ty)))}
- ty_path(path, id) {ty_path(fld.fold_path(path), fld.new_id(id))}
- ty_fixed_length(t, vs) {ty_fixed_length(fld.fold_ty(t), vs)}
- ty_mac(mac) {ty_mac(fold_mac(mac))}
+ ty_nil | ty_bot | ty_infer => copy t,
+ ty_box(mt) => ty_box(fold_mt(mt, fld)),
+ ty_uniq(mt) => ty_uniq(fold_mt(mt, fld)),
+ ty_vec(mt) => ty_vec(fold_mt(mt, fld)),
+ ty_ptr(mt) => ty_ptr(fold_mt(mt, fld)),
+ ty_rptr(region, mt) => ty_rptr(region, fold_mt(mt, fld)),
+ ty_rec(fields) => ty_rec(vec::map(fields, |f| fold_field(f, fld))),
+ ty_fn(proto, decl) => ty_fn(proto, fold_fn_decl(decl, fld)),
+ ty_tup(tys) => ty_tup(vec::map(tys, |ty| fld.fold_ty(ty))),
+ ty_path(path, id) => ty_path(fld.fold_path(path), fld.new_id(id)),
+ ty_fixed_length(t, vs) => ty_fixed_length(fld.fold_ty(t), vs),
+ ty_mac(mac) => ty_mac(fold_mac(mac))
}
}
let attrs = vec::map(v.attrs, fold_attribute);
let de = alt v.disr_expr {
- some(e) {some(fld.fold_expr(e))}
- none {none}
+ some(e) => some(fld.fold_expr(e)),
+ none => none
};
return {name: /* FIXME (#2543) */ copy v.name,
attrs: attrs,
pat: fld.fold_pat(l.pat),
init:
alt l.init {
- option::none::<initializer> { l.init }
- option::some::<initializer>(init) {
+ option::none::<initializer> => l.init,
+ option::some::<initializer>(init) => {
option::some::<initializer>({op: init.op,
expr: fld.fold_expr(init.expr)})
}
}
fn fold_class_item(&&ci: @class_member) -> @class_member {
@{node: alt ci.node {
- instance_var(nm, t, mt, id, p) {
+ instance_var(nm, t, mt, id, p) => {
instance_var(/* FIXME (#2543) */ copy nm,
(self as ast_fold).fold_ty(t), mt, id, p)
}
- class_method(m) {
+ class_method(m) => {
class_method(self.fold_method(m, self as ast_fold))
}
}, span: self.new_span(ci.span)}
(parser, string_reader) {
let res = io::read_whole_file_str(path);
alt res {
- result::ok(_) { /* Continue. */ }
- result::err(e) { sess.span_diagnostic.handler().fatal(e); }
+ result::ok(_) => { /* Continue. */ }
+ result::err(e) => sess.span_diagnostic.handler().fatal(e)
}
let src = @result::unwrap(res);
let filemap = codemap::new_filemap(path, src, sess.chpos, sess.byte_pos);
{
let expect_item_next = vec::is_not_empty(first_item_attrs);
alt self.token {
- token::POUND {
+ token::POUND => {
let lo = self.span.lo;
if self.look_ahead(1u) == token::LBRACKET {
self.bump();
return some(right(self.parse_syntax_ext_naked(lo)));
} else { return none; }
}
- token::DOC_COMMENT(_) {
+ token::DOC_COMMENT(_) => {
return some(left(self.parse_outer_attributes()));
}
- _ {
- return none;
- }
+ _ => return none
}
}
let mut attrs: ~[ast::attribute] = ~[];
loop {
alt copy self.token {
- token::POUND {
+ token::POUND => {
if self.look_ahead(1u) != token::LBRACKET {
break;
}
attrs += ~[self.parse_attribute(ast::attr_outer)];
}
- token::DOC_COMMENT(s) {
+ token::DOC_COMMENT(s) => {
let attr = ::attr::mk_sugared_doc_attr(
*self.get_str(s), self.span.lo, self.span.hi);
if attr.node.style != ast::attr_outer {
attrs += ~[attr];
self.bump();
}
- _ {
- break;
- }
+ _ => break
}
}
return attrs;
let mut next_outer_attrs: ~[ast::attribute] = ~[];
loop {
alt copy self.token {
- token::POUND {
+ token::POUND => {
if self.look_ahead(1u) != token::LBRACKET {
// This is an extension
break;
break;
}
}
- token::DOC_COMMENT(s) {
+ token::DOC_COMMENT(s) => {
let attr = ::attr::mk_sugared_doc_attr(
*self.get_str(s), self.span.lo, self.span.hi);
self.bump();
break;
}
}
- _ {
- break;
- }
+ _ => break
}
}
return {inner: inner_attrs, next: next_outer_attrs};
let lo = self.span.lo;
let ident = self.parse_ident();
alt self.token {
- token::EQ {
+ token::EQ => {
self.bump();
let lit = self.parse_lit();
let mut hi = self.span.hi;
return @spanned(lo, hi, ast::meta_name_value(ident, lit));
}
- token::LPAREN {
+ token::LPAREN => {
let inner_items = self.parse_meta_seq();
let mut hi = self.span.hi;
return @spanned(lo, hi, ast::meta_list(ident, inner_items));
}
- _ {
+ _ => {
let mut hi = self.span.hi;
return @spanned(lo, hi, ast::meta_word(ident));
}
}
fn parse_optional_meta() -> ~[@ast::meta_item] {
- alt self.token { token::LPAREN { return self.parse_meta_seq(); }
- _ { return ~[]; } }
+ alt self.token {
+ token::LPAREN => return self.parse_meta_seq(),
+ _ => return ~[]
+ }
}
}
alt e.node {
ast::expr_if(_, _, _) | ast::expr_alt(_, _, _) | ast::expr_block(_)
| ast::expr_while(_, _) | ast::expr_loop(_)
- | ast::expr_call(_, _, true) {
- false
- }
- _ { true }
+ | ast::expr_call(_, _, true) => false,
+ _ => true
}
}
fn stmt_ends_with_semi(stmt: ast::stmt) -> bool {
alt stmt.node {
- ast::stmt_decl(d, _) {
+ ast::stmt_decl(d, _) => {
return alt d.node {
- ast::decl_local(_) { true }
- ast::decl_item(_) { false }
+ ast::decl_local(_) => true,
+ ast::decl_item(_) => false
}
}
- ast::stmt_expr(e, _) {
+ ast::stmt_expr(e, _) => {
return expr_requires_semi_to_be_stmt(e);
}
- ast::stmt_semi(e, _) {
+ ast::stmt_semi(e, _) => {
return false;
}
}
fn need_parens(expr: @ast::expr, outer_prec: uint) -> bool {
alt expr.node {
- ast::expr_binary(op, _, _) { operator_prec(op) < outer_prec }
- ast::expr_cast(_, _) { parse::prec::as_prec < outer_prec }
+ ast::expr_binary(op, _, _) => operator_prec(op) < outer_prec,
+ ast::expr_cast(_, _) => parse::prec::as_prec < outer_prec,
// This may be too conservative in some cases
- ast::expr_assign(_, _) { true }
- ast::expr_move(_, _) { true }
- ast::expr_swap(_, _) { true }
- ast::expr_assign_op(_, _, _) { true }
- ast::expr_ret(_) { true }
- ast::expr_assert(_) { true }
- ast::expr_log(_, _, _) { true }
- _ { !parse::classify::expr_requires_semi_to_be_stmt(expr) }
+ ast::expr_assign(_, _) => true,
+ ast::expr_move(_, _) => true,
+ ast::expr_swap(_, _) => true,
+ ast::expr_assign_op(_, _, _) => true,
+ ast::expr_ret(_) => true,
+ ast::expr_assert(_) => true,
+ ast::expr_log(_, _, _) => true,
+ _ => !parse::classify::expr_requires_semi_to_be_stmt(expr)
}
}
fn ends_in_lit_int(ex: @ast::expr) -> bool {
alt ex.node {
- ast::expr_lit(node) {
- alt node {
- @{node: ast::lit_int(_, ast::ty_i), _} |
- @{node: ast::lit_int_unsuffixed(_), _}
- { true }
- _ { false }
- }
+ ast::expr_lit(node) => alt node {
+ @{node: ast::lit_int(_, ast::ty_i), _}
+ | @{node: ast::lit_int_unsuffixed(_), _} => true,
+ _ => false
}
ast::expr_binary(_, _, sub) | ast::expr_unary(_, sub) |
ast::expr_move(_, sub) | ast::expr_copy(sub) |
ast::expr_assign(_, sub) |
ast::expr_assign_op(_, _, sub) | ast::expr_swap(_, sub) |
- ast::expr_log(_, _, sub) | ast::expr_assert(sub) {
+ ast::expr_log(_, _, sub) | ast::expr_assert(sub) => {
ends_in_lit_int(sub)
}
- ast::expr_fail(osub) | ast::expr_ret(osub) {
- alt osub {
- some(ex) { ends_in_lit_int(ex) }
- _ { false }
- }
+ ast::expr_fail(osub) | ast::expr_ret(osub) => alt osub {
+ some(ex) => ends_in_lit_int(ex),
+ _ => false
}
- _ { false }
+ _ => false
}
}
fn parse_ident() -> ast::ident {
alt copy self.token {
- token::IDENT(i, _) { self.bump(); return self.get_str(i); }
- token::INTERPOLATED(token::nt_ident(*)) { self.bug(
+ token::IDENT(i, _) => { self.bump(); return self.get_str(i); }
+ token::INTERPOLATED(token::nt_ident(*)) => { self.bug(
~"ident interpolation not converted to real token"); }
- _ { self.fatal(~"expected ident, found `"
+ _ => { self.fatal(~"expected ident, found `"
+ token_to_str(self.reader, self.token)
+ ~"`"); }
}
fn is_any_keyword(tok: token::token) -> bool {
alt tok {
- token::IDENT(sid, false) {
+ token::IDENT(sid, false) => {
self.keywords.contains_key_ref(self.get_str(sid))
}
- _ { false }
+ _ => false
}
}
let mut bump = false;
let val = alt self.token {
- token::IDENT(sid, false) {
+ token::IDENT(sid, false) => {
if word == *self.get_str(sid) {
bump = true;
true
} else { false }
}
- _ { false }
+ _ => false
};
if bump { self.bump() }
val
fn check_restricted_keywords() {
alt self.token {
- token::IDENT(_, false) {
+ token::IDENT(_, false) => {
let w = token_to_str(self.reader, self.token);
self.check_restricted_keywords_(w);
}
- _ { }
+ _ => ()
}
}
while self.token != token::GT
&& self.token != token::BINOP(token::SHR) {
alt sep {
- some(t) { if first { first = false; }
- else { self.expect(t); } }
- _ { }
+ some(t) => {
+ if first { first = false; }
+ else { self.expect(t); }
+ }
+ _ => ()
}
vec::push(v, f(self));
}
let mut v: ~[T] = ~[];
while self.token != ket {
alt sep.sep {
- some(t) { if first { first = false; }
- else { self.expect(t); } }
- _ { }
+ some(t) => {
+ if first { first = false; }
+ else { self.expect(t); }
+ }
+ _ => ()
}
if sep.trailing_sep_allowed && self.token == ket { break; }
vec::push(v, f(self));
fn companion_file(+prefix: ~str, suffix: option<~str>) -> ~str {
return alt suffix {
- option::some(s) { path::connect(prefix, s) }
- option::none { prefix }
+ option::some(s) => path::connect(prefix, s),
+ option::none => prefix
} + ~".rs";
}
// Crude, but there's no lib function for this and I'm not
// up to writing it just now
alt io::file_reader(path) {
- result::ok(_) { true }
- result::err(_) { false }
+ result::ok(_) => true,
+ result::err(_) => false
}
}
fn cdir_path_opt(id: ast::ident, attrs: ~[ast::attribute]) -> @~str {
alt ::attr::first_attr_value_str_by_name(attrs, ~"path") {
- some(d) {
- return d;
- }
- none { return id; }
+ some(d) => return d,
+ none => return id
}
}
&view_items: ~[@ast::view_item],
&items: ~[@ast::item]) {
alt cdir.node {
- ast::cdir_src_mod(id, attrs) {
+ ast::cdir_src_mod(id, attrs) => {
let file_path = cdir_path_opt(@(*id + ~".rs"), attrs);
let full_path =
if path::path_is_absolute(*file_path) {
cx.sess.byte_pos = cx.sess.byte_pos + r0.pos;
vec::push(items, i);
}
- ast::cdir_dir_mod(id, cdirs, attrs) {
+ ast::cdir_dir_mod(id, cdirs, attrs) => {
let path = cdir_path_opt(id, attrs);
let full_path =
if path::path_is_absolute(*path) {
cx.sess.next_id += 1;
vec::push(items, i);
}
- ast::cdir_view_item(vi) { vec::push(view_items, vi); }
- ast::cdir_syntax(pth) { }
+ ast::cdir_view_item(vi) => vec::push(view_items, vi),
+ ast::cdir_syntax(pth) => ()
}
}
//
-> option<{tok: token::token, sp: span}> {
if rdr.curr == '/' {
alt nextch(rdr) {
- '/' {
+ '/' => {
bump(rdr);
bump(rdr);
// line comments starting with "///" or "//!" are doc-comments
return consume_whitespace_and_comments(rdr);
}
}
- '*' { bump(rdr); bump(rdr); return consume_block_comment(rdr); }
- _ {}
+ '*' => { bump(rdr); bump(rdr); return consume_block_comment(rdr); }
+ _ => ()
}
} else if rdr.curr == '#' {
if nextch(rdr) == '!' {
let c = rdr.curr;
if c == '_' { bump(rdr); again; }
alt char::to_digit(c, radix) {
- some(d) {
+ some(d) => {
str::push_char(rslt, c);
bump(rdr);
}
- _ { return rslt; }
+ _ => return rslt
}
};
}
}
let parsed = option::get(u64::from_str_radix(num_str, base as u64));
alt tp {
- either::left(t) { return token::LIT_INT(parsed as i64, t); }
- either::right(t) { return token::LIT_UINT(parsed, t); }
+ either::left(t) => return token::LIT_INT(parsed as i64, t),
+ either::right(t) => return token::LIT_UINT(parsed, t)
}
}
let mut is_float = false;
num_str += ~"." + dec_part;
}
alt scan_exponent(rdr) {
- some(s) {
+ some(s) => {
is_float = true;
num_str += s;
}
- none {}
+ none => ()
}
if rdr.curr == 'f' {
bump(rdr);
// One-byte tokens.
- ';' { bump(rdr); return token::SEMI; }
- ',' { bump(rdr); return token::COMMA; }
- '.' {
+ ';' => { bump(rdr); return token::SEMI; }
+ ',' => { bump(rdr); return token::COMMA; }
+ '.' => {
bump(rdr);
if rdr.curr == '.' && nextch(rdr) != '.' {
bump(rdr);
}
return token::DOT;
}
- '(' { bump(rdr); return token::LPAREN; }
- ')' { bump(rdr); return token::RPAREN; }
- '{' { bump(rdr); return token::LBRACE; }
- '}' { bump(rdr); return token::RBRACE; }
- '[' { bump(rdr); return token::LBRACKET; }
- ']' { bump(rdr); return token::RBRACKET; }
- '@' { bump(rdr); return token::AT; }
- '#' { bump(rdr); return token::POUND; }
- '~' { bump(rdr); return token::TILDE; }
- ':' {
+ '(' => { bump(rdr); return token::LPAREN; }
+ ')' => { bump(rdr); return token::RPAREN; }
+ '{' => { bump(rdr); return token::LBRACE; }
+ '}' => { bump(rdr); return token::RBRACE; }
+ '[' => { bump(rdr); return token::LBRACKET; }
+ ']' => { bump(rdr); return token::RBRACKET; }
+ '@' => { bump(rdr); return token::AT; }
+ '#' => { bump(rdr); return token::POUND; }
+ '~' => { bump(rdr); return token::TILDE; }
+ ':' => {
bump(rdr);
if rdr.curr == ':' {
bump(rdr);
} else { return token::COLON; }
}
- '$' { bump(rdr); return token::DOLLAR; }
+ '$' => { bump(rdr); return token::DOLLAR; }
// Multi-byte tokens.
- '=' {
+ '=' => {
bump(rdr);
if rdr.curr == '=' {
bump(rdr);
return token::EQ;
}
}
- '!' {
+ '!' => {
bump(rdr);
if rdr.curr == '=' {
bump(rdr);
return token::NE;
} else { return token::NOT; }
}
- '<' {
+ '<' => {
bump(rdr);
alt rdr.curr {
- '=' { bump(rdr); return token::LE; }
- '<' { return binop(rdr, token::SHL); }
- '-' {
+ '=' => { bump(rdr); return token::LE; }
+ '<' => { return binop(rdr, token::SHL); }
+ '-' => {
bump(rdr);
alt rdr.curr {
- '>' { bump(rdr); return token::DARROW; }
- _ { return token::LARROW; }
+ '>' => { bump(rdr); return token::DARROW; }
+ _ => { return token::LARROW; }
}
}
- _ { return token::LT; }
+ _ => { return token::LT; }
}
}
- '>' {
+ '>' => {
bump(rdr);
alt rdr.curr {
- '=' { bump(rdr); return token::GE; }
- '>' { return binop(rdr, token::SHR); }
- _ { return token::GT; }
+ '=' => { bump(rdr); return token::GE; }
+ '>' => { return binop(rdr, token::SHR); }
+ _ => { return token::GT; }
}
}
- '\'' {
+ '\'' => {
bump(rdr);
let mut c2 = rdr.curr;
bump(rdr);
let escaped = rdr.curr;
bump(rdr);
alt escaped {
- 'n' { c2 = '\n'; }
- 'r' { c2 = '\r'; }
- 't' { c2 = '\t'; }
- '\\' { c2 = '\\'; }
- '\'' { c2 = '\''; }
- '"' { c2 = '"'; }
- 'x' { c2 = scan_numeric_escape(rdr, 2u); }
- 'u' { c2 = scan_numeric_escape(rdr, 4u); }
- 'U' { c2 = scan_numeric_escape(rdr, 8u); }
- c2 {
+ 'n' => { c2 = '\n'; }
+ 'r' => { c2 = '\r'; }
+ 't' => { c2 = '\t'; }
+ '\\' => { c2 = '\\'; }
+ '\'' => { c2 = '\''; }
+ '"' => { c2 = '"'; }
+ 'x' => { c2 = scan_numeric_escape(rdr, 2u); }
+ 'u' => { c2 = scan_numeric_escape(rdr, 4u); }
+ 'U' => { c2 = scan_numeric_escape(rdr, 8u); }
+ c2 => {
rdr.fatal(fmt!{"unknown character escape: %d", c2 as int});
}
}
bump(rdr); // advance curr past token
return token::LIT_INT(c2 as i64, ast::ty_char);
}
- '"' {
+ '"' => {
let n = rdr.chpos;
bump(rdr);
while rdr.curr != '"' {
let ch = rdr.curr;
bump(rdr);
alt ch {
- '\\' {
+ '\\' => {
let escaped = rdr.curr;
bump(rdr);
alt escaped {
- 'n' { str::push_char(accum_str, '\n'); }
- 'r' { str::push_char(accum_str, '\r'); }
- 't' { str::push_char(accum_str, '\t'); }
- '\\' { str::push_char(accum_str, '\\'); }
- '\'' { str::push_char(accum_str, '\''); }
- '"' { str::push_char(accum_str, '"'); }
- '\n' { consume_whitespace(rdr); }
- 'x' {
+ 'n' => str::push_char(accum_str, '\n'),
+ 'r' => str::push_char(accum_str, '\r'),
+ 't' => str::push_char(accum_str, '\t'),
+ '\\' => str::push_char(accum_str, '\\'),
+ '\'' => str::push_char(accum_str, '\''),
+ '"' => str::push_char(accum_str, '"'),
+ '\n' => consume_whitespace(rdr),
+ 'x' => {
str::push_char(accum_str, scan_numeric_escape(rdr, 2u));
}
- 'u' {
+ 'u' => {
str::push_char(accum_str, scan_numeric_escape(rdr, 4u));
}
- 'U' {
+ 'U' => {
str::push_char(accum_str, scan_numeric_escape(rdr, 8u));
}
- c2 {
+ c2 => {
rdr.fatal(fmt!{"unknown string escape: %d", c2 as int});
}
}
}
- _ { str::push_char(accum_str, ch); }
+ _ => str::push_char(accum_str, ch)
}
}
bump(rdr);
return token::LIT_STR((*rdr.interner).intern(@accum_str));
}
- '-' {
+ '-' => {
if nextch(rdr) == '>' {
bump(rdr);
bump(rdr);
return token::RARROW;
} else { return binop(rdr, token::MINUS); }
}
- '&' {
+ '&' => {
if nextch(rdr) == '&' {
bump(rdr);
bump(rdr);
return token::ANDAND;
} else { return binop(rdr, token::AND); }
}
- '|' {
+ '|' => {
alt nextch(rdr) {
- '|' { bump(rdr); bump(rdr); return token::OROR; }
- _ { return binop(rdr, token::OR); }
+ '|' => { bump(rdr); bump(rdr); return token::OROR; }
+ _ => { return binop(rdr, token::OR); }
}
}
- '+' { return binop(rdr, token::PLUS); }
- '*' { return binop(rdr, token::STAR); }
- '/' { return binop(rdr, token::SLASH); }
- '^' { return binop(rdr, token::CARET); }
- '%' { return binop(rdr, token::PERCENT); }
- c { rdr.fatal(fmt!{"unknown start of token: %d", c as int}); }
+ '+' => { return binop(rdr, token::PLUS); }
+ '*' => { return binop(rdr, token::STAR); }
+ '/' => { return binop(rdr, token::SLASH); }
+ '^' => { return binop(rdr, token::CARET); }
+ '%' => { return binop(rdr, token::PERCENT); }
+ c => { rdr.fatal(fmt!{"unknown start of token: %d", c as int}); }
}
}
at INTERPOLATED tokens */
macro_rules! maybe_whole_expr {
{$p:expr} => { alt copy $p.token {
- INTERPOLATED(token::nt_expr(e)) {
+ INTERPOLATED(token::nt_expr(e)) => {
$p.bump();
return pexpr(e);
}
- INTERPOLATED(token::nt_path(pt)) {
+ INTERPOLATED(token::nt_path(pt)) => {
$p.bump();
return $p.mk_pexpr($p.span.lo, $p.span.lo,
expr_path(pt));
}
- _ {}
+ _ => ()
}}
}
macro_rules! maybe_whole {
{$p:expr, $constructor:ident} => { alt copy $p.token {
- INTERPOLATED(token::$constructor(x)) { $p.bump(); return x; }
- _ {}
+ INTERPOLATED(token::$constructor(x)) => { $p.bump(); return x; }
+ _ => ()
}} ;
{deref $p:expr, $constructor:ident} => { alt copy $p.token {
- INTERPOLATED(token::$constructor(x)) { $p.bump(); return *x; }
- _ {}
+ INTERPOLATED(token::$constructor(x)) => { $p.bump(); return *x; }
+ _ => ()
}} ;
{some $p:expr, $constructor:ident} => { alt copy $p.token {
- INTERPOLATED(token::$constructor(x)) { $p.bump(); return some(x); }
- _ {}
+ INTERPOLATED(token::$constructor(x)) => { $p.bump(); return some(x); }
+ _ => ()
}} ;
{pair_empty $p:expr, $constructor:ident} => { alt copy $p.token {
- INTERPOLATED(token::$constructor(x)) { $p.bump(); return (~[], x); }
- _ {}
+ INTERPOLATED(token::$constructor(x)) => { $p.bump(); return (~[], x); }
+ _ => ()
}}
}
`%s`",
token_to_str(p.reader, p.token)};
alt p.token {
- token::SEMI {
+ token::SEMI => {
p.bump();
debug!{"parse_trait_methods(): parsing required method"};
// NB: at the moment, visibility annotations on required
self_ty: self_ty,
id: p.get_id(), span: mk_sp(lo, hi)})
}
- token::LBRACE {
+ token::LBRACE => {
debug!{"parse_trait_methods(): parsing provided method"};
let (inner_attrs, body) =
p.parse_inner_attrs_and_block(true);
vis: vis})
}
- _ { p.fatal(~"expected `;` or `}` but found `" +
+ _ => { p.fatal(~"expected `;` or `}` but found `" +
token_to_str(p.reader, p.token) + ~"`");
}
}
fn region_from_name(s: option<@~str>) -> @region {
let r = alt s {
- some (string) { re_named(string) }
- none { re_anon }
+ some (string) => re_named(string),
+ none => re_anon
};
@{id: self.get_id(), node: r}
self.expect(token::BINOP(token::AND));
alt copy self.token {
- token::IDENT(sid, _) {
+ token::IDENT(sid, _) => {
self.bump();
let n = self.get_str(sid);
self.region_from_name(some(n))
}
- _ {
+ _ => {
self.region_from_name(none)
}
}
let lo = self.span.lo;
alt self.maybe_parse_dollar_mac() {
- some(e) {
+ some(e) => {
return @{id: self.get_id(),
node: ty_mac(spanned(lo, self.span.hi, e)),
span: mk_sp(lo, self.span.hi)};
}
- none {}
+ none => ()
}
let t = if self.token == token::LPAREN {
return @{id: self.get_id(),
node: alt self.maybe_parse_fixed_vstore() {
// Consider a fixed vstore suffix (/N or /_)
- none { t }
- some(v) {
+ none => t,
+ some(v) => {
ty_fixed_length(@{id: self.get_id(), node:t, span: sp}, v)
} },
span: sp}
fn maybe_parse_dollar_mac() -> option<mac_> {
alt copy self.token {
- token::DOLLAR {
+ token::DOLLAR => {
let lo = self.span.lo;
self.bump();
alt copy self.token {
- token::LIT_INT_UNSUFFIXED(num) {
+ token::LIT_INT_UNSUFFIXED(num) => {
self.bump();
some(mac_var(num as uint))
}
- token::LPAREN {
+ token::LPAREN => {
self.bump();
let e = self.parse_expr();
self.expect(token::RPAREN);
let hi = self.last_span.hi;
some(mac_aq(mk_sp(lo,hi), e))
}
- _ {
+ _ => {
self.fatal(~"expected `(` or unsuffixed integer literal");
}
}
}
- _ {none}
+ _ => none
}
}
if self.token == token::BINOP(token::SLASH) {
self.bump();
alt copy self.token {
- token::UNDERSCORE {
+ token::UNDERSCORE => {
self.bump(); some(none)
}
- token::LIT_INT_UNSUFFIXED(i) if i >= 0i64 {
+ token::LIT_INT_UNSUFFIXED(i) if i >= 0i64 => {
self.bump(); some(some(i as uint))
}
- _ {
- none
- }
+ _ => none
}
} else {
none
fn lit_from_token(tok: token::token) -> lit_ {
alt tok {
- token::LIT_INT(i, it) { lit_int(i, it) }
- token::LIT_UINT(u, ut) { lit_uint(u, ut) }
- token::LIT_INT_UNSUFFIXED(i) { lit_int_unsuffixed(i) }
- token::LIT_FLOAT(s, ft) { lit_float(self.get_str(s), ft) }
- token::LIT_STR(s) { lit_str(self.get_str(s)) }
- token::LPAREN { self.expect(token::RPAREN); lit_nil }
- _ { self.unexpected_last(tok); }
+ token::LIT_INT(i, it) => lit_int(i, it),
+ token::LIT_UINT(u, ut) => lit_uint(u, ut),
+ token::LIT_INT_UNSUFFIXED(i) => lit_int_unsuffixed(i),
+ token::LIT_FLOAT(s, ft) => lit_float(self.get_str(s), ft),
+ token::LIT_STR(s) => lit_str(self.get_str(s)),
+ token::LPAREN => { self.expect(token::RPAREN); lit_nil }
+ _ => self.unexpected_last(tok)
}
}
fn to_expr(e: pexpr) -> @expr {
alt e.node {
- expr_tup(es) if vec::len(es) == 1u { es[0u] }
- _ { *e }
+ expr_tup(es) if vec::len(es) == 1u => es[0u],
+ _ => *e
}
}
let mut ex: expr_;
alt self.maybe_parse_dollar_mac() {
- some(x) {return pexpr(self.mk_mac_expr(lo, self.span.hi, x));}
- _ {}
+ some(x) => return pexpr(self.mk_mac_expr(lo, self.span.hi, x)),
+ _ => ()
}
if self.token == token::LPAREN {
} else if self.eat_keyword(~"fn") {
let proto = self.parse_fn_ty_proto();
alt proto {
- proto_bare { self.fatal(~"fn expr are deprecated, use fn@"); }
- _ { /* fallthrough */ }
+ proto_bare => self.fatal(~"fn expr are deprecated, use fn@"),
+ _ => { /* fallthrough */ }
}
return pexpr(self.parse_fn_expr(proto));
} else if self.eat_keyword(~"unchecked") {
if self.token == token::NOT {
self.bump();
let tts = alt self.token {
- token::LPAREN | token::LBRACE | token::LBRACKET {
+ token::LPAREN | token::LBRACE | token::LBRACKET => {
let ket = token::flip_delimiter(self.token);
self.parse_unspanned_seq(copy self.token, ket,
seq_sep_none(),
|p| p.parse_token_tree())
}
- _ { self.fatal(~"expected open delimiter"); }
+ _ => self.fatal(~"expected open delimiter")
};
let hi = self.span.hi;
// only.
alt ex {
expr_lit(@{node: lit_str(_), span: _}) |
- expr_vec(_, _) {
- alt self.maybe_parse_fixed_vstore() {
- none { }
- some(v) {
+ expr_vec(_, _) => alt self.maybe_parse_fixed_vstore() {
+ none => (),
+ some(v) => {
hi = self.span.hi;
ex = expr_vstore(self.mk_expr(lo, hi, ex), vstore_fixed(v));
- }
}
}
- _ { }
+ _ => ()
}
return self.mk_pexpr(lo, hi, ex);
fn parse_syntax_ext_naked(lo: uint) -> @expr {
alt self.token {
- token::IDENT(_, _) {}
- _ { self.fatal(~"expected a syntax expander name"); }
+ token::IDENT(_, _) => (),
+ _ => self.fatal(~"expected a syntax expander name")
}
let pth = self.parse_path_without_tps();
//temporary for a backwards-compatible cycle:
let mut depth = 1u;
while (depth > 0u) {
alt (self.token) {
- token::LBRACE {depth += 1u;}
- token::RBRACE {depth -= 1u;}
- token::EOF {self.fatal(~"unexpected EOF in macro body");}
- _ {}
+ token::LBRACE => depth += 1u,
+ token::RBRACE => depth -= 1u,
+ token::EOF => self.fatal(~"unexpected EOF in macro body"),
+ _ => ()
}
self.bump();
}
// expr.f
if self.eat(token::DOT) {
alt copy self.token {
- token::IDENT(i, _) {
+ token::IDENT(i, _) => {
hi = self.span.hi;
self.bump();
let tys = if self.eat(token::MOD_SEP) {
self.get_str(i),
tys));
}
- _ { self.unexpected(); }
+ _ => self.unexpected()
}
again;
}
if self.expr_is_complete(e) { break; }
alt copy self.token {
// expr(...)
- token::LPAREN if self.permits_call() {
+ token::LPAREN if self.permits_call() => {
let es = self.parse_unspanned_seq(
token::LPAREN, token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
}
// expr[...]
- token::LBRACKET {
+ token::LBRACKET => {
self.bump();
let ix = self.parse_expr();
hi = ix.span.hi;
e = self.mk_pexpr(lo, hi, expr_index(self.to_expr(e), ix));
}
- _ { return e; }
+ _ => return e
}
}
return e;
fn parse_tt_tok(p: parser, delim_ok: bool) -> token_tree {
alt p.token {
token::RPAREN | token::RBRACE | token::RBRACKET
- if !delim_ok {
+ if !delim_ok => {
p.fatal(~"incorrect close delimiter: `"
+ token_to_str(p.reader, p.token) + ~"`");
}
- token::EOF {
+ token::EOF => {
p.fatal(~"file ended in the middle of a macro invocation");
}
/* we ought to allow different depths of unquotation */
- token::DOLLAR if p.quote_depth > 0u {
+ token::DOLLAR if p.quote_depth > 0u => {
p.bump();
let sp = p.span;
return tt_nonterminal(sp, p.parse_ident());
}
}
- _ { /* ok */ }
+ _ => { /* ok */ }
}
let res = tt_tok(p.span, p.token);
p.bump();
}
return alt self.token {
- token::LPAREN | token::LBRACE | token::LBRACKET {
+ token::LPAREN | token::LBRACE | token::LBRACKET => {
let ket = token::flip_delimiter(self.token);
tt_delim(vec::append(
~[parse_tt_tok(self, true)],
|p| p.parse_token_tree()),
~[parse_tt_tok(self, true)])))
}
- _ { parse_tt_tok(self, false) }
+ _ => parse_tt_tok(self, false)
};
}
maybe_whole!{self, nt_matchers};
let name_idx = @mut 0u;
return alt self.token {
- token::LBRACE | token::LPAREN | token::LBRACKET {
+ token::LBRACE | token::LPAREN | token::LBRACKET => {
self.parse_matcher_subseq(name_idx, copy self.token,
token::flip_delimiter(self.token))
}
- _ { self.fatal(~"expected open delimiter"); }
+ _ => self.fatal(~"expected open delimiter")
}
}
let mut ex;
alt copy self.token {
- token::NOT {
+ token::NOT => {
self.bump();
let e = self.to_expr(self.parse_prefix_expr());
hi = e.span.hi;
self.get_id(); // see ast_util::op_expr_callee_id
ex = expr_unary(not, e);
}
- token::BINOP(b) {
+ token::BINOP(b) => {
alt b {
- token::MINUS {
+ token::MINUS => {
self.bump();
let e = self.to_expr(self.parse_prefix_expr());
hi = e.span.hi;
self.get_id(); // see ast_util::op_expr_callee_id
ex = expr_unary(neg, e);
}
- token::STAR {
+ token::STAR => {
self.bump();
let e = self.to_expr(self.parse_prefix_expr());
hi = e.span.hi;
ex = expr_unary(deref, e);
}
- token::AND {
+ token::AND => {
self.bump();
let m = self.parse_mutability();
let e = self.to_expr(self.parse_prefix_expr());
// HACK: turn &[...] into a &-evec
ex = alt e.node {
expr_vec(*) | expr_lit(@{node: lit_str(_), span: _})
- if m == m_imm {
+ if m == m_imm => {
expr_vstore(e, vstore_slice(self.region_from_name(none)))
}
- _ { expr_addr_of(m, e) }
+ _ => expr_addr_of(m, e)
};
}
- _ { return self.parse_dot_or_call_expr(); }
+ _ => return self.parse_dot_or_call_expr()
}
}
- token::AT {
+ token::AT => {
self.bump();
let m = self.parse_mutability();
let e = self.to_expr(self.parse_prefix_expr());
// HACK: turn @[...] into a @-evec
ex = alt e.node {
expr_vec(*) | expr_lit(@{node: lit_str(_), span: _})
- if m == m_imm { expr_vstore(e, vstore_box) }
- _ { expr_unary(box(m), e) }
+ if m == m_imm => expr_vstore(e, vstore_box),
+ _ => expr_unary(box(m), e)
};
}
- token::TILDE {
+ token::TILDE => {
self.bump();
let m = self.parse_mutability();
let e = self.to_expr(self.parse_prefix_expr());
// HACK: turn ~[...] into a ~-evec
ex = alt e.node {
expr_vec(*) | expr_lit(@{node: lit_str(_), span: _})
- if m == m_imm { expr_vstore(e, vstore_uniq) }
- _ { expr_unary(uniq(m), e) }
+ if m == m_imm => expr_vstore(e, vstore_uniq),
+ _ => expr_unary(uniq(m), e)
};
}
- _ { return self.parse_dot_or_call_expr(); }
+ _ => return self.parse_dot_or_call_expr()
}
return self.mk_pexpr(lo, hi, ex);
}
}
let cur_opt = token_to_binop(peeked);
alt cur_opt {
- some(cur_op) {
+ some(cur_op) => {
let cur_prec = operator_prec(cur_op);
if cur_prec > min_prec {
self.bump();
return self.parse_more_binops(bin, min_prec);
}
}
- _ {}
+ _ => ()
}
if as_prec > min_prec && self.eat_keyword(~"as") {
let rhs = self.parse_ty(true);
let lo = self.span.lo;
let lhs = self.parse_binops();
alt copy self.token {
- token::EQ {
+ token::EQ => {
self.bump();
let rhs = self.parse_expr();
return self.mk_expr(lo, rhs.span.hi, expr_assign(lhs, rhs));
}
- token::BINOPEQ(op) {
+ token::BINOPEQ(op) => {
self.bump();
let rhs = self.parse_expr();
let mut aop;
alt op {
- token::PLUS { aop = add; }
- token::MINUS { aop = subtract; }
- token::STAR { aop = mul; }
- token::SLASH { aop = div; }
- token::PERCENT { aop = rem; }
- token::CARET { aop = bitxor; }
- token::AND { aop = bitand; }
- token::OR { aop = bitor; }
- token::SHL { aop = shl; }
- token::SHR { aop = shr; }
+ token::PLUS => aop = add,
+ token::MINUS => aop = subtract,
+ token::STAR => aop = mul,
+ token::SLASH => aop = div,
+ token::PERCENT => aop = rem,
+ token::CARET => aop = bitxor,
+ token::AND => aop = bitand,
+ token::OR => aop = bitor,
+ token::SHL => aop = shl,
+ token::SHR => aop = shr
}
self.get_id(); // see ast_util::op_expr_callee_id
return self.mk_expr(lo, rhs.span.hi,
expr_assign_op(aop, lhs, rhs));
}
- token::LARROW {
+ token::LARROW => {
self.bump();
let rhs = self.parse_expr();
return self.mk_expr(lo, rhs.span.hi, expr_move(lhs, rhs));
}
- token::DARROW {
+ token::DARROW => {
self.bump();
let rhs = self.parse_expr();
return self.mk_expr(lo, rhs.span.hi, expr_swap(lhs, rhs));
}
- _ {/* fall through */ }
+ _ => {/* fall through */ }
}
return lhs;
}
self.parse_lambda_expr_(
|| {
alt self.token {
- token::BINOP(token::OR) | token::OROR {
+ token::BINOP(token::OR) | token::OROR => {
self.parse_fn_block_decl()
}
- _ {
+ _ => {
// No argument list - `do foo {`
({
{
// them as the lambda arguments
let e = self.parse_expr_res(RESTRICT_NO_BAR_OR_DOUBLEBAR_OP);
alt e.node {
- expr_call(f, args, false) {
+ expr_call(f, args, false) => {
let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
ctor(block));
@{node: expr_call(f, args, true)
with *e}
}
- expr_path(*) | expr_field(*) | expr_call(*) {
+ expr_path(*) | expr_field(*) | expr_call(*) => {
let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
ctor(block));
self.mk_expr(lo.lo, last_arg.span.hi,
expr_call(e, ~[last_arg], true))
}
- _ {
+ _ => {
// There may be other types of expressions that can
// represent the callee in `for` and `do` expressions
// but they aren't represented by tests
fn parse_initializer() -> option<initializer> {
alt self.token {
- token::EQ {
+ token::EQ => {
self.bump();
return some({op: init_assign, expr: self.parse_expr()});
}
- token::LARROW {
+ token::LARROW => {
self.bump();
return some({op: init_move, expr: self.parse_expr()});
}
// return some(rec(op = init_recv,
// expr = self.parse_expr()));
// }
- _ {
+ _ => {
return none;
}
}
let mut hi = self.span.hi;
let mut pat;
alt self.token {
- token::UNDERSCORE { self.bump(); pat = pat_wild; }
- token::AT {
+ token::UNDERSCORE => { self.bump(); pat = pat_wild; }
+ token::AT => {
self.bump();
let sub = self.parse_pat(refutable);
hi = sub.span.hi;
// HACK: parse @"..." as a literal of a vstore @str
pat = alt sub.node {
- pat_lit(e@@{node: expr_lit(@{node: lit_str(_), span: _}), _}) {
+ pat_lit(e@@{
+ node: expr_lit(@{node: lit_str(_), span: _}), _
+ }) => {
let vst = @{id: self.get_id(), callee_id: self.get_id(),
node: expr_vstore(e, vstore_box),
span: mk_sp(lo, hi)};
pat_lit(vst)
}
- _ { pat_box(sub) }
+ _ => pat_box(sub)
};
}
- token::TILDE {
+ token::TILDE => {
self.bump();
let sub = self.parse_pat(refutable);
hi = sub.span.hi;
// HACK: parse ~"..." as a literal of a vstore ~str
pat = alt sub.node {
- pat_lit(e@@{node: expr_lit(@{node: lit_str(_), span: _}), _}) {
+ pat_lit(e@@{
+ node: expr_lit(@{node: lit_str(_), span: _}), _
+ }) => {
let vst = @{id: self.get_id(), callee_id: self.get_id(),
node: expr_vstore(e, vstore_uniq),
span: mk_sp(lo, hi)};
pat_lit(vst)
}
- _ { pat_uniq(sub) }
+ _ => pat_uniq(sub)
};
}
- token::LBRACE {
+ token::LBRACE => {
self.bump();
let mut fields = ~[];
let mut etc = false;
self.bump();
pat = pat_rec(fields, etc);
}
- token::LPAREN {
+ token::LPAREN => {
self.bump();
if self.token == token::RPAREN {
hi = self.span.hi;
pat = pat_tup(fields);
}
}
- tok {
+ tok => {
if !is_ident(tok) ||
self.is_keyword(~"true") || self.is_keyword(~"false") {
let val = self.parse_expr_res(RESTRICT_NO_BAR_OP);
let mut args: ~[@pat] = ~[];
let mut star_pat = false;
alt self.token {
- token::LPAREN {
- alt self.look_ahead(1u) {
- token::BINOP(token::STAR) {
+ token::LPAREN => alt self.look_ahead(1u) {
+ token::BINOP(token::STAR) => {
// This is a "top constructor only" pat
- self.bump(); self.bump();
- star_pat = true;
- self.expect(token::RPAREN);
+ self.bump(); self.bump();
+ star_pat = true;
+ self.expect(token::RPAREN);
}
- _ {
+ _ => {
args = self.parse_unspanned_seq(
token::LPAREN, token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
|p| p.parse_pat(refutable));
- hi = self.span.hi;
+ hi = self.span.hi;
}
- }
}
- _ { }
+ _ => ()
}
// at this point, we're not sure whether it's a enum or a
// bind
} else {
let mut item_attrs;
alt self.parse_outer_attrs_or_ext(first_item_attrs) {
- none { item_attrs = ~[]; }
- some(left(attrs)) { item_attrs = attrs; }
- some(right(ext)) {
+ none => item_attrs = ~[],
+ some(left(attrs)) => item_attrs = attrs,
+ some(right(ext)) => {
return @spanned(lo, ext.span.hi,
stmt_expr(ext, self.get_id()));
}
let item_attrs = vec::append(first_item_attrs, item_attrs);
alt self.parse_item(item_attrs) {
- some(i) {
+ some(i) => {
let mut hi = i.span.hi;
let decl = @spanned(lo, hi, decl_item(i));
return @spanned(lo, hi, stmt_decl(decl, self.get_id()));
}
- none() { /* fallthrough */ }
+ none() => { /* fallthrough */ }
}
check_expected_item(self, item_attrs);
while self.token != token::RBRACE {
alt self.token {
- token::SEMI {
+ token::SEMI => {
self.bump(); // empty
}
- _ {
+ _ => {
let stmt = self.parse_stmt(initial_attrs);
initial_attrs = ~[];
alt stmt.node {
- stmt_expr(e, stmt_id) { // Expression without semicolon:
+ stmt_expr(e, stmt_id) => { // Expression without semicolon:
alt self.token {
- token::SEMI {
+ token::SEMI => {
self.bump();
push(stmts,
@{node: stmt_semi(e, stmt_id) with *stmt});
}
- token::RBRACE {
+ token::RBRACE => {
expr = some(e);
}
- t {
+ t => {
if classify::stmt_ends_with_semi(*stmt) {
self.fatal(~"expected `;` or `}` after \
expression but found `"
}
}
- _ { // All other kinds of statements:
+ _ => { // All other kinds of statements:
vec::push(stmts, stmt);
if classify::stmt_ends_with_semi(*stmt) {
fn is_self_ident() -> bool {
alt self.token {
- token::IDENT(sid, false) if ~"self" == *self.get_str(sid) {
- true
- }
- _ => {
- false
- }
+ token::IDENT(sid, false) if ~"self" == *self.get_str(sid) => true,
+ _ => false
}
}
fn parse_method_name() -> ident {
alt copy self.token {
- token::BINOP(op) { self.bump(); @token::binop_to_str(op) }
- token::NOT { self.bump(); @~"!" }
- token::LBRACKET {
+ token::BINOP(op) => { self.bump(); @token::binop_to_str(op) }
+ token::NOT => { self.bump(); @~"!" }
+ token::LBRACKET => {
self.bump();
self.expect(token::RBRACKET);
@~"[]"
}
- _ {
+ _ => {
let id = self.parse_value_ident();
if id == @~"unary" && self.eat(token::BINOP(token::MINUS)) {
@~"unary-"
traits = ~[];
};
ident = alt ident_old {
- some(name) { name }
- none { self.expect_keyword(~"of"); fail; }
+ some(name) => name,
+ none => { self.expect_keyword(~"of"); fail; }
};
self.expect_keyword(~"for");
ty = self.parse_ty(false);
let mut the_dtor : option<(blk, ~[attribute], codemap::span)> = none;
while self.token != token::RBRACE {
alt self.parse_class_item(class_path) {
- ctor_decl(a_fn_decl, attrs, blk, s) {
+ ctor_decl(a_fn_decl, attrs, blk, s) => {
the_ctor = some((a_fn_decl, attrs, blk, s));
}
- dtor_decl(blk, attrs, s) {
+ dtor_decl(blk, attrs, s) => {
the_dtor = some((blk, attrs, s));
}
- members(mms) { ms = vec::append(ms, mms); }
+ members(mms) => { ms = vec::append(ms, mms); }
}
}
let actual_dtor = do option::map(the_dtor) |dtor| {
span: d_s}};
self.bump();
alt the_ctor {
- some((ct_d, ct_attrs, ct_b, ct_s)) {
+ some((ct_d, ct_attrs, ct_b, ct_s)) => {
(class_name,
item_class(ty_params, traits, ms, some({
node: {id: ctor_id,
/*
Is it strange for the parser to check this?
*/
- none {
+ none => {
(class_name,
item_class(ty_params, traits, ms, none, actual_dtor),
none)
fn token_is_pound_or_doc_comment(++tok: token::token) -> bool {
alt tok {
- token::POUND | token::DOC_COMMENT(_) { true }
- _ { false }
+ token::POUND | token::DOC_COMMENT(_) => true,
+ _ => false
}
}
}
debug!{"parse_mod_items: parse_item(attrs=%?)", attrs};
alt self.parse_item(attrs) {
- some(i) { vec::push(items, i); }
- _ {
+ some(i) => vec::push(items, i),
+ _ => {
self.fatal(~"expected item but found `" +
token_to_str(self.reader, self.token) + ~"`");
}
fn parse_fn_ty_proto() -> proto {
alt self.token {
- token::AT {
+ token::AT => {
self.bump();
proto_box
}
- token::TILDE {
+ token::TILDE => {
self.bump();
proto_uniq
}
- token::BINOP(token::AND) {
+ token::BINOP(token::AND) => {
self.bump();
proto_block
}
- _ {
+ _ => {
proto_block
}
}
fn fn_expr_lookahead(tok: token::token) -> bool {
alt tok {
- token::LPAREN | token::AT | token::TILDE | token::BINOP(_) {
- true
- }
- _ {
- false
- }
+ token::LPAREN | token::AT | token::TILDE | token::BINOP(_) => true,
+ _ => false
}
}
self.expect(token::NOT);
let id = self.parse_ident();
let tts = alt self.token {
- token::LPAREN | token::LBRACE | token::LBRACKET {
+ token::LPAREN | token::LBRACE | token::LBRACKET => {
let ket = token::flip_delimiter(self.token);
self.parse_unspanned_seq(copy self.token, ket,
seq_sep_none(),
|p| p.parse_token_tree())
}
- _ { self.fatal(~"expected open delimiter"); }
+ _ => self.fatal(~"expected open delimiter")
};
let m = ast::mac_invoc_tt(pth, tts);
let m: ast::mac = {node: m,
} else { return none; };
some(self.mk_item(lo, self.last_span.hi, ident, item_, visibility,
alt extra_attrs {
- some(as) { vec::append(attrs, as) }
- none { attrs }
+ some(as) => vec::append(attrs, as),
+ none => attrs
}))
}
let mut path = ~[first_ident];
debug!{"parsed view_path: %s", *first_ident};
alt self.token {
- token::EQ {
+ token::EQ => {
// x = foo::bar
self.bump();
path = ~[self.parse_ident()];
view_path_simple(first_ident, path, self.get_id()));
}
- token::MOD_SEP {
+ token::MOD_SEP => {
// foo::bar or foo::{a,b,c} or foo::*
while self.token == token::MOD_SEP {
self.bump();
alt copy self.token {
- token::IDENT(i, _) {
+ token::IDENT(i, _) => {
self.bump();
vec::push(path, self.get_str(i));
}
// foo::bar::{a,b,c}
- token::LBRACE {
+ token::LBRACE => {
let idents = self.parse_unspanned_seq(
token::LBRACE, token::RBRACE,
seq_sep_trailing_allowed(token::COMMA),
}
// foo::bar::*
- token::BINOP(token::STAR) {
+ token::BINOP(token::STAR) => {
self.bump();
let path = @{span: mk_sp(lo, self.span.hi),
global: false, idents: path,
view_path_glob(path, self.get_id()));
}
- _ { break; }
+ _ => break
}
}
}
- _ { }
+ _ => ()
}
let last = path[vec::len(path) - 1u];
let path = @{span: mk_sp(lo, self.span.hi), global: false,
fn parse_str() -> @~str {
alt copy self.token {
- token::LIT_STR(s) { self.bump(); self.get_str(s) }
- _ {
- self.fatal(~"expected string literal")
- }
+ token::LIT_STR(s) => { self.bump(); self.get_str(s) }
+ _ => self.fatal(~"expected string literal")
}
}
let id = self.parse_ident();
alt self.token {
// mod x = "foo.rs";
- token::SEMI {
+ token::SEMI => {
let mut hi = self.span.hi;
self.bump();
return spanned(lo, hi, cdir_src_mod(id, outer_attrs));
}
// mod x = "foo_dir" { ...directives... }
- token::LBRACE {
+ token::LBRACE => {
self.bump();
let inner_attrs = self.parse_inner_attrs_and_next();
let mod_attrs = vec::append(outer_attrs, inner_attrs.inner);
return spanned(lo, hi,
cdir_dir_mod(id, cdirs, mod_attrs));
}
- _ { self.unexpected(); }
+ _ => self.unexpected()
}
} else if self.is_view_item() {
let vi = self.parse_view_item(outer_attrs);
*/
fn token_to_binop(tok: token) -> option<ast::binop> {
alt tok {
- BINOP(STAR) { some(mul) }
- BINOP(SLASH) { some(div) }
- BINOP(PERCENT) { some(rem) }
+ BINOP(STAR) => some(mul),
+ BINOP(SLASH) => some(div),
+ BINOP(PERCENT) => some(rem),
// 'as' sits between here with 11
- BINOP(PLUS) { some(add) }
- BINOP(MINUS) { some(subtract) }
- BINOP(SHL) { some(shl) }
- BINOP(SHR) { some(shr) }
- BINOP(AND) { some(bitand) }
- BINOP(CARET) { some(bitxor) }
- BINOP(OR) { some(bitor) }
- LT { some(lt) }
- LE { some(le) }
- GE { some(ge) }
- GT { some(gt) }
- EQEQ { some(eq) }
- NE { some(ne) }
- ANDAND { some(and) }
- OROR { some(or) }
- _ { none }
+ BINOP(PLUS) => some(add),
+ BINOP(MINUS) => some(subtract),
+ BINOP(SHL) => some(shl),
+ BINOP(SHR) => some(shr),
+ BINOP(AND) => some(bitand),
+ BINOP(CARET) => some(bitxor),
+ BINOP(OR) => some(bitor),
+ LT => some(lt),
+ LE => some(le),
+ GE => some(ge),
+ GT => some(gt),
+ EQEQ => some(eq),
+ NE => some(ne),
+ ANDAND => some(and),
+ OROR => some(or),
+ _ => none
}
}
fn binop_to_str(o: binop) -> ~str {
alt o {
- PLUS { ~"+" }
- MINUS { ~"-" }
- STAR { ~"*" }
- SLASH { ~"/" }
- PERCENT { ~"%" }
- CARET { ~"^" }
- AND { ~"&" }
- OR { ~"|" }
- SHL { ~"<<" }
- SHR { ~">>" }
+ PLUS => ~"+",
+ MINUS => ~"-",
+ STAR => ~"*",
+ SLASH => ~"/",
+ PERCENT => ~"%",
+ CARET => ~"^",
+ AND => ~"&",
+ OR => ~"|",
+ SHL => ~"<<",
+ SHR => ~">>"
}
}
fn to_str(in: interner<@~str>, t: token) -> ~str {
alt t {
- EQ { ~"=" }
- LT { ~"<" }
- LE { ~"<=" }
- EQEQ { ~"==" }
- NE { ~"!=" }
- GE { ~">=" }
- GT { ~">" }
- NOT { ~"!" }
- TILDE { ~"~" }
- OROR { ~"||" }
- ANDAND { ~"&&" }
- BINOP(op) { binop_to_str(op) }
- BINOPEQ(op) { binop_to_str(op) + ~"=" }
+ EQ => ~"=",
+ LT => ~"<",
+ LE => ~"<=",
+ EQEQ => ~"==",
+ NE => ~"!=",
+ GE => ~">=",
+ GT => ~">",
+ NOT => ~"!",
+ TILDE => ~"~",
+ OROR => ~"||",
+ ANDAND => ~"&&",
+ BINOP(op) => binop_to_str(op),
+ BINOPEQ(op) => binop_to_str(op) + ~"=",
/* Structural symbols */
- AT { ~"@" }
- DOT { ~"." }
- DOTDOT { ~".." }
- ELLIPSIS { ~"..." }
- COMMA { ~"," }
- SEMI { ~";" }
- COLON { ~":" }
- MOD_SEP { ~"::" }
- RARROW { ~"->" }
- LARROW { ~"<-" }
- DARROW { ~"<->" }
- FAT_ARROW { ~"=>" }
- LPAREN { ~"(" }
- RPAREN { ~")" }
- LBRACKET { ~"[" }
- RBRACKET { ~"]" }
- LBRACE { ~"{" }
- RBRACE { ~"}" }
- POUND { ~"#" }
- DOLLAR { ~"$" }
+ AT => ~"@",
+ DOT => ~".",
+ DOTDOT => ~"..",
+ ELLIPSIS => ~"...",
+ COMMA => ~",",
+ SEMI => ~";",
+ COLON => ~":",
+ MOD_SEP => ~"::",
+ RARROW => ~"->",
+ LARROW => ~"<-",
+ DARROW => ~"<->",
+ FAT_ARROW => ~"=>",
+ LPAREN => ~"(",
+ RPAREN => ~")",
+ LBRACKET => ~"[",
+ RBRACKET => ~"]",
+ LBRACE => ~"{",
+ RBRACE => ~"}",
+ POUND => ~"#",
+ DOLLAR => ~"$",
/* Literals */
- LIT_INT(c, ast::ty_char) {
+ LIT_INT(c, ast::ty_char) => {
~"'" + char::escape_default(c as char) + ~"'"
}
- LIT_INT(i, t) {
+ LIT_INT(i, t) => {
int::to_str(i as int, 10u) + ast_util::int_ty_to_str(t)
}
- LIT_UINT(u, t) {
+ LIT_UINT(u, t) => {
uint::to_str(u as uint, 10u) + ast_util::uint_ty_to_str(t)
}
- LIT_INT_UNSUFFIXED(i) {
+ LIT_INT_UNSUFFIXED(i) => {
int::to_str(i as int, 10u)
}
- LIT_FLOAT(s, t) {
+ LIT_FLOAT(s, t) => {
let mut body = *in.get(s);
if body.ends_with(~".") {
body = body + ~"0"; // `10.f` is not a float literal
}
body + ast_util::float_ty_to_str(t)
}
- LIT_STR(s) { ~"\"" + str::escape_default( *in.get(s)) + ~"\"" }
+ LIT_STR(s) => { ~"\"" + str::escape_default( *in.get(s)) + ~"\"" }
/* Name components */
- IDENT(s, _) { *in.get(s) }
+ IDENT(s, _) => *in.get(s),
- UNDERSCORE { ~"_" }
+ UNDERSCORE => ~"_",
/* Other */
- DOC_COMMENT(s) { *in.get(s) }
- EOF { ~"<eof>" }
- INTERPOLATED(nt) {
+ DOC_COMMENT(s) => *in.get(s),
+ EOF => ~"<eof>",
+ INTERPOLATED(nt) => {
~"an interpolated " +
alt nt {
- nt_item(*) { ~"item" } nt_block(*) { ~"block" }
- nt_stmt(*) { ~"statement" } nt_pat(*) { ~"pattern" }
- nt_expr(*) { ~"expression" } nt_ty(*) { ~"type" }
- nt_ident(*) { ~"identifier" } nt_path(*) { ~"path" }
- nt_tt(*) { ~"tt" } nt_matchers(*) { ~"matcher sequence" }
+ nt_item(*) => ~"item",
+ nt_block(*) => ~"block",
+ nt_stmt(*) => ~"statement",
+ nt_pat(*) => ~"pattern",
+ nt_expr(*) => ~"expression",
+ nt_ty(*) => ~"type",
+ nt_ident(*) => ~"identifier",
+ nt_path(*) => ~"path",
+ nt_tt(*) => ~"tt",
+ nt_matchers(*) => ~"matcher sequence"
}
}
}
pure fn can_begin_expr(t: token) -> bool {
alt t {
- LPAREN { true }
- LBRACE { true }
- LBRACKET { true }
- IDENT(_, _) { true }
- UNDERSCORE { true }
- TILDE { true }
- LIT_INT(_, _) { true }
- LIT_UINT(_, _) { true }
- LIT_INT_UNSUFFIXED(_) { true }
- LIT_FLOAT(_, _) { true }
- LIT_STR(_) { true }
- POUND { true }
- AT { true }
- NOT { true }
- BINOP(MINUS) { true }
- BINOP(STAR) { true }
- BINOP(AND) { true }
- BINOP(OR) { true } // in lambda syntax
- OROR { true } // in lambda syntax
- MOD_SEP { true }
+ LPAREN => true,
+ LBRACE => true,
+ LBRACKET => true,
+ IDENT(_, _) => true,
+ UNDERSCORE => true,
+ TILDE => true,
+ LIT_INT(_, _) => true,
+ LIT_UINT(_, _) => true,
+ LIT_INT_UNSUFFIXED(_) => true,
+ LIT_FLOAT(_, _) => true,
+ LIT_STR(_) => true,
+ POUND => true,
+ AT => true,
+ NOT => true,
+ BINOP(MINUS) => true,
+ BINOP(STAR) => true,
+ BINOP(AND) => true,
+ BINOP(OR) => true, // in lambda syntax
+ OROR => true, // in lambda syntax
+ MOD_SEP => true,
INTERPOLATED(nt_expr(*))
| INTERPOLATED(nt_ident(*))
| INTERPOLATED(nt_block(*))
- | INTERPOLATED(nt_path(*)) { true }
- _ { false }
+ | INTERPOLATED(nt_path(*)) => true,
+ _ => false
}
}
/// what's the opposite delimiter?
fn flip_delimiter(&t: token::token) -> token::token {
alt t {
- token::LPAREN { token::RPAREN }
- token::LBRACE { token::RBRACE }
- token::LBRACKET { token::RBRACKET }
- token::RPAREN { token::LPAREN }
- token::RBRACE { token::LBRACE }
- token::RBRACKET { token::LBRACKET }
- _ { fail }
+ token::LPAREN => token::RPAREN,
+ token::LBRACE => token::RBRACE,
+ token::LBRACKET => token::RBRACKET,
+ token::RPAREN => token::LPAREN,
+ token::RBRACE => token::LBRACE,
+ token::RBRACKET => token::LBRACKET,
+ _ => fail
}
}
fn is_lit(t: token) -> bool {
alt t {
- LIT_INT(_, _) { true }
- LIT_UINT(_, _) { true }
- LIT_INT_UNSUFFIXED(_) { true }
- LIT_FLOAT(_, _) { true }
- LIT_STR(_) { true }
- _ { false }
+ LIT_INT(_, _) => true,
+ LIT_UINT(_, _) => true,
+ LIT_INT_UNSUFFIXED(_) => true,
+ LIT_FLOAT(_, _) => true,
+ LIT_STR(_) => true,
+ _ => false
}
}
pure fn is_ident(t: token) -> bool {
- alt t { IDENT(_, _) { true } _ { false } }
+ alt t { IDENT(_, _) => true, _ => false }
}
pure fn is_plain_ident(t: token) -> bool {
- alt t { IDENT(_, false) { true } _ { false } }
+ alt t { IDENT(_, false) => true, _ => false }
}
pure fn is_bar(t: token) -> bool {
- alt t { BINOP(OR) | OROR { true } _ { false } }
+ alt t { BINOP(OR) | OROR => true, _ => false }
}
/**
fn tok_str(++t: token) -> ~str {
alt t {
- STRING(s, len) { return fmt!{"STR(%s,%d)", *s, len}; }
- BREAK(_) { return ~"BREAK"; }
- BEGIN(_) { return ~"BEGIN"; }
- END { return ~"END"; }
- EOF { return ~"EOF"; }
+ STRING(s, len) => return fmt!{"STR(%s,%d)", *s, len},
+ BREAK(_) => return ~"BREAK",
+ BEGIN(_) => return ~"BEGIN",
+ END => return ~"END",
+ EOF => return ~"EOF"
}
}
fn pretty_print(t: token) {
debug!{"pp ~[%u,%u]", self.left, self.right};
alt t {
- EOF {
+ EOF => {
if !self.scan_stack_empty {
self.check_stack(0);
self.advance_left(self.token[self.left],
}
self.indent(0);
}
- BEGIN(b) {
+ BEGIN(b) => {
if self.scan_stack_empty {
self.left_total = 1;
self.right_total = 1;
self.size[self.right] = -self.right_total;
self.scan_push(self.right);
}
- END {
+ END => {
if self.scan_stack_empty {
debug!{"pp END/print ~[%u,%u]", self.left, self.right};
self.print(t, 0);
self.scan_push(self.right);
}
}
- BREAK(b) {
+ BREAK(b) => {
if self.scan_stack_empty {
self.left_total = 1;
self.right_total = 1;
self.size[self.right] = -self.right_total;
self.right_total += b.blank_space;
}
- STRING(s, len) {
+ STRING(s, len) => {
if self.scan_stack_empty {
debug!{"pp STRING/print ~[%u,%u]", self.left, self.right};
self.print(t, len);
if L >= 0 {
self.print(x, L);
alt x {
- BREAK(b) { self.left_total += b.blank_space; }
- STRING(_, len) { assert (len == L); self.left_total += len; }
- _ { }
+ BREAK(b) => self.left_total += b.blank_space,
+ STRING(_, len) => { assert (len == L); self.left_total += len; }
+ _ => ()
}
if self.left != self.right {
self.left += 1u;
if !self.scan_stack_empty {
let x = self.scan_top();
alt copy self.token[x] {
- BEGIN(b) {
+ BEGIN(b) => {
if k > 0 {
self.size[self.scan_pop()] = self.size[x] +
self.right_total;
self.check_stack(k - 1);
}
}
- END {
+ END => {
// paper says + not =, but that makes no sense.
self.size[self.scan_pop()] = 1;
self.check_stack(k + 1);
}
- _ {
+ _ => {
self.size[self.scan_pop()] = self.size[x] + self.right_total;
if k > 0 { self.check_stack(k); }
}
self.space};
log(debug, buf_str(self.token, self.size, self.left, self.right, 6u));
alt x {
- BEGIN(b) {
+ BEGIN(b) => {
if L > self.space {
let col = self.margin - self.space + b.offset;
debug!{"print BEGIN -> push broken block at col %d", col};
pbreak: fits});
}
}
- END {
+ END => {
debug!{"print END -> pop END"};
assert (self.print_stack.len() != 0u);
self.print_stack.pop();
}
- BREAK(b) {
+ BREAK(b) => {
let top = self.get_top();
alt top.pbreak {
- fits {
+ fits => {
debug!{"print BREAK in fitting block"};
self.space -= b.blank_space;
self.indent(b.blank_space);
}
- broken(consistent) {
+ broken(consistent) => {
debug!{"print BREAK in consistent block"};
self.print_newline(top.offset + b.offset);
self.space = self.margin - (top.offset + b.offset);
}
- broken(inconsistent) {
+ broken(inconsistent) => {
if L > self.space {
debug!{"print BREAK w/ newline in inconsistent"};
self.print_newline(top.offset + b.offset);
}
}
}
- STRING(s, len) {
+ STRING(s, len) => {
debug!{"print STRING"};
assert (L == len);
// assert L <= space;
self.space -= len;
self.print_str(*s);
}
- EOF {
+ EOF => {
// EOF should never get here.
fail;
}
fn bclose(s: ps, span: codemap::span) { bclose_(s, span, indent_unit); }
fn is_begin(s: ps) -> bool {
- alt s.s.last_token() { pp::BEGIN(_) { true } _ { false } }
+ alt s.s.last_token() { pp::BEGIN(_) => true, _ => false }
}
fn is_end(s: ps) -> bool {
- alt s.s.last_token() { pp::END { true } _ { false } }
+ alt s.s.last_token() { pp::END => true, _ => false }
}
fn is_bol(s: ps) -> bool {
fn print_region(s: ps, region: @ast::region) {
alt region.node {
- ast::re_anon { word_space(s, ~"&"); }
- ast::re_named(name) {
+ ast::re_anon => word_space(s, ~"&"),
+ ast::re_named(name) => {
word(s.s, ~"&");
word(s.s, *name);
}
maybe_print_comment(s, ty.span.lo);
ibox(s, 0u);
alt ty.node {
- ast::ty_nil { word(s.s, ~"()"); }
- ast::ty_bot { word(s.s, ~"!"); }
- ast::ty_box(mt) { word(s.s, ~"@"); print_mt(s, mt); }
- ast::ty_uniq(mt) { word(s.s, ~"~"); print_mt(s, mt); }
- ast::ty_vec(mt) {
+ ast::ty_nil => word(s.s, ~"()"),
+ ast::ty_bot => word(s.s, ~"!"),
+ ast::ty_box(mt) => { word(s.s, ~"@"); print_mt(s, mt); }
+ ast::ty_uniq(mt) => { word(s.s, ~"~"); print_mt(s, mt); }
+ ast::ty_vec(mt) => {
word(s.s, ~"[");
alt mt.mutbl {
- ast::m_mutbl { word_space(s, ~"mut"); }
- ast::m_const { word_space(s, ~"const"); }
- ast::m_imm { }
+ ast::m_mutbl => word_space(s, ~"mut"),
+ ast::m_const => word_space(s, ~"const"),
+ ast::m_imm => ()
}
print_type(s, mt.ty);
word(s.s, ~"]");
}
- ast::ty_ptr(mt) { word(s.s, ~"*"); print_mt(s, mt); }
- ast::ty_rptr(region, mt) {
+ ast::ty_ptr(mt) => { word(s.s, ~"*"); print_mt(s, mt); }
+ ast::ty_rptr(region, mt) => {
alt region.node {
- ast::re_anon { word(s.s, ~"&"); }
- _ { print_region(s, region); word(s.s, ~"/"); }
+ ast::re_anon => word(s.s, ~"&"),
+ _ => { print_region(s, region); word(s.s, ~"/"); }
}
print_mt(s, mt);
}
- ast::ty_rec(fields) {
+ ast::ty_rec(fields) => {
word(s.s, ~"{");
fn print_field(s: ps, f: ast::ty_field) {
cbox(s, indent_unit);
commasep_cmnt(s, consistent, fields, print_field, get_span);
word(s.s, ~",}");
}
- ast::ty_tup(elts) {
+ ast::ty_tup(elts) => {
popen(s);
commasep(s, inconsistent, elts, print_type);
pclose(s);
}
- ast::ty_fn(proto, d) {
+ ast::ty_fn(proto, d) => {
print_ty_fn(s, some(proto), d, none, none);
}
- ast::ty_path(path, _) { print_path(s, path, print_colons); }
- ast::ty_fixed_length(t, v) {
+ ast::ty_path(path, _) => print_path(s, path, print_colons),
+ ast::ty_fixed_length(t, v) => {
print_type(s, t);
word(s.s, ~"/");
print_vstore(s, ast::vstore_fixed(v));
}
- ast::ty_mac(_) {
+ ast::ty_mac(_) => {
fail ~"print_type doesn't know how to print a ty_mac";
}
- ast::ty_infer {
+ ast::ty_infer => {
fail ~"print_type shouldn't see a ty_infer";
}
maybe_print_comment(s, item.span.lo);
print_outer_attributes(s, item.attrs);
alt item.node {
- ast::foreign_item_fn(decl, typarams) {
+ ast::foreign_item_fn(decl, typarams) => {
print_fn(s, decl, item.ident, typarams);
end(s); // end head-ibox
word(s.s, ~";");
let ann_node = node_item(s, item);
s.ann.pre(ann_node);
alt item.node {
- ast::item_const(ty, expr) {
+ ast::item_const(ty, expr) => {
head(s, ~"const");
word_space(s, *item.ident + ~":");
print_type(s, ty);
end(s); // end the outer cbox
}
- ast::item_fn(decl, typarams, body) {
+ ast::item_fn(decl, typarams, body) => {
print_fn(s, decl, item.ident, typarams);
word(s.s, ~" ");
print_block_with_attrs(s, body, item.attrs);
}
- ast::item_mod(_mod) {
+ ast::item_mod(_mod) => {
head(s, ~"mod");
word_nbsp(s, *item.ident);
bopen(s);
print_mod(s, _mod, item.attrs);
bclose(s, item.span);
}
- ast::item_foreign_mod(nmod) {
+ ast::item_foreign_mod(nmod) => {
head(s, ~"extern");
word_nbsp(s, ~"mod");
word_nbsp(s, *item.ident);
print_foreign_mod(s, nmod, item.attrs);
bclose(s, item.span);
}
- ast::item_ty(ty, params) {
+ ast::item_ty(ty, params) => {
ibox(s, indent_unit);
ibox(s, 0u);
word_nbsp(s, ~"type");
word(s.s, ~";");
end(s); // end the outer ibox
}
- ast::item_enum(variants, params) {
+ ast::item_enum(variants, params) => {
let newtype =
vec::len(variants) == 1u &&
str::eq(item.ident, variants[0].node.name) &&
bclose(s, item.span);
}
}
- ast::item_class(tps, traits, items, m_ctor, m_dtor) {
+ ast::item_class(tps, traits, items, m_ctor, m_dtor) => {
head(s, ~"class");
word_nbsp(s, *item.ident);
print_type_params(s, tps);
maybe_print_comment(s, ci.span.lo);
let pr = ast_util::class_member_visibility(ci);
alt pr {
- ast::private {
+ ast::private => {
head(s, ~"priv");
bopen(s);
hardbreak_if_not_bol(s);
}
- _ {}
+ _ => ()
}
alt ci.node {
- ast::instance_var(nm, t, mt, _,_) {
+ ast::instance_var(nm, t, mt, _,_) => {
word_nbsp(s, ~"let");
alt mt {
- ast::class_mutable { word_nbsp(s, ~"mut"); }
- _ {}
+ ast::class_mutable => word_nbsp(s, ~"mut"),
+ _ => ()
}
word(s.s, *nm);
word_nbsp(s, ~":");
print_type(s, t);
word(s.s, ~";");
}
- ast::class_method(m) {
+ ast::class_method(m) => {
print_method(s, m);
}
}
alt pr {
- ast::private { bclose(s, ci.span); }
- _ {}
+ ast::private => bclose(s, ci.span),
+ _ => ()
}
}
bclose(s, item.span);
}
- ast::item_impl(tps, traits, ty, methods) {
+ ast::item_impl(tps, traits, ty, methods) => {
head(s, ~"impl");
word(s.s, *item.ident);
print_type_params(s, tps);
}
bclose(s, item.span);
}
- ast::item_trait(tps, traits, methods) {
+ ast::item_trait(tps, traits, methods) => {
head(s, ~"trait");
word(s.s, *item.ident);
print_type_params(s, tps);
for methods.each |meth| { print_trait_method(s, meth); }
bclose(s, item.span);
}
- ast::item_mac({node: ast::mac_invoc_tt(pth, tts), _}) {
+ ast::item_mac({node: ast::mac_invoc_tt(pth, tts), _}) => {
head(s, path_to_str(pth) + ~"! " + *item.ident);
bopen(s);
for tts.each |tt| { print_tt(s, tt); }
bclose(s, item.span);
}
- ast::item_mac(_) {
+ ast::item_mac(_) => {
fail ~"invalid item-position syntax bit"
}
}
/// expression arguments as expressions). It can be done! I think.
fn print_tt(s: ps, tt: ast::token_tree) {
alt tt {
- ast::tt_delim(tts) {
- for tts.each() |tt_elt| { print_tt(s, tt_elt); }
- }
- ast::tt_tok(_, tk) {
+ ast::tt_delim(tts) => for tts.each() |tt_elt| { print_tt(s, tt_elt); }
+ ast::tt_tok(_, tk) => {
alt tk {
- parse::token::IDENT(*) { // don't let idents run together
+ parse::token::IDENT(*) => { // don't let idents run together
if s.s.token_tree_last_was_ident { word(s.s, ~" ") }
s.s.token_tree_last_was_ident = true;
}
- _ { s.s.token_tree_last_was_ident = false; }
+ _ => { s.s.token_tree_last_was_ident = false; }
}
word(s.s, parse::token::to_str(*s.intr, tk));
}
- ast::tt_seq(_, tts, sep, zerok) {
+ ast::tt_seq(_, tts, sep, zerok) => {
word(s.s, ~"$(");
for tts.each() |tt_elt| { print_tt(s, tt_elt); }
word(s.s, ~")");
alt sep {
- some(tk) { word(s.s, parse::token::to_str(*s.intr, tk)); }
- none {}
+ some(tk) => word(s.s, parse::token::to_str(*s.intr, tk)),
+ none => ()
}
word(s.s, if zerok { ~"*" } else { ~"+" });
s.s.token_tree_last_was_ident = false;
}
- ast::tt_nonterminal(_, name) {
+ ast::tt_nonterminal(_, name) => {
word(s.s, ~"$" + *name);
s.s.token_tree_last_was_ident = true;
}
pclose(s);
}
alt v.node.disr_expr {
- some(d) {
+ some(d) => {
space(s.s);
word_space(s, ~"=");
print_expr(s, d);
}
- _ {}
+ _ => ()
}
}
fn print_trait_method(s: ps, m: ast::trait_method) {
alt m {
- required(ty_m) { print_ty_method(s, ty_m) }
- provided(m) { print_method(s, m) }
+ required(ty_m) => print_ty_method(s, ty_m),
+ provided(m) => print_method(s, m)
}
}
let mut count = 0;
for attrs.each |attr| {
alt attr.node.style {
- ast::attr_outer { print_attribute(s, attr); count += 1; }
- _ {/* fallthrough */ }
+ ast::attr_outer => { print_attribute(s, attr); count += 1; }
+ _ => {/* fallthrough */ }
}
}
if count > 0 { hardbreak_if_not_bol(s); }
let mut count = 0;
for attrs.each |attr| {
alt attr.node.style {
- ast::attr_inner {
+ ast::attr_inner => {
print_attribute(s, attr);
if !attr.node.is_sugared_doc {
word(s.s, ~";");
}
count += 1;
}
- _ {/* fallthrough */ }
+ _ => {/* fallthrough */ }
}
}
if count > 0 { hardbreak_if_not_bol(s); }
fn print_stmt(s: ps, st: ast::stmt) {
maybe_print_comment(s, st.span.lo);
alt st.node {
- ast::stmt_decl(decl, _) {
+ ast::stmt_decl(decl, _) => {
print_decl(s, decl);
}
- ast::stmt_expr(expr, _) {
+ ast::stmt_expr(expr, _) => {
space_if_not_bol(s);
print_expr(s, expr);
}
- ast::stmt_semi(expr, _) {
+ ast::stmt_semi(expr, _) => {
space_if_not_bol(s);
print_expr(s, expr);
word(s.s, ~";");
fn print_possibly_embedded_block_(s: ps, blk: ast::blk, embedded: embed_type,
indented: uint, attrs: ~[ast::attribute]) {
alt blk.node.rules {
- ast::unchecked_blk { word(s.s, ~"unchecked"); }
- ast::unsafe_blk { word(s.s, ~"unsafe"); }
- ast::default_blk { }
+ ast::unchecked_blk => word(s.s, ~"unchecked"),
+ ast::unsafe_blk => word(s.s, ~"unsafe"),
+ ast::default_blk => ()
}
maybe_print_comment(s, blk.span.lo);
let ann_node = node_block(s, blk);
s.ann.pre(ann_node);
alt embedded {
- block_block_fn { end(s); }
- block_normal { bopen(s); }
+ block_block_fn => end(s),
+ block_normal => bopen(s)
}
print_inner_attributes(s, attrs);
print_stmt(s, *st);
}
alt blk.node.expr {
- some(expr) {
+ some(expr) => {
space_if_not_bol(s);
print_expr(s, expr);
maybe_print_trailing_comment(s, expr.span, some(blk.span.hi));
}
- _ { }
+ _ => ()
}
bclose_(s, blk.span, indented);
s.ann.post(ann_node);
// alt, do, & while unambiguously without being parenthesized
fn print_maybe_parens_discrim(s: ps, e: @ast::expr) {
let disambig = alt e.node {
- ast::expr_ret(none) | ast::expr_fail(none) { true }
- _ { false }
+ ast::expr_ret(none) | ast::expr_fail(none) => true,
+ _ => false
};
if disambig { popen(s); }
print_expr(s, e);
print_block(s, blk);
fn do_else(s: ps, els: option<@ast::expr>) {
alt els {
- some(_else) {
+ some(_else) => {
alt _else.node {
// "another else-if"
- ast::expr_if(i, t, e) {
+ ast::expr_if(i, t, e) => {
cbox(s, indent_unit - 1u);
ibox(s, 0u);
word(s.s, ~" else if ");
do_else(s, e);
}
// "final else"
- ast::expr_block(b) {
+ ast::expr_block(b) => {
cbox(s, indent_unit - 1u);
ibox(s, 0u);
word(s.s, ~" else ");
print_block(s, b);
}
// BLEAH, constraints would be great here
- _ {
+ _ => {
fail ~"print_if saw if with weird alternative";
}
}
}
- _ {/* fall through */ }
+ _ => {/* fall through */ }
}
}
do_else(s, elseopt);
fn print_mac(s: ps, m: ast::mac) {
alt m.node {
- ast::mac_invoc(path, arg, body) {
+ ast::mac_invoc(path, arg, body) => {
word(s.s, ~"#");
print_path(s, path, false);
alt arg {
- some(@{node: ast::expr_vec(_, _), _}) { }
- _ { word(s.s, ~" "); }
+ some(@{node: ast::expr_vec(_, _), _}) => (),
+ _ => word(s.s, ~" ")
}
option::iter(arg, |a| print_expr(s, a));
// FIXME: extension 'body' (#2339)
}
- ast::mac_invoc_tt(pth, tts) {
+ ast::mac_invoc_tt(pth, tts) => {
head(s, path_to_str(pth) + ~"!");
bopen(s);
for tts.each() |tt| { print_tt(s, tt); }
bclose(s, m.span);
}
- ast::mac_ellipsis { word(s.s, ~"..."); }
- ast::mac_var(v) { word(s.s, fmt!{"$%u", v}); }
- _ { /* fixme */ }
+ ast::mac_ellipsis => word(s.s, ~"..."),
+ ast::mac_var(v) => word(s.s, fmt!{"$%u", v}),
+ _ => { /* fixme */ }
}
}
fn print_vstore(s: ps, t: ast::vstore) {
alt t {
- ast::vstore_fixed(some(i)) { word(s.s, fmt!{"%u", i}); }
- ast::vstore_fixed(none) { word(s.s, ~"_"); }
- ast::vstore_uniq { word(s.s, ~"~"); }
- ast::vstore_box { word(s.s, ~"@"); }
- ast::vstore_slice(r) {
- alt r.node {
- ast::re_anon { word(s.s, ~"&"); }
- ast::re_named(name) {
- word(s.s, ~"&");
- word(s.s, *name);
- word(s.s, ~".");
- }
- }
+ ast::vstore_fixed(some(i)) => word(s.s, fmt!{"%u", i}),
+ ast::vstore_fixed(none) => word(s.s, ~"_"),
+ ast::vstore_uniq => word(s.s, ~"~"),
+ ast::vstore_box => word(s.s, ~"@"),
+ ast::vstore_slice(r) => alt r.node {
+ ast::re_anon => word(s.s, ~"&"),
+ ast::re_named(name) => {
+ word(s.s, ~"&");
+ word(s.s, *name);
+ word(s.s, ~".");
+ }
}
- }
+ }
}
fn print_expr(s: ps, &&expr: @ast::expr) {
let ann_node = node_expr(s, expr);
s.ann.pre(ann_node);
alt expr.node {
- ast::expr_vstore(e, v) {
- alt v {
- ast::vstore_fixed(_) {
+ ast::expr_vstore(e, v) => alt v {
+ ast::vstore_fixed(_) => {
print_expr(s, e);
- word(s.s, ~"/");
- print_vstore(s, v);
+ word(s.s, ~"/");
+ print_vstore(s, v);
}
- _ {
+ _ => {
print_vstore(s, v);
- print_expr(s, e);
+ print_expr(s, e);
}
- }
}
- ast::expr_vec(exprs, mutbl) {
+ ast::expr_vec(exprs, mutbl) => {
ibox(s, indent_unit);
word(s.s, ~"[");
if mutbl == ast::m_mutbl {
end(s);
}
- ast::expr_rec(fields, wth) {
+ ast::expr_rec(fields, wth) => {
word(s.s, ~"{");
commasep_cmnt(s, consistent, fields, print_field, get_span);
alt wth {
- some(expr) {
+ some(expr) => {
if vec::len(fields) > 0u { space(s.s); }
ibox(s, indent_unit);
word_space(s, ~"with");
print_expr(s, expr);
end(s);
}
- _ { word(s.s, ~","); }
+ _ => word(s.s, ~",")
}
word(s.s, ~"}");
}
- ast::expr_struct(path, fields) {
+ ast::expr_struct(path, fields) => {
print_path(s, path, true);
word(s.s, ~"{");
commasep_cmnt(s, consistent, fields, print_field, get_span);
word(s.s, ~",");
word(s.s, ~"}");
}
- ast::expr_tup(exprs) {
+ ast::expr_tup(exprs) => {
popen(s);
commasep_exprs(s, inconsistent, exprs);
pclose(s);
}
- ast::expr_call(func, args, has_block) {
+ ast::expr_call(func, args, has_block) => {
let mut base_args = args;
let blk = if has_block {
let blk_arg = vec::pop(base_args);
alt blk_arg.node {
- ast::expr_loop_body(_) { word_nbsp(s, ~"for"); }
- ast::expr_do_body(_) { word_nbsp(s, ~"do"); }
- _ {}
+ ast::expr_loop_body(_) => word_nbsp(s, ~"for"),
+ ast::expr_do_body(_) => word_nbsp(s, ~"do"),
+ _ => ()
}
some(blk_arg)
} else { none };
print_expr(s, option::get(blk));
}
}
- ast::expr_binary(op, lhs, rhs) {
+ ast::expr_binary(op, lhs, rhs) => {
let prec = operator_prec(op);
print_op_maybe_parens(s, lhs, prec);
space(s.s);
word_space(s, ast_util::binop_to_str(op));
print_op_maybe_parens(s, rhs, prec + 1u);
}
- ast::expr_unary(op, expr) {
+ ast::expr_unary(op, expr) => {
word(s.s, ast_util::unop_to_str(op));
print_op_maybe_parens(s, expr, parse::prec::unop_prec);
}
- ast::expr_addr_of(m, expr) {
+ ast::expr_addr_of(m, expr) => {
word(s.s, ~"&");
print_mutability(s, m);
print_expr(s, expr);
}
- ast::expr_lit(lit) { print_literal(s, lit); }
- ast::expr_cast(expr, ty) {
+ ast::expr_lit(lit) => print_literal(s, lit),
+ ast::expr_cast(expr, ty) => {
print_op_maybe_parens(s, expr, parse::prec::as_prec);
space(s.s);
word_space(s, ~"as");
print_type_ex(s, ty, true);
}
- ast::expr_if(test, blk, elseopt) {
+ ast::expr_if(test, blk, elseopt) => {
print_if(s, test, blk, elseopt, false);
}
- ast::expr_while(test, blk) {
+ ast::expr_while(test, blk) => {
head(s, ~"while");
print_maybe_parens_discrim(s, test);
space(s.s);
print_block(s, blk);
}
- ast::expr_loop(blk) {
+ ast::expr_loop(blk) => {
head(s, ~"loop");
space(s.s);
print_block(s, blk);
}
- ast::expr_alt(expr, arms, mode) {
+ ast::expr_alt(expr, arms, mode) => {
cbox(s, alt_indent_unit);
ibox(s, 4u);
word_nbsp(s, ~"alt");
}
space(s.s);
alt arm.guard {
- some(e) { word_space(s, ~"if"); print_expr(s, e); space(s.s); }
- none { }
+ some(e) => {
+ word_space(s, ~"if");
+ print_expr(s, e);
+ space(s.s);
+ }
+ none => ()
}
word_space(s, ~"=>");
// Extract the expression from the extra block the parser adds
}
bclose_(s, expr.span, alt_indent_unit);
}
- ast::expr_fn(proto, decl, body, cap_clause) {
+ ast::expr_fn(proto, decl, body, cap_clause) => {
// containing cbox, will be closed by print-block at }
cbox(s, indent_unit);
// head-box, will be closed by print-block at start
space(s.s);
print_block(s, body);
}
- ast::expr_fn_block(decl, body, cap_clause) {
+ ast::expr_fn_block(decl, body, cap_clause) => {
print_fn_block_args(s, decl, *cap_clause);
// The parser always adds an extra implicit block around lambdas
assert body.node.stmts.is_empty();
space(s.s);
print_expr(s, body.node.expr.get());
}
- ast::expr_loop_body(body) {
+ ast::expr_loop_body(body) => {
print_expr(s, body);
}
- ast::expr_do_body(body) {
+ ast::expr_do_body(body) => {
print_expr(s, body);
}
- ast::expr_block(blk) {
+ ast::expr_block(blk) => {
// containing cbox, will be closed by print-block at }
cbox(s, indent_unit);
// head-box, will be closed by print-block after {
ibox(s, 0u);
print_block(s, blk);
}
- ast::expr_copy(e) { word_space(s, ~"copy"); print_expr(s, e); }
- ast::expr_unary_move(e) { word_space(s, ~"move"); print_expr(s, e); }
- ast::expr_move(lhs, rhs) {
+ ast::expr_copy(e) => { word_space(s, ~"copy"); print_expr(s, e); }
+ ast::expr_unary_move(e) => { word_space(s, ~"move"); print_expr(s, e); }
+ ast::expr_move(lhs, rhs) => {
print_expr(s, lhs);
space(s.s);
word_space(s, ~"<-");
print_expr(s, rhs);
}
- ast::expr_assign(lhs, rhs) {
+ ast::expr_assign(lhs, rhs) => {
print_expr(s, lhs);
space(s.s);
word_space(s, ~"=");
print_expr(s, rhs);
}
- ast::expr_swap(lhs, rhs) {
+ ast::expr_swap(lhs, rhs) => {
print_expr(s, lhs);
space(s.s);
word_space(s, ~"<->");
print_expr(s, rhs);
}
- ast::expr_assign_op(op, lhs, rhs) {
+ ast::expr_assign_op(op, lhs, rhs) => {
print_expr(s, lhs);
space(s.s);
word(s.s, ast_util::binop_to_str(op));
word_space(s, ~"=");
print_expr(s, rhs);
}
- ast::expr_field(expr, id, tys) {
+ ast::expr_field(expr, id, tys) => {
// Deal with '10.x'
if ends_in_lit_int(expr) {
popen(s); print_expr(s, expr); pclose(s);
word(s.s, ~">");
}
}
- ast::expr_index(expr, index) {
+ ast::expr_index(expr, index) => {
print_expr_parens_if_not_bot(s, expr);
word(s.s, ~"[");
print_expr(s, index);
word(s.s, ~"]");
}
- ast::expr_path(path) { print_path(s, path, true); }
- ast::expr_fail(maybe_fail_val) {
+ ast::expr_path(path) => print_path(s, path, true),
+ ast::expr_fail(maybe_fail_val) => {
word(s.s, ~"fail");
alt maybe_fail_val {
- some(expr) { word(s.s, ~" "); print_expr(s, expr); }
- _ { }
+ some(expr) => { word(s.s, ~" "); print_expr(s, expr); }
+ _ => ()
}
}
- ast::expr_break { word(s.s, ~"break"); }
- ast::expr_again { word(s.s, ~"again"); }
- ast::expr_ret(result) {
+ ast::expr_break => word(s.s, ~"break"),
+ ast::expr_again => word(s.s, ~"again"),
+ ast::expr_ret(result) => {
word(s.s, ~"return");
alt result {
- some(expr) { word(s.s, ~" "); print_expr(s, expr); }
- _ { }
+ some(expr) => { word(s.s, ~" "); print_expr(s, expr); }
+ _ => ()
}
}
- ast::expr_log(lvl, lexp, expr) {
+ ast::expr_log(lvl, lexp, expr) => {
alt check lvl {
- 1 { word_nbsp(s, ~"log"); print_expr(s, expr); }
- 0 { word_nbsp(s, ~"log_err"); print_expr(s, expr); }
- 2 {
+ 1 => { word_nbsp(s, ~"log"); print_expr(s, expr); }
+ 0 => { word_nbsp(s, ~"log_err"); print_expr(s, expr); }
+ 2 => {
word_nbsp(s, ~"log");
popen(s);
print_expr(s, lexp);
}
}
}
- ast::expr_assert(expr) {
+ ast::expr_assert(expr) => {
word_nbsp(s, ~"assert");
print_expr(s, expr);
}
- ast::expr_mac(m) { print_mac(s, m); }
+ ast::expr_mac(m) => print_mac(s, m),
}
s.ann.post(ann_node);
end(s);
ast::expr_assign_op(_, _, _) | ast::expr_swap(_, _) |
ast::expr_log(_, _, _) | ast::expr_assert(_) |
ast::expr_call(_, _, true) |
- ast::expr_vstore(_, _) { true }
- _ { false }
+ ast::expr_vstore(_, _) => true,
+ _ => false
};
if parens { popen(s); }
print_expr(s, ex);
fn print_local_decl(s: ps, loc: @ast::local) {
print_pat(s, loc.node.pat);
alt loc.node.ty.node {
- ast::ty_infer { }
- _ { word_space(s, ~":"); print_type(s, loc.node.ty); }
+ ast::ty_infer => (),
+ _ => { word_space(s, ~":"); print_type(s, loc.node.ty); }
}
}
fn print_decl(s: ps, decl: @ast::decl) {
maybe_print_comment(s, decl.span.lo);
alt decl.node {
- ast::decl_local(locs) {
+ ast::decl_local(locs) => {
space_if_not_bol(s);
ibox(s, indent_unit);
word_nbsp(s, ~"let");
print_local_decl(s, loc);
end(s);
alt loc.node.init {
- some(init) {
+ some(init) => {
nbsp(s);
alt init.op {
- ast::init_assign { word_space(s, ~"="); }
- ast::init_move { word_space(s, ~"<-"); }
+ ast::init_assign => word_space(s, ~"="),
+ ast::init_move => word_space(s, ~"<-")
}
print_expr(s, init.expr);
}
- _ { }
+ _ => ()
}
}
commasep(s, consistent, locs, print_local);
end(s);
}
- ast::decl_item(item) { print_item(s, item); }
+ ast::decl_item(item) => print_item(s, item)
}
}
if colons_before_params { word(s.s, ~"::"); }
alt path.rp {
- none { /* ok */ }
- some(r) {
+ none => { /* ok */ }
+ some(r) => {
word(s.s, ~"/");
print_region(s, r);
}
/* Pat isn't normalized, but the beauty of it
is that it doesn't matter */
alt pat.node {
- ast::pat_wild { word(s.s, ~"_"); }
- ast::pat_ident(binding_mode, path, sub) {
+ ast::pat_wild => word(s.s, ~"_"),
+ ast::pat_ident(binding_mode, path, sub) => {
alt binding_mode {
- ast::bind_by_ref => { word_space(s, ~"ref"); }
- ast::bind_by_value => {}
+ ast::bind_by_ref => word_space(s, ~"ref"),
+ ast::bind_by_value => ()
}
print_path(s, path, true);
alt sub {
some(p) => { word(s.s, ~"@"); print_pat(s, p); }
- none => {}
+ none => ()
}
}
- ast::pat_enum(path, args_) {
+ ast::pat_enum(path, args_) => {
print_path(s, path, true);
alt args_ {
- none { word(s.s, ~"(*)"); }
- some(args) {
+ none => word(s.s, ~"(*)"),
+ some(args) => {
if vec::len(args) > 0u {
popen(s);
commasep(s, inconsistent, args, print_pat);
}
}
}
- ast::pat_rec(fields, etc) {
+ ast::pat_rec(fields, etc) => {
word(s.s, ~"{");
fn print_field(s: ps, f: ast::field_pat) {
cbox(s, indent_unit);
}
word(s.s, ~"}");
}
- ast::pat_tup(elts) {
+ ast::pat_tup(elts) => {
popen(s);
commasep(s, inconsistent, elts, print_pat);
pclose(s);
}
- ast::pat_box(inner) { word(s.s, ~"@"); print_pat(s, inner); }
- ast::pat_uniq(inner) { word(s.s, ~"~"); print_pat(s, inner); }
- ast::pat_lit(e) { print_expr(s, e); }
- ast::pat_range(begin, end) {
+ ast::pat_box(inner) => { word(s.s, ~"@"); print_pat(s, inner); }
+ ast::pat_uniq(inner) => { word(s.s, ~"~"); print_pat(s, inner); }
+ ast::pat_lit(e) => print_expr(s, e),
+ ast::pat_range(begin, end) => {
print_expr(s, begin);
space(s.s);
word_space(s, ~"to");
fn print_fn(s: ps, decl: ast::fn_decl, name: ast::ident,
typarams: ~[ast::ty_param]) {
alt decl.purity {
- ast::impure_fn { head(s, ~"fn") }
- _ { head(s, purity_to_str(decl.purity) + ~" fn") }
+ ast::impure_fn => head(s, ~"fn"),
+ _ => head(s, purity_to_str(decl.purity) + ~" fn")
}
word(s.s, *name);
print_type_params(s, typarams);
fn mode_to_str(m: ast::mode) -> ~str {
alt m {
- ast::expl(ast::by_mutbl_ref) { ~"&" }
- ast::expl(ast::by_move) { ~"-" }
- ast::expl(ast::by_ref) { ~"&&" }
- ast::expl(ast::by_val) { ~"++" }
- ast::expl(ast::by_copy) { ~"+" }
- ast::infer(_) { ~"" }
+ ast::expl(ast::by_mutbl_ref) => ~"&",
+ ast::expl(ast::by_move) => ~"-",
+ ast::expl(ast::by_ref) => ~"&&",
+ ast::expl(ast::by_val) => ~"++",
+ ast::expl(ast::by_copy) => ~"+",
+ ast::infer(_) => ~""
}
}
for vec::each(*bounds) |bound| {
nbsp(s);
alt bound {
- ast::bound_copy { word(s.s, ~"copy"); }
- ast::bound_send { word(s.s, ~"send"); }
- ast::bound_const { word(s.s, ~"const"); }
- ast::bound_owned { word(s.s, ~"owned"); }
- ast::bound_trait(t) { print_type(s, t); }
+ ast::bound_copy => word(s.s, ~"copy"),
+ ast::bound_send => word(s.s, ~"send"),
+ ast::bound_const => word(s.s, ~"const"),
+ ast::bound_owned => word(s.s, ~"owned"),
+ ast::bound_trait(t) => print_type(s, t)
}
}
}
fn print_meta_item(s: ps, &&item: @ast::meta_item) {
ibox(s, indent_unit);
alt item.node {
- ast::meta_word(name) { word(s.s, *name); }
- ast::meta_name_value(name, value) {
+ ast::meta_word(name) => word(s.s, *name),
+ ast::meta_name_value(name, value) => {
word_space(s, *name);
word_space(s, ~"=");
print_literal(s, @value);
}
- ast::meta_list(name, items) {
+ ast::meta_list(name, items) => {
word(s.s, *name);
popen(s);
commasep(s, consistent, items, print_meta_item);
fn print_view_path(s: ps, &&vp: @ast::view_path) {
alt vp.node {
- ast::view_path_simple(ident, path, _) {
+ ast::view_path_simple(ident, path, _) => {
if path.idents[vec::len(path.idents)-1u] != ident {
word_space(s, *ident);
word_space(s, ~"=");
print_path(s, path, false);
}
- ast::view_path_glob(path, _) {
+ ast::view_path_glob(path, _) => {
print_path(s, path, false);
word(s.s, ~"::*");
}
- ast::view_path_list(path, idents, _) {
+ ast::view_path_list(path, idents, _) => {
print_path(s, path, false);
word(s.s, ~"::{");
do commasep(s, inconsistent, idents) |s, w| {
maybe_print_comment(s, item.span.lo);
print_outer_attributes(s, item.attrs);
alt item.node {
- ast::view_item_use(id, mta, _) {
+ ast::view_item_use(id, mta, _) => {
head(s, ~"use");
word(s.s, *id);
if vec::len(mta) > 0u {
}
}
- ast::view_item_import(vps) {
+ ast::view_item_import(vps) => {
head(s, ~"import");
print_view_paths(s, vps);
}
- ast::view_item_export(vps) {
+ ast::view_item_export(vps) => {
head(s, ~"export");
print_view_paths(s, vps);
}
fn print_mutability(s: ps, mutbl: ast::mutability) {
alt mutbl {
- ast::m_mutbl { word_nbsp(s, ~"mut"); }
- ast::m_const { word_nbsp(s, ~"const"); }
- ast::m_imm {/* nothing */ }
+ ast::m_mutbl => word_nbsp(s, ~"mut"),
+ ast::m_const => word_nbsp(s, ~"const"),
+ ast::m_imm => {/* nothing */ }
}
}
ibox(s, indent_unit);
print_arg_mode(s, input.mode);
alt input.ty.node {
- ast::ty_infer {
- word(s.s, *input.ident);
- }
- _ {
+ ast::ty_infer => word(s.s, *input.ident),
+ _ => {
if str::len(*input.ident) > 0u {
word_space(s, *input.ident + ~":");
}
tps: option<~[ast::ty_param]>) {
ibox(s, indent_unit);
word(s.s, opt_proto_to_str(opt_proto));
- alt id { some(id) { word(s.s, ~" "); word(s.s, *id); } _ { } }
- alt tps { some(tps) { print_type_params(s, tps); } _ { } }
+ alt id { some(id) => { word(s.s, ~" "); word(s.s, *id); } _ => () }
+ alt tps { some(tps) => print_type_params(s, tps), _ => () }
zerobreak(s.s);
popen(s);
commasep(s, inconsistent, decl.inputs, print_arg);
fn maybe_print_trailing_comment(s: ps, span: codemap::span,
next_pos: option<uint>) {
let mut cm;
- alt s.cm { some(ccm) { cm = ccm; } _ { return; } }
+ alt s.cm { some(ccm) => cm = ccm, _ => return }
alt next_comment(s) {
- some(cmnt) {
+ some(cmnt) => {
if cmnt.style != comments::trailing { return; }
let span_line = codemap::lookup_char_pos(cm, span.hi);
let comment_line = codemap::lookup_char_pos(cm, cmnt.pos);
let mut next = cmnt.pos + 1u;
- alt next_pos { none { } some(p) { next = p; } }
+ alt next_pos { none => (), some(p) => next = p }
if span.hi < cmnt.pos && cmnt.pos < next &&
span_line.line == comment_line.line {
print_comment(s, cmnt);
s.cur_cmnt += 1u;
}
}
- _ { }
+ _ => ()
}
}
if option::is_none(next_comment(s)) { hardbreak(s.s); }
loop {
alt next_comment(s) {
- some(cmnt) { print_comment(s, cmnt); s.cur_cmnt += 1u; }
- _ { break; }
+ some(cmnt) => { print_comment(s, cmnt); s.cur_cmnt += 1u; }
+ _ => break
}
}
}
fn print_literal(s: ps, &&lit: @ast::lit) {
maybe_print_comment(s, lit.span.lo);
alt next_lit(s, lit.span.lo) {
- some(ltrl) {
+ some(ltrl) => {
word(s.s, ltrl.lit);
return;
}
- _ {}
+ _ => ()
}
alt lit.node {
- ast::lit_str(st) { print_string(s, *st); }
- ast::lit_int(ch, ast::ty_char) {
+ ast::lit_str(st) => print_string(s, *st),
+ ast::lit_int(ch, ast::ty_char) => {
word(s.s, ~"'" + char::escape_default(ch as char) + ~"'");
}
- ast::lit_int(i, t) {
+ ast::lit_int(i, t) => {
if i < 0_i64 {
word(s.s,
~"-" + u64::to_str(-i as u64, 10u)
+ ast_util::int_ty_to_str(t));
}
}
- ast::lit_uint(u, t) {
+ ast::lit_uint(u, t) => {
word(s.s,
u64::to_str(u, 10u)
+ ast_util::uint_ty_to_str(t));
}
- ast::lit_int_unsuffixed(i) {
+ ast::lit_int_unsuffixed(i) => {
if i < 0_i64 {
word(s.s, ~"-" + u64::to_str(-i as u64, 10u));
} else {
word(s.s, u64::to_str(i as u64, 10u));
}
}
- ast::lit_float(f, t) {
+ ast::lit_float(f, t) => {
word(s.s, *f + ast_util::float_ty_to_str(t));
}
- ast::lit_nil { word(s.s, ~"()"); }
- ast::lit_bool(val) {
+ ast::lit_nil => word(s.s, ~"()"),
+ ast::lit_bool(val) => {
if val { word(s.s, ~"true"); } else { word(s.s, ~"false"); }
}
}
fn next_lit(s: ps, pos: uint) -> option<comments::lit> {
alt s.literals {
- some(lits) {
+ some(lits) => {
while s.cur_lit < vec::len(lits) {
let ltrl = lits[s.cur_lit];
if ltrl.pos > pos { return none; }
}
return none;
}
- _ { return none; }
+ _ => return none
}
}
fn maybe_print_comment(s: ps, pos: uint) {
loop {
alt next_comment(s) {
- some(cmnt) {
+ some(cmnt) => {
if cmnt.pos < pos {
print_comment(s, cmnt);
s.cur_cmnt += 1u;
} else { break; }
}
- _ { break; }
+ _ => break
}
}
}
fn print_comment(s: ps, cmnt: comments::cmnt) {
alt cmnt.style {
- comments::mixed {
+ comments::mixed => {
assert (vec::len(cmnt.lines) == 1u);
zerobreak(s.s);
word(s.s, cmnt.lines[0]);
zerobreak(s.s);
}
- comments::isolated {
+ comments::isolated => {
pprust::hardbreak_if_not_bol(s);
for cmnt.lines.each |line| {
// Don't print empty lines because they will end up as trailing
hardbreak(s.s);
}
}
- comments::trailing {
+ comments::trailing => {
word(s.s, ~" ");
if vec::len(cmnt.lines) == 1u {
word(s.s, cmnt.lines[0]);
end(s);
}
}
- comments::blank_line {
+ comments::blank_line => {
// We need to do at least one, possibly two hardbreaks.
let is_semi =
alt s.s.last_token() {
- pp::STRING(s, _) { *s == ~";" }
- _ { false }
+ pp::STRING(s, _) => *s == ~";",
+ _ => false
};
if is_semi || is_begin(s) || is_end(s) { hardbreak(s.s); }
hardbreak(s.s);
fn next_comment(s: ps) -> option<comments::cmnt> {
alt s.comments {
- some(cmnts) {
+ some(cmnts) => {
if s.cur_cmnt < vec::len(cmnts) {
return some(cmnts[s.cur_cmnt]);
} else { return none::<comments::cmnt>; }
}
- _ { return none::<comments::cmnt>; }
+ _ => return none::<comments::cmnt>
}
}
fn opt_proto_to_str(opt_p: option<ast::proto>) -> ~str {
alt opt_p {
- none { ~"fn" }
- some(p) { proto_to_str(p) }
+ none => ~"fn",
+ some(p) => proto_to_str(p)
}
}
fn print_purity(s: ps, p: ast::purity) {
alt p {
- ast::impure_fn {}
- _ { word_nbsp(s, purity_to_str(p)) }
+ ast::impure_fn => (),
+ _ => word_nbsp(s, purity_to_str(p))
}
}
fn proto_to_str(p: ast::proto) -> ~str {
return alt p {
- ast::proto_bare { ~"extern fn" }
- ast::proto_block { ~"fn&" }
- ast::proto_uniq { ~"fn~" }
- ast::proto_box { ~"fn@" }
+ ast::proto_bare => ~"extern fn",
+ ast::proto_block => ~"fn&",
+ ast::proto_uniq => ~"fn~",
+ ast::proto_box => ~"fn@"
};
}
impl <T: const copy> of interner<T> for hash_interner<T> {
fn intern(val: T) -> uint {
alt self.map.find(val) {
- some(idx) { return idx; }
- none {
+ some(idx) => return idx,
+ none => {
let new_idx = self.vect.len();
self.map.insert(val, new_idx);
self.vect.push(val);
fn name_of_fn(fk: fn_kind) -> ident {
alt fk {
fk_item_fn(name, _) | fk_method(name, _, _)
- | fk_ctor(name, _, _, _, _) { /* FIXME (#2543) */ copy name }
- fk_anon(*) | fk_fn_block(*) { @~"anon" }
- fk_dtor(*) { @~"drop" }
+ | fk_ctor(name, _, _, _, _) => /* FIXME (#2543) */ copy name,
+ fk_anon(*) | fk_fn_block(*) => @~"anon",
+ fk_dtor(*) => @~"drop"
}
}
fn tps_of_fn(fk: fn_kind) -> ~[ty_param] {
alt fk {
fk_item_fn(_, tps) | fk_method(_, tps, _)
- | fk_ctor(_, _, tps, _, _) | fk_dtor(tps, _, _, _) {
+ | fk_ctor(_, _, tps, _, _) | fk_dtor(tps, _, _, _) => {
/* FIXME (#2543) */ copy tps
}
- fk_anon(*) | fk_fn_block(*) { ~[] }
+ fk_anon(*) | fk_fn_block(*) => ~[]
}
}
fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) {
alt cd.node {
- cdir_src_mod(_, _) { }
- cdir_dir_mod(_, cdirs, _) {
- for cdirs.each |cdir| {
- visit_crate_directive(cdir, e, v);
- }
+ cdir_src_mod(_, _) => (),
+ cdir_dir_mod(_, cdirs, _) => for cdirs.each |cdir| {
+ visit_crate_directive(cdir, e, v);
}
- cdir_view_item(vi) { v.visit_view_item(vi, e, v); }
- cdir_syntax(_) { }
+ cdir_view_item(vi) => v.visit_view_item(vi, e, v),
+ cdir_syntax(_) => ()
}
}
fn visit_local<E>(loc: @local, e: E, v: vt<E>) {
v.visit_pat(loc.node.pat, e, v);
v.visit_ty(loc.node.ty, e, v);
- alt loc.node.init { none { } some(i) { v.visit_expr(i.expr, e, v); } }
+ alt loc.node.init {
+ none => (),
+ some(i) => v.visit_expr(i.expr, e, v)
+ }
}
fn visit_item<E>(i: @item, e: E, v: vt<E>) {
alt i.node {
- item_const(t, ex) { v.visit_ty(t, e, v); v.visit_expr(ex, e, v); }
- item_fn(decl, tp, body) {
+ item_const(t, ex) => { v.visit_ty(t, e, v); v.visit_expr(ex, e, v); }
+ item_fn(decl, tp, body) => {
v.visit_fn(fk_item_fn(/* FIXME (#2543) */ copy i.ident,
/* FIXME (#2543) */ copy tp), decl, body,
i.span, i.id, e, v);
}
- item_mod(m) { v.visit_mod(m, i.span, i.id, e, v); }
- item_foreign_mod(nm) {
+ item_mod(m) => v.visit_mod(m, i.span, i.id, e, v),
+ item_foreign_mod(nm) => {
for nm.view_items.each |vi| { v.visit_view_item(vi, e, v); }
for nm.items.each |ni| { v.visit_foreign_item(ni, e, v); }
}
- item_ty(t, tps) {
+ item_ty(t, tps) => {
v.visit_ty(t, e, v);
v.visit_ty_params(tps, e, v);
}
- item_enum(variants, tps) {
+ item_enum(variants, tps) => {
v.visit_ty_params(tps, e, v);
for variants.each |vr| {
for vr.node.args.each |va| { v.visit_ty(va.ty, e, v); }
}
}
- item_impl(tps, traits, ty, methods) {
+ item_impl(tps, traits, ty, methods) => {
v.visit_ty_params(tps, e, v);
for traits.each |p| {
visit_path(p.path, e, v);
visit_method_helper(m, e, v)
}
}
- item_class(tps, traits, members, m_ctor, m_dtor) {
+ item_class(tps, traits, members, m_ctor, m_dtor) => {
v.visit_ty_params(tps, e, v);
for members.each |m| {
v.visit_class_item(m, e, v);
ast_util::local_def(i.id), e, v)
};
}
- item_trait(tps, traits, methods) {
+ item_trait(tps, traits, methods) => {
v.visit_ty_params(tps, e, v);
for traits.each |p| { visit_path(p.path, e, v); }
for methods.each |m| {
v.visit_trait_method(m, e, v);
}
}
- item_mac(m) { visit_mac(m, e, v) }
+ item_mac(m) => visit_mac(m, e, v)
}
}
fn visit_class_item<E>(cm: @class_member, e:E, v:vt<E>) {
alt cm.node {
- instance_var(_, t, _, _, _) {
- v.visit_ty(t, e, v);
- }
- class_method(m) {
- visit_method_helper(m, e, v);
- }
+ instance_var(_, t, _, _, _) => v.visit_ty(t, e, v),
+ class_method(m) => visit_method_helper(m, e, v)
}
}
fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
alt t.node {
ty_box(mt) | ty_uniq(mt) |
- ty_vec(mt) | ty_ptr(mt) | ty_rptr(_, mt) {
+ ty_vec(mt) | ty_ptr(mt) | ty_rptr(_, mt) => {
v.visit_ty(mt.ty, e, v);
}
- ty_rec(flds) {
- for flds.each |f| { v.visit_ty(f.node.mt.ty, e, v); }
+ ty_rec(flds) => for flds.each |f| {
+ v.visit_ty(f.node.mt.ty, e, v);
+ }
+ ty_tup(ts) => for ts.each |tt| {
+ v.visit_ty(tt, e, v);
}
- ty_tup(ts) { for ts.each |tt| { v.visit_ty(tt, e, v); } }
- ty_fn(_, decl) {
+ ty_fn(_, decl) => {
for decl.inputs.each |a| { v.visit_ty(a.ty, e, v); }
v.visit_ty(decl.output, e, v);
}
- ty_path(p, _) { visit_path(p, e, v); }
- ty_fixed_length(t, _) {
- v.visit_ty(t, e, v);
- }
+ ty_path(p, _) => visit_path(p, e, v),
+ ty_fixed_length(t, _) => v.visit_ty(t, e, v),
ty_nil |
ty_bot |
ty_mac(_) |
- ty_infer {
- }
+ ty_infer => ()
}
}
fn visit_pat<E>(p: @pat, e: E, v: vt<E>) {
alt p.node {
- pat_enum(path, children) {
+ pat_enum(path, children) => {
visit_path(path, e, v);
do option::iter(children) |children| {
for children.each |child| { v.visit_pat(child, e, v); }}
}
- pat_rec(fields, _) {
- for fields.each |f| { v.visit_pat(f.pat, e, v); }
+ pat_rec(fields, _) => for fields.each |f| {
+ v.visit_pat(f.pat, e, v)
}
- pat_tup(elts) { for elts.each |elt| { v.visit_pat(elt, e, v); } }
- pat_box(inner) | pat_uniq(inner) {
- v.visit_pat(inner, e, v);
+ pat_tup(elts) => for elts.each |elt| {
+ v.visit_pat(elt, e, v)
}
- pat_ident(_, path, inner) {
+ pat_box(inner) | pat_uniq(inner) => v.visit_pat(inner, e, v),
+ pat_ident(_, path, inner) => {
visit_path(path, e, v);
do option::iter(inner) |subpat| { v.visit_pat(subpat, e, v)};
}
- pat_lit(ex) { v.visit_expr(ex, e, v); }
- pat_range(e1, e2) { v.visit_expr(e1, e, v); v.visit_expr(e2, e, v); }
- pat_wild {}
+ pat_lit(ex) => v.visit_expr(ex, e, v),
+ pat_range(e1, e2) => { v.visit_expr(e1, e, v); v.visit_expr(e2, e, v); }
+ pat_wild => ()
}
}
fn visit_foreign_item<E>(ni: @foreign_item, e: E, v: vt<E>) {
alt ni.node {
- foreign_item_fn(fd, tps) {
+ foreign_item_fn(fd, tps) => {
v.visit_ty_params(tps, e, v);
visit_fn_decl(fd, e, v);
}
for tps.each |tp| {
for vec::each(*tp.bounds) |bound| {
alt bound {
- bound_trait(t) { v.visit_ty(t, e, v); }
- bound_copy | bound_send | bound_const | bound_owned { }
+ bound_trait(t) => v.visit_ty(t, e, v),
+ bound_copy | bound_send | bound_const | bound_owned => ()
}
}
}
fn visit_trait_method<E>(m: trait_method, e: E, v: vt<E>) {
alt m {
- required(ty_m) {
- v.visit_ty_method(ty_m, e, v)
- }
- provided(m) {
- visit_method_helper(m, e, v)
- }
+ required(ty_m) => v.visit_ty_method(ty_m, e, v),
+ provided(m) => visit_method_helper(m, e, v)
}
}
fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
alt s.node {
- stmt_decl(d, _) { v.visit_decl(d, e, v); }
- stmt_expr(ex, _) { v.visit_expr(ex, e, v); }
- stmt_semi(ex, _) { v.visit_expr(ex, e, v); }
+ stmt_decl(d, _) => v.visit_decl(d, e, v),
+ stmt_expr(ex, _) => v.visit_expr(ex, e, v),
+ stmt_semi(ex, _) => v.visit_expr(ex, e, v)
}
}
fn visit_decl<E>(d: @decl, e: E, v: vt<E>) {
alt d.node {
- decl_local(locs) {
- for locs.each |loc| { v.visit_local(loc, e, v); }
+ decl_local(locs) => for locs.each |loc| {
+ v.visit_local(loc, e, v)
}
- decl_item(it) { v.visit_item(it, e, v); }
+ decl_item(it) => v.visit_item(it, e, v)
}
}
fn visit_expr_opt<E>(eo: option<@expr>, e: E, v: vt<E>) {
- alt eo { none { } some(ex) { v.visit_expr(ex, e, v); } }
+ alt eo { none => (), some(ex) => v.visit_expr(ex, e, v) }
}
fn visit_exprs<E>(exprs: ~[@expr], e: E, v: vt<E>) {
fn visit_mac<E>(m: mac, e: E, v: vt<E>) {
alt m.node {
- ast::mac_invoc(pth, arg, body) {
+ ast::mac_invoc(pth, arg, body) => {
option::map(arg, |arg| v.visit_expr(arg, e, v)); }
- ast::mac_invoc_tt(pth, tt) { /* no user-serviceable parts inside */ }
- ast::mac_ellipsis { }
- ast::mac_aq(_, e) { /* FIXME: maybe visit (Issue #2340) */ }
- ast::mac_var(_) { }
+ ast::mac_invoc_tt(pth, tt) => { /* no user-serviceable parts inside */ }
+ ast::mac_ellipsis => (),
+ ast::mac_aq(_, e) => { /* FIXME: maybe visit (Issue #2340) */ }
+ ast::mac_var(_) => ()
}
}
fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
alt ex.node {
- expr_vstore(x, _) { v.visit_expr(x, e, v); }
- expr_vec(es, _) { visit_exprs(es, e, v); }
+ expr_vstore(x, _) => v.visit_expr(x, e, v),
+ expr_vec(es, _) => visit_exprs(es, e, v),
expr_repeat(element, count, _) => {
v.visit_expr(element, e, v);
v.visit_expr(count, e, v);
}
- expr_rec(flds, base) {
+ expr_rec(flds, base) => {
for flds.each |f| { v.visit_expr(f.node.expr, e, v); }
visit_expr_opt(base, e, v);
}
- expr_struct(p, flds) {
+ expr_struct(p, flds) => {
visit_path(p, e, v);
for flds.each |f| { v.visit_expr(f.node.expr, e, v); }
}
- expr_tup(elts) { for elts.each |el| { v.visit_expr(el, e, v); } }
- expr_call(callee, args, _) {
+ expr_tup(elts) => for elts.each |el| { v.visit_expr(el, e, v); }
+ expr_call(callee, args, _) => {
visit_exprs(args, e, v);
v.visit_expr(callee, e, v);
}
- expr_binary(_, a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); }
+ expr_binary(_, a, b) => {
+ v.visit_expr(a, e, v); v.visit_expr(b, e, v);
+ }
expr_addr_of(_, x) | expr_unary(_, x) |
expr_loop_body(x) | expr_do_body(x) |
- expr_assert(x) { v.visit_expr(x, e, v); }
- expr_lit(_) { }
- expr_cast(x, t) { v.visit_expr(x, e, v); v.visit_ty(t, e, v); }
- expr_if(x, b, eo) {
+ expr_assert(x) => v.visit_expr(x, e, v),
+ expr_lit(_) => (),
+ expr_cast(x, t) => { v.visit_expr(x, e, v); v.visit_ty(t, e, v); }
+ expr_if(x, b, eo) => {
v.visit_expr(x, e, v);
v.visit_block(b, e, v);
visit_expr_opt(eo, e, v);
}
- expr_while(x, b) { v.visit_expr(x, e, v); v.visit_block(b, e, v); }
- expr_loop(b) { v.visit_block(b, e, v); }
- expr_alt(x, arms, _) {
+ expr_while(x, b) => { v.visit_expr(x, e, v); v.visit_block(b, e, v); }
+ expr_loop(b) => v.visit_block(b, e, v),
+ expr_alt(x, arms, _) => {
v.visit_expr(x, e, v);
for arms.each |a| { v.visit_arm(a, e, v); }
}
- expr_fn(proto, decl, body, cap_clause) {
+ expr_fn(proto, decl, body, cap_clause) => {
v.visit_fn(fk_anon(proto, cap_clause), decl, body,
ex.span, ex.id, e, v);
}
- expr_fn_block(decl, body, cap_clause) {
+ expr_fn_block(decl, body, cap_clause) => {
v.visit_fn(fk_fn_block(cap_clause), decl, body,
ex.span, ex.id, e, v);
}
- expr_block(b) { v.visit_block(b, e, v); }
- expr_assign(a, b) { v.visit_expr(b, e, v); v.visit_expr(a, e, v); }
- expr_copy(a) { v.visit_expr(a, e, v); }
- expr_unary_move(a) { v.visit_expr(a, e, v); }
- expr_move(a, b) { v.visit_expr(b, e, v); v.visit_expr(a, e, v); }
- expr_swap(a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); }
- expr_assign_op(_, a, b) {
+ expr_block(b) => v.visit_block(b, e, v),
+ expr_assign(a, b) => { v.visit_expr(b, e, v); v.visit_expr(a, e, v); }
+ expr_copy(a) => v.visit_expr(a, e, v),
+ expr_unary_move(a) => v.visit_expr(a, e, v),
+ expr_move(a, b) => { v.visit_expr(b, e, v); v.visit_expr(a, e, v); }
+ expr_swap(a, b) => { v.visit_expr(a, e, v); v.visit_expr(b, e, v); }
+ expr_assign_op(_, a, b) => {
v.visit_expr(b, e, v);
v.visit_expr(a, e, v);
}
- expr_field(x, _, tys) {
+ expr_field(x, _, tys) => {
v.visit_expr(x, e, v);
for tys.each |tp| { v.visit_ty(tp, e, v); }
}
- expr_index(a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); }
- expr_path(p) { visit_path(p, e, v); }
- expr_fail(eo) { visit_expr_opt(eo, e, v); }
- expr_break { }
- expr_again { }
- expr_ret(eo) { visit_expr_opt(eo, e, v); }
- expr_log(_, lv, x) {
+ expr_index(a, b) => { v.visit_expr(a, e, v); v.visit_expr(b, e, v); }
+ expr_path(p) => visit_path(p, e, v),
+ expr_fail(eo) => visit_expr_opt(eo, e, v),
+ expr_break => (),
+ expr_again => (),
+ expr_ret(eo) => visit_expr_opt(eo, e, v),
+ expr_log(_, lv, x) => {
v.visit_expr(lv, e, v);
v.visit_expr(x, e, v);
}
- expr_mac(mac) { visit_mac(mac, e, v); }
+ expr_mac(mac) => visit_mac(mac, e, v),
}
v.visit_expr_post(ex, e, v);
}
fn mk_intermediate_name(output_path: ~str, extension: ~str) ->
~str unsafe {
let stem = alt str::find_char(output_path, '.') {
- some(dot_pos) { str::slice(output_path, 0u, dot_pos) }
- none { output_path }
+ some(dot_pos) => str::slice(output_path, 0u, dot_pos),
+ none => output_path
};
return stem + ~"." + extension;
}
if opts.save_temps {
alt opts.output_type {
- output_type_bitcode {
+ output_type_bitcode => {
if opts.optimize != 0u {
let filename = mk_intermediate_name(output, ~"no-opt.bc");
str::as_c_str(filename, |buf| {
});
}
}
- _ {
+ _ => {
let filename = mk_intermediate_name(output, ~"bc");
str::as_c_str(filename, |buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf)
let LLVMOptDefault = 2 as c_int; // -O2, -Os
let LLVMOptAggressive = 3 as c_int; // -O3
- let mut CodeGenOptLevel;
- alt check opts.optimize {
- 0u { CodeGenOptLevel = LLVMOptNone; }
- 1u { CodeGenOptLevel = LLVMOptLess; }
- 2u { CodeGenOptLevel = LLVMOptDefault; }
- 3u { CodeGenOptLevel = LLVMOptAggressive; }
- }
+ let mut CodeGenOptLevel = alt check opts.optimize {
+ 0u => LLVMOptNone,
+ 1u => LLVMOptLess,
+ 2u => LLVMOptDefault,
+ 3u => LLVMOptAggressive
+ };
let mut FileType;
if opts.output_type == output_type_object ||
for linkage_metas.each |meta| {
if *attr::get_meta_item_name(meta) == ~"name" {
alt attr::get_meta_item_value_str(meta) {
- some(v) { name = some(v); }
- none { vec::push(cmh_items, meta); }
+ some(v) => { name = some(v); }
+ none => vec::push(cmh_items, meta)
}
} else if *attr::get_meta_item_name(meta) == ~"vers" {
alt attr::get_meta_item_value_str(meta) {
- some(v) { vers = some(v); }
- none { vec::push(cmh_items, meta); }
+ some(v) => { vers = some(v); }
+ none => vec::push(cmh_items, meta)
}
} else { vec::push(cmh_items, meta); }
}
for cmh_items.each |m_| {
let m = m_;
alt m.node {
- ast::meta_name_value(key, value) {
+ ast::meta_name_value(key, value) => {
symbol_hasher.write_str(len_and_str(*key));
symbol_hasher.write_str(len_and_str_lit(value));
}
- ast::meta_word(name) {
+ ast::meta_word(name) => {
symbol_hasher.write_str(len_and_str(*name));
}
- ast::meta_list(_, _) {
+ ast::meta_list(_, _) => {
// FIXME (#607): Implement this
fail ~"unimplemented meta_item variant";
}
fn crate_meta_name(sess: session, _crate: ast::crate,
output: ~str, metas: provided_metas) -> @~str {
return alt metas.name {
- some(v) { v }
- none {
+ some(v) => v,
+ none => {
let name =
{
let mut os =
fn crate_meta_vers(sess: session, _crate: ast::crate,
metas: provided_metas) -> @~str {
return alt metas.vers {
- some(v) { v }
- none {
+ some(v) => v,
+ none => {
let vers = ~"0.0";
warn_missing(sess, ~"vers", vers);
@vers
fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> ~str {
alt ccx.type_hashcodes.find(t) {
- some(h) { return h; }
- none {
+ some(h) => return h,
+ none => {
let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta);
ccx.type_hashcodes.insert(t, hash);
return hash;
let mut result = ~"";
do str::chars_iter(s) |c| {
alt c {
- '@' { result += ~"_sbox_"; }
- '~' { result += ~"_ubox_"; }
- '*' { result += ~"_ptr_"; }
- '&' { result += ~"_ref_"; }
- ',' { result += ~"_"; }
+ '@' => result += ~"_sbox_",
+ '~' => result += ~"_ubox_",
+ '*' => result += ~"_ptr_",
+ '&' => result += ~"_ref_",
+ ',' => result += ~"_",
- '{' | '(' { result += ~"_of_"; }
+ '{' | '(' => result += ~"_of_",
'a' to 'z'
| 'A' to 'Z'
| '0' to '9'
- | '_' { str::push_char(result,c); }
- _ {
+ | '_' => str::push_char(result,c),
+ _ => {
if c > 'z' && char::is_XID_continue(c) {
str::push_char(result,c);
}
let mut n = ~"_ZN"; // Begin name-sequence.
for ss.each |s| {
- alt s { path_name(s) | path_mod(s) {
+ alt s { path_name(s) | path_mod(s) => {
let sani = sanitize(*s);
n += fmt!{"%u%s", str::len(sani), sani};
} }
return str::connect(parts, ~".");
}
return alt config.os {
- session::os_macos { rmext(rmlib(filename)) }
- session::os_linux { rmext(rmlib(filename)) }
- session::os_freebsd { rmext(rmlib(filename)) }
- _ { rmext(filename) }
+ session::os_macos => rmext(rmlib(filename)),
+ session::os_linux => rmext(rmlib(filename)),
+ session::os_freebsd => rmext(rmlib(filename)),
+ _ => rmext(filename)
};
}
pure fn not_win32(os: session::os) -> bool {
alt os {
- session::os_win32 { false }
- _ { true }
+ session::os_win32 => false,
+ _ => true
}
}
// Mac doesn't appear to support $ORIGIN
let prefix = alt os {
- session::os_linux { ~"$ORIGIN" + path::path_sep() }
- session::os_freebsd { ~"$ORIGIN" + path::path_sep() }
- session::os_macos { ~"@executable_path" + path::path_sep() }
- session::os_win32 { core::unreachable(); }
+ session::os_linux => ~"$ORIGIN" + path::path_sep(),
+ session::os_freebsd => ~"$ORIGIN" + path::path_sep(),
+ session::os_macos => ~"@executable_path" + path::path_sep(),
+ session::os_win32 => core::unreachable()
};
prefix + get_relative_to(
meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)),
data_layout: alt target_os {
- session::os_macos {
+ session::os_macos => {
~"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16" +
~"-i32:32:32-i64:32:64" +
~"-f32:32:32-f64:32:64-v64:64:64" +
~"-v128:128:128-a0:0:64-f80:128:128" + ~"-n8:16:32"
}
- session::os_win32 {
+ session::os_win32 => {
~"e-p:32:32-f64:64:64-i64:64:64-f80:32:32-n8:16:32"
}
- session::os_linux {
+ session::os_linux => {
~"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32"
}
- session::os_freebsd {
+ session::os_freebsd => {
~"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32"
}
},
target_triple: alt target_os {
- session::os_macos { ~"i686-apple-darwin" }
- session::os_win32 { ~"i686-pc-mingw32" }
- session::os_linux { ~"i686-unknown-linux-gnu" }
- session::os_freebsd { ~"i686-unknown-freebsd" }
+ session::os_macos => ~"i686-apple-darwin",
+ session::os_win32 => ~"i686-pc-mingw32",
+ session::os_linux => ~"i686-unknown-linux-gnu",
+ session::os_freebsd => ~"i686-unknown-freebsd"
},
cc_args: ~[~"-m32"]
meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)),
data_layout: alt target_os {
- session::os_macos {
+ session::os_macos => {
~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+
~"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
~"s0:64:64-f80:128:128-n8:16:32:64"
}
- session::os_win32 {
+ session::os_win32 => {
// FIXME: Test this. Copied from linux (#2398)
~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+
~"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
~"s0:64:64-f80:128:128-n8:16:32:64-S128"
}
- session::os_linux {
+ session::os_linux => {
~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+
~"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
~"s0:64:64-f80:128:128-n8:16:32:64-S128"
}
- session::os_freebsd {
+ session::os_freebsd => {
~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+
~"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
~"s0:64:64-f80:128:128-n8:16:32:64-S128"
},
target_triple: alt target_os {
- session::os_macos { ~"x86_64-apple-darwin" }
- session::os_win32 { ~"x86_64-pc-mingw32" }
- session::os_linux { ~"x86_64-unknown-linux-gnu" }
- session::os_freebsd { ~"x86_64-unknown-freebsd" }
+ session::os_macos => ~"x86_64-apple-darwin",
+ session::os_win32 => ~"x86_64-pc-mingw32",
+ session::os_linux => ~"x86_64-unknown-linux-gnu",
+ session::os_freebsd => ~"x86_64-unknown-freebsd",
},
cc_args: ~[~"-m64"]
fn source_name(input: input) -> ~str {
alt input {
- file_input(ifile) { ifile }
- str_input(_) { anon_src() }
+ file_input(ifile) => ifile,
+ str_input(_) => anon_src()
}
}
fn default_configuration(sess: session, argv0: ~str, input: input) ->
ast::crate_cfg {
let libc = alt sess.targ_cfg.os {
- session::os_win32 { ~"msvcrt.dll" }
- session::os_macos { ~"libc.dylib" }
- session::os_linux { ~"libc.so.6" }
- session::os_freebsd { ~"libc.so.7" }
+ session::os_win32 => ~"msvcrt.dll",
+ session::os_macos => ~"libc.dylib",
+ session::os_linux => ~"libc.so.6",
+ session::os_freebsd => ~"libc.so.7"
// _ { "libc.so" }
};
let mk = attr::mk_name_value_item_str;
let (arch,wordsz) = alt sess.targ_cfg.arch {
- session::arch_x86 { (~"x86",~"32") }
- session::arch_x86_64 { (~"x86_64",~"64") }
- session::arch_arm { (~"arm",~"32") }
+ session::arch_x86 => (~"x86",~"32"),
+ session::arch_x86_64 => (~"x86_64",~"64"),
+ session::arch_arm => (~"arm",~"32")
};
return ~[ // Target bindings.
fn parse_input(sess: session, cfg: ast::crate_cfg, input: input)
-> @ast::crate {
alt input {
- file_input(file) {
+ file_input(file) => {
parse::parse_crate_from_file(file, cfg, sess.parse_sess)
}
- str_input(src) {
+ str_input(src) => {
// FIXME (#2319): Don't really want to box the source string
parse::parse_crate_from_source_str(
anon_src(), @src, cfg, sess.parse_sess)
fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input,
ppm: pp_mode) {
fn ann_paren_for_expr(node: pprust::ann_node) {
- alt node { pprust::node_expr(s, expr) { pprust::popen(s); } _ { } }
+ alt node {
+ pprust::node_expr(s, expr) => pprust::popen(s),
+ _ => ()
+ }
}
fn ann_typed_post(tcx: ty::ctxt, node: pprust::ann_node) {
alt node {
- pprust::node_expr(s, expr) {
+ pprust::node_expr(s, expr) => {
pp::space(s.s);
pp::word(s.s, ~"as");
pp::space(s.s);
pp::word(s.s, ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr)));
pprust::pclose(s);
}
- _ { }
+ _ => ()
}
}
fn ann_identified_post(node: pprust::ann_node) {
alt node {
- pprust::node_item(s, item) {
+ pprust::node_item(s, item) => {
pp::space(s.s);
pprust::synth_comment(s, int::to_str(item.id, 10u));
}
- pprust::node_block(s, blk) {
+ pprust::node_block(s, blk) => {
pp::space(s.s);
pprust::synth_comment(s,
~"block " + int::to_str(blk.node.id, 10u));
}
- pprust::node_expr(s, expr) {
+ pprust::node_expr(s, expr) => {
pp::space(s.s);
pprust::synth_comment(s, int::to_str(expr.id, 10u));
pprust::pclose(s);
}
- pprust::node_pat(s, pat) {
+ pprust::node_pat(s, pat) => {
pp::space(s.s);
pprust::synth_comment(s, ~"pat " + int::to_str(pat.id, 10u));
}
// from stdin, we're going to just suck the source into a string
// so both the parser and pretty-printer can use it.
let upto = alt ppm {
- ppm_expanded | ppm_expanded_identified { cu_expand }
- ppm_typed { cu_typeck }
- _ { cu_parse }
+ ppm_expanded | ppm_expanded_identified => cu_expand,
+ ppm_typed => cu_typeck,
+ _ => cu_parse
};
let {crate, tcx} = compile_upto(sess, cfg, input, upto, none);
let ann = alt ppm {
- ppm_typed {
+ ppm_typed => {
{pre: ann_paren_for_expr,
post: |a| ann_typed_post(option::get(tcx), a) }
}
- ppm_identified | ppm_expanded_identified {
+ ppm_identified | ppm_expanded_identified => {
{pre: ann_paren_for_expr, post: ann_identified_post}
}
- ppm_expanded | ppm_normal { pprust::no_ann() }
+ ppm_expanded | ppm_normal => pprust::no_ann()
};
let is_expanded = upto != cu_parse;
let src = codemap::get_filemap(sess.codemap, source_name(input)).src;
fn build_target_config(sopts: @session::options,
demitter: diagnostic::emitter) -> @session::config {
let os = alt get_os(sopts.target_triple) {
- some(os) { os }
- none { early_error(demitter, ~"unknown operating system") }
+ some(os) => os,
+ none => early_error(demitter, ~"unknown operating system")
};
let arch = alt get_arch(sopts.target_triple) {
- some(arch) { arch }
- none { early_error(demitter,
- ~"unknown architecture: " + sopts.target_triple) }
+ some(arch) => arch,
+ none => early_error(demitter,
+ ~"unknown architecture: " + sopts.target_triple)
};
let (int_type, uint_type, float_type) = alt arch {
- session::arch_x86 {(ast::ty_i32, ast::ty_u32, ast::ty_f64)}
- session::arch_x86_64 {(ast::ty_i64, ast::ty_u64, ast::ty_f64)}
- session::arch_arm {(ast::ty_i32, ast::ty_u32, ast::ty_f64)}
+ session::arch_x86 => (ast::ty_i32, ast::ty_u32, ast::ty_f64),
+ session::arch_x86_64 => (ast::ty_i64, ast::ty_u64, ast::ty_f64),
+ session::arch_arm => (ast::ty_i32, ast::ty_u32, ast::ty_f64)
};
let target_strs = alt arch {
- session::arch_x86 {x86::get_target_strs(os)}
- session::arch_x86_64 {x86_64::get_target_strs(os)}
- session::arch_arm {x86::get_target_strs(os)}
+ session::arch_x86 => x86::get_target_strs(os),
+ session::arch_x86_64 => x86_64::get_target_strs(os),
+ session::arch_arm => x86::get_target_strs(os)
};
let target_cfg: @session::config =
@{os: os, arch: arch, target_strs: target_strs, int_type: int_type,
for flags.each |lint_name| {
let lint_name = str::replace(lint_name, ~"-", ~"_");
alt lint_dict.find(lint_name) {
- none {
+ none => {
early_error(demitter, fmt!{"unknown %s flag: %s",
level_name, lint_name});
}
- some(lint) {
+ some(lint) => {
vec::push(lint_opts, (lint.lint, level));
}
}
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; }
+ link::output_type_llvm_assembly | link::output_type_assembly => (),
+ _ => debugging_opts |= session::no_asm_comments
}
let opt_level: uint =
if opt_present(matches, ~"O") {
2u
} else if opt_present(matches, ~"opt-level") {
alt getopts::opt_str(matches, ~"opt-level") {
- ~"0" { 0u }
- ~"1" { 1u }
- ~"2" { 2u }
- ~"3" { 3u }
- _ {
+ ~"0" => 0u,
+ ~"1" => 1u,
+ ~"2" => 2u,
+ ~"3" => 3u,
+ _ => {
early_error(demitter, ~"optimization level needs " +
~"to be between 0-3")
}
} else { 0u };
let target =
alt target_opt {
- none { host_triple() }
- some(s) { s }
+ none => host_triple(),
+ some(s) => s
};
let addl_lib_search_paths = getopts::opt_strs(matches, ~"L");
let obj_suffix =
alt sopts.output_type {
- link::output_type_none { ~"none" }
- link::output_type_bitcode { ~"bc" }
- link::output_type_assembly { ~"s" }
- link::output_type_llvm_assembly { ~"ll" }
+ link::output_type_none => ~"none",
+ link::output_type_bitcode => ~"bc",
+ link::output_type_assembly => ~"s",
+ link::output_type_llvm_assembly => ~"ll",
// Object and exe output both use the '.o' extension here
- link::output_type_object | link::output_type_exe {
- ~"o"
- }
+ link::output_type_object | link::output_type_exe => ~"o"
};
alt ofile {
- none {
+ none => {
// "-" as input file will cause the parser to read from stdin so we
// have to make up a name
// We want to toss everything after the final '.'
let dirname = alt odir {
- some(d) { d }
- none {
- alt input {
- str_input(_) {
- os::getcwd()
- }
- file_input(ifile) {
- path::dirname(ifile)
- }
- }
+ some(d) => d,
+ none => alt input {
+ str_input(_) => os::getcwd(),
+ file_input(ifile) => path::dirname(ifile)
}
};
let base_filename = alt input {
- file_input(ifile) {
+ file_input(ifile) => {
let (path, _) = path::splitext(ifile);
path::basename(path)
}
- str_input(_) {
- ~"rust_out"
- }
+ str_input(_) => ~"rust_out"
};
let base_path = path::connect(dirname, base_filename);
}
}
- some(out_file) {
+ some(out_file) => {
out_path = out_file;
obj_path = if stop_after_codegen {
out_file
fn test_switch_implies_cfg_test() {
let matches =
alt getopts::getopts(~[~"--test"], opts()) {
- ok(m) { m }
- err(f) { fail ~"test_switch_implies_cfg_test: " +
- getopts::fail_str(f); }
+ ok(m) => m,
+ err(f) => fail ~"test_switch_implies_cfg_test: " +
+ getopts::fail_str(f)
};
let sessopts = build_session_options(matches, diagnostic::emit);
let sess = build_session(sessopts, diagnostic::emit);
fn test_switch_implies_cfg_test_unless_cfg_test() {
let matches =
alt getopts::getopts(~[~"--test", ~"--cfg=test"], opts()) {
- ok(m) { m }
- err(f) {
+ ok(m) => m,
+ err(f) => {
fail ~"test_switch_implies_cfg_test_unless_cfg_test: " +
getopts::fail_str(f);
}
io::println(fmt!{" %s %7.7s %s",
padded(max_key, k),
alt v.default {
- lint::allow { ~"allow" }
- lint::warn { ~"warn" }
- lint::deny { ~"deny" }
- lint::forbid { ~"forbid" }
+ lint::allow => ~"allow",
+ lint::warn => ~"warn",
+ lint::deny => ~"deny",
+ lint::forbid => ~"forbid"
},
v.desc});
}
let matches =
alt getopts::getopts(args, opts()) {
- ok(m) { m }
- err(f) {
+ ok(m) => m,
+ err(f) => {
early_error(demitter, getopts::fail_str(f))
}
};
return;
}
let input = alt vec::len(matches.free) {
- 0u { early_error(demitter, ~"no input filename given") }
- 1u {
+ 0u => early_error(demitter, ~"no input filename given"),
+ 1u => {
let ifile = matches.free[0];
if ifile == ~"-" {
let src = str::from_bytes(io::stdin().read_whole_stream());
file_input(ifile)
}
}
- _ { early_error(demitter, ~"multiple input filenames provided") }
+ _ => early_error(demitter, ~"multiple input filenames provided")
};
let sopts = build_session_options(matches, demitter);
~"normal"),
|a| parse_pretty(sess, a) );
alt pretty {
- some::<pp_mode>(ppm) {
+ some::<pp_mode>(ppm) => {
pretty_print_input(sess, cfg, input, ppm);
return;
}
- none::<pp_mode> {/* continue */ }
+ none::<pp_mode> => {/* continue */ }
}
let ls = opt_present(matches, ~"ls");
if ls {
alt input {
- file_input(ifile) {
+ file_input(ifile) => {
list_metadata(sess, ifile, io::stdout());
}
- str_input(_) {
+ str_input(_) => {
early_error(demitter, ~"can not list metadata for stdin");
}
}
f(demitter)
} {
- result::ok(_) { /* fallthrough */ }
- result::err(_) {
+ result::ok(_) => { /* fallthrough */ }
+ result::err(_) => {
// Task failed without emitting a fatal diagnostic
if comm::recv(p) == done {
diagnostic::emit(
fn span_lint_level(level: lint::level,
sp: span, msg: ~str) {
alt level {
- lint::allow { }
- lint::warn { self.span_warn(sp, msg); }
- lint::deny | lint::forbid {
+ lint::allow => { },
+ lint::warn => self.span_warn(sp, msg),
+ lint::deny | lint::forbid => {
self.span_err(sp, msg);
}
}
fn building_library(req_crate_type: crate_type, crate: @ast::crate,
testing: bool) -> bool {
alt req_crate_type {
- bin_crate { false }
- lib_crate { true }
- unknown_crate {
+ bin_crate => false,
+ lib_crate => true,
+ unknown_crate => {
if testing {
false
} else {
alt syntax::attr::first_attr_value_str_by_name(
crate.node.attrs,
~"crate_type") {
- option::some(@~"lib") { true }
- _ { false }
+ option::some(@~"lib") => true,
+ _ => false
}
}
}
import metadata::loader;
alt os {
- os_win32 { loader::os_win32 }
- os_linux { loader::os_linux }
- os_macos { loader::os_macos }
- os_freebsd { loader::os_freebsd }
+ os_win32 => loader::os_win32,
+ os_linux => loader::os_linux,
+ os_macos => loader::os_macos,
+ os_freebsd => loader::os_freebsd
}
}
fn filter_stmt(cx: ctxt, &&stmt: @ast::stmt) ->
option<@ast::stmt> {
alt stmt.node {
- ast::stmt_decl(decl, _) {
+ ast::stmt_decl(decl, _) => {
alt decl.node {
- ast::decl_item(item) {
+ ast::decl_item(item) => {
if item_in_cfg(cx, item) {
option::some(stmt)
} else { option::none }
}
- _ { option::some(stmt) }
+ _ => option::some(stmt)
}
}
- _ { option::some(stmt) }
+ _ => option::some(stmt)
}
}
sess.parse_sess);
let item =
alt item {
- some(i) { i }
- none {
+ some(i) => i,
+ none => {
sess.fatal(~"no item found in intrinsic module");
}
};
// indicate to the translation pass which function we want to be main.
fn nomain(&&item: @ast::item) -> option<@ast::item> {
alt item.node {
- ast::item_fn(_, _, _) {
+ ast::item_fn(_, _, _) => {
if *item.ident == ~"main" {
option::none
} else { option::some(item) }
}
- _ { option::some(item) }
+ _ => option::some(item)
}
}
if is_test_fn(i) {
alt i.node {
- ast::item_fn(decl, _, _) if decl.purity == ast::unsafe_fn {
+ ast::item_fn(decl, _, _) if decl.purity == ast::unsafe_fn => {
cx.sess.span_fatal(
i.span,
~"unsafe functions cannot be used for tests");
}
- _ {
+ _ => {
debug!{"this is a test function"};
let test = {span: i.span,
path: cx.path, ignore: is_ignored(cx, i),
fn has_test_signature(i: @ast::item) -> bool {
alt i.node {
- ast::item_fn(decl, tps, _) {
+ ast::item_fn(decl, tps, _) => {
let input_cnt = vec::len(decl.inputs);
let no_output = decl.output.node == ast::ty_nil;
let tparm_cnt = vec::len(tps);
input_cnt == 0u && no_output && tparm_cnt == 0u
}
- _ { false }
+ _ => false
}
}
let is_std = {
let items = attr::find_linkage_metas(cx.crate.node.attrs);
alt attr::last_meta_item_value_str_by_name(items, ~"name") {
- some(@~"std") { true }
- _ { false }
+ some(@~"std") => true,
+ _ => false
}
};
if is_std { path }
fn type_to_str_inner(names: type_names, outer0: ~[TypeRef], ty: TypeRef) ->
~str {
alt type_has_name(names, ty) {
- option::some(n) { return n; }
- _ {}
+ option::some(n) => return n,
+ _ => {}
}
let outer = vec::append_one(outer0, ty);
}
alt kind {
- Void { return ~"Void"; }
- Half { return ~"Half"; }
- Float { return ~"Float"; }
- Double { return ~"Double"; }
- X86_FP80 { return ~"X86_FP80"; }
- FP128 { return ~"FP128"; }
- PPC_FP128 { return ~"PPC_FP128"; }
- Label { return ~"Label"; }
- Integer {
+ Void => return ~"Void",
+ Half => return ~"Half",
+ Float => return ~"Float",
+ Double => return ~"Double",
+ X86_FP80 => return ~"X86_FP80",
+ FP128 => return ~"FP128",
+ PPC_FP128 => return ~"PPC_FP128",
+ Label => return ~"Label",
+ Integer => {
return ~"i" + int::str(llvm::LLVMGetIntTypeWidth(ty) as int);
}
- Function {
+ Function => {
let mut s = ~"fn(";
let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
let n_args = llvm::LLVMCountParamTypes(ty) as uint;
s += type_to_str_inner(names, outer, out_ty);
return s;
}
- Struct {
+ Struct => {
let mut s: ~str = ~"{";
let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint;
let elts = vec::from_elem(n_elts, 0 as TypeRef);
s += ~"}";
return s;
}
- Array {
+ Array => {
let el_ty = llvm::LLVMGetElementType(ty);
return ~"[" + type_to_str_inner(names, outer, el_ty) + ~" x " +
uint::str(llvm::LLVMGetArrayLength(ty) as uint) + ~"]";
}
- Pointer {
+ Pointer => {
let mut i: uint = 0u;
for outer0.each |tout| {
i += 1u;
return addrstr + ~"*" +
type_to_str_inner(names, outer, llvm::LLVMGetElementType(ty));
}
- Vector { return ~"Vector"; }
- Metadata { return ~"Metadata"; }
- X86_MMX { return ~"X86_MMAX"; }
+ Vector => return ~"Vector",
+ Metadata => return ~"Metadata",
+ X86_MMX => return ~"X86_MMAX"
}
}
fn float_width(llt: TypeRef) -> uint {
return alt llvm::LLVMGetTypeKind(llt) as int {
- 1 { 32u }
- 2 { 64u }
- 3 { 80u }
- 4 | 5 { 128u }
- _ { fail ~"llvm_float_width called on a non-float type" }
+ 1 => 32u,
+ 2 => 64u,
+ 3 => 80u,
+ 4 | 5 => 128u,
+ _ => fail ~"llvm_float_width called on a non-float type"
};
}
fn visit_view_item(e: env, i: @ast::view_item) {
alt i.node {
- ast::view_item_use(ident, meta_items, id) {
+ ast::view_item_use(ident, meta_items, id) => {
debug!{"resolving use stmt. ident: %?, meta: %?", ident, meta_items};
let cnum = resolve_crate(e, ident, meta_items, ~"", i.span);
cstore::add_use_stmt_cnum(e.cstore, id, cnum);
}
- _ { }
+ _ => ()
}
}
fn visit_item(e: env, i: @ast::item) {
alt i.node {
- ast::item_foreign_mod(m) {
+ ast::item_foreign_mod(m) => {
alt attr::foreign_abi(i.attrs) {
- either::right(abi) {
+ either::right(abi) => {
if abi != ast::foreign_abi_cdecl &&
abi != ast::foreign_abi_stdcall { return; }
}
- either::left(msg) { e.diag.span_fatal(i.span, msg); }
+ either::left(msg) => e.diag.span_fatal(i.span, msg)
}
let cstore = e.cstore;
let foreign_name =
alt attr::first_attr_value_str_by_name(i.attrs, ~"link_name") {
- some(nn) {
+ some(nn) => {
if *nn == ~"" {
e.diag.span_fatal(
i.span,
}
nn
}
- none { i.ident }
+ none => i.ident
};
let mut already_added = false;
if vec::len(attr::find_attrs_by_name(i.attrs, ~"nolink")) == 0u {
}
for link_args.each |a| {
alt attr::get_meta_item_value_str(attr::attr_meta(a)) {
- some(linkarg) {
+ some(linkarg) => {
cstore::add_used_link_args(cstore, *linkarg);
}
- none {/* fallthrough */ }
+ none => {/* fallthrough */ }
}
}
}
- _ { }
+ _ => { }
}
}
let metas = metas_with_ident(ident, metas);
alt existing_match(e, metas, hash) {
- none {
+ none => {
let load_ctxt: loader::ctxt = {
diag: e.diag,
filesearch: e.filesearch,
let cname =
alt attr::last_meta_item_value_str_by_name(metas, ~"name") {
- option::some(v) { v }
- option::none { ident }
+ option::some(v) => v,
+ option::none => ident
};
let cmeta = @{name: *cname, data: cdata,
cnum_map: cnum_map, cnum: cnum};
cstore::add_used_crate_file(cstore, cfilename);
return cnum;
}
- some(cnum) {
+ some(cnum) => {
return cnum;
}
}
debug!{"resolving dep crate %s ver: %s hash: %s",
*dep.name, *dep.vers, *dep.hash};
alt existing_match(e, metas_with_ident(cname, cmetas), *dep.hash) {
- some(local_cnum) {
+ some(local_cnum) => {
debug!{"already have it"};
// We've already seen this crate
cnum_map.insert(extrn_cnum, local_cnum);
}
- none {
+ none => {
debug!{"need to load it"};
// This is a new one so we've got to load it
// FIXME (#2404): Need better error reporting than just a bogus
-> ast::purity {
let cdata = cstore::get_crate_data(cstore, did.crate).data;
alt check decoder::lookup_def(did.crate, cdata, did) {
- ast::def_fn(_, p) { p }
+ ast::def_fn(_, p) => p
}
}
// Internal method to retrieve the data from the cstore
pure fn p(cstore: cstore) -> cstore_private {
- alt cstore { private(p) { p } }
+ alt cstore { private(p) => p }
}
fn mk_cstore() -> cstore {
fn lookup_item(item_id: int, data: @~[u8]) -> ebml::doc {
let items = ebml::get_doc(ebml::doc(data), tag_items);
alt maybe_find_item(item_id, items) {
- none { fail(fmt!{"lookup_item: id not found: %d", item_id}); }
- some(d) { d }
+ none => fail(fmt!{"lookup_item: id not found: %d", item_id}),
+ some(d) => d
}
}
ast::class_immutable,
|d| {
alt ebml::doc_as_u8(d) as char {
- 'm' { ast::class_mutable }
- _ { ast::class_immutable }
+ 'm' => ast::class_mutable,
+ _ => ast::class_immutable
}
})
}
fn item_ty_region_param(item: ebml::doc) -> bool {
alt ebml::maybe_get_doc(item, tag_region_param) {
- some(_) { true }
- none { false }
+ some(_) => true,
+ none => false
}
}
-> def_like {
let fam_ch = item_family(item);
alt fam_ch {
- 'c' { dl_def(ast::def_const(did)) }
- 'C' { dl_def(ast::def_class(did, true)) }
- 'S' { dl_def(ast::def_class(did, false)) }
- 'u' { dl_def(ast::def_fn(did, ast::unsafe_fn)) }
- 'f' { dl_def(ast::def_fn(did, ast::impure_fn)) }
- 'p' { dl_def(ast::def_fn(did, ast::pure_fn)) }
- 'F' { dl_def(ast::def_fn(did, ast::extern_fn)) }
- 'y' { dl_def(ast::def_ty(did)) }
- 't' { dl_def(ast::def_ty(did)) }
- 'm' { dl_def(ast::def_mod(did)) }
- 'n' { dl_def(ast::def_foreign_mod(did)) }
- 'v' {
+ 'c' => dl_def(ast::def_const(did)),
+ 'C' => dl_def(ast::def_class(did, true)),
+ 'S' => dl_def(ast::def_class(did, false)),
+ 'u' => dl_def(ast::def_fn(did, ast::unsafe_fn)),
+ 'f' => dl_def(ast::def_fn(did, ast::impure_fn)),
+ 'p' => dl_def(ast::def_fn(did, ast::pure_fn)),
+ 'F' => dl_def(ast::def_fn(did, ast::extern_fn)),
+ 'y' => dl_def(ast::def_ty(did)),
+ 't' => dl_def(ast::def_ty(did)),
+ 'm' => dl_def(ast::def_mod(did)),
+ 'n' => dl_def(ast::def_foreign_mod(did)),
+ 'v' => {
let mut tid = option::get(item_parent_item(item));
tid = {crate: cnum, node: tid.node};
dl_def(ast::def_variant(tid, did))
}
- 'I' { dl_def(ast::def_ty(did)) }
- 'i' { dl_impl(did) }
- 'g' | 'j' | 'N' => { dl_field }
- ch { fail fmt!{"unexpected family code: '%c'", ch} }
+ 'I' => dl_def(ast::def_ty(did)),
+ 'i' => dl_impl(did),
+ 'g' | 'j' | 'N' => dl_field,
+ ch => fail fmt!{"unexpected family code: '%c'", ch}
}
}
let items = ebml::get_doc(ebml::doc(cdata.data), tag_items);
let mut found = none;
let cls_items = alt maybe_find_item(id, items) {
- some(it) { it }
- none { fail (fmt!{"get_class_method: class id not found \
- when looking up method %s", *name}) }};
+ some(it) => it,
+ none => fail (fmt!{"get_class_method: class id not found \
+ when looking up method %s", *name})
+ };
for ebml::tagged_docs(cls_items, tag_item_trait_method) |mid| {
let m_did = class_member_id(mid, cdata);
if item_name(mid) == name {
}
}
alt found {
- some(found) { found }
- none { fail (fmt!{"get_class_method: no method named %s", *name}) }
+ some(found) => found,
+ none => fail (fmt!{"get_class_method: no method named %s", *name})
}
}
let items = ebml::get_doc(ebml::doc(cdata.data), tag_items);
let mut found = none;
let cls_items = alt maybe_find_item(id, items) {
- some(it) { it }
- none { fail (fmt!{"class_dtor: class id not found \
- when looking up dtor for %d", id}); }
+ some(it) => it,
+ none => fail (fmt!{"class_dtor: class id not found \
+ when looking up dtor for %d", id})
};
for ebml::tagged_docs(cls_items, tag_item_dtor) |doc| {
let doc1 = ebml::get_doc(doc, tag_def_id);
fn def_like_to_def(def_like: def_like) -> ast::def {
alt def_like {
- dl_def(def) { return def; }
- dl_impl(*) { fail ~"found impl in def_like_to_def"; }
- dl_field { fail ~"found field in def_like_to_def"; }
+ dl_def(def) => return def,
+ dl_impl(*) => fail ~"found impl in def_like_to_def",
+ dl_field => fail ~"found field in def_like_to_def"
}
}
// Get the item.
alt maybe_find_item(def_id.node, items) {
- none {
+ none => {
debug!{"(each_path) ignoring implicit item: %s",
*path};
}
- some(item_doc) {
+ some(item_doc) => {
// Construct the def for this item.
let def_like = item_to_def_like(item_doc, def_id,
cdata.cnum);
let item_doc = lookup_item(id, cdata.data);
let path = vec::init(item_path(item_doc));
alt decode_inlined_item(cdata, tcx, path, item_doc) {
- some(ii) { csearch::found(ii) }
- none {
+ some(ii) => csearch::found(ii),
+ none => {
alt item_parent_item(item_doc) {
- some(did) {
+ some(did) => {
let did = translate_def_id(cdata, did);
let parent_item = lookup_item(did.node, cdata.data);
alt decode_inlined_item(cdata, tcx, path,
parent_item) {
- some(ii) { csearch::found_parent(did, ii) }
- none { csearch::not_found }
+ some(ii) => csearch::found_parent(did, ii),
+ none => csearch::not_found
}
}
- none { csearch::not_found }
+ none => csearch::not_found
}
}
}
let name = item_name(item);
let mut arg_tys: ~[ty::t] = ~[];
alt ty::get(ctor_ty).struct {
- ty::ty_fn(f) {
+ ty::ty_fn(f) => {
for f.inputs.each |a| { vec::push(arg_tys, a.ty); }
}
- _ { /* Nullary enum variant. */ }
+ _ => { /* Nullary enum variant. */ }
}
alt variant_disr_val(item) {
- some(val) { disr_val = val; }
- _ { /* empty */ }
+ some(val) => { disr_val = val; }
+ _ => { /* empty */ }
}
vec::push(infos, @{args: arg_tys, ctor_ty: ctor_ty, name: name,
id: did, disr_val: disr_val});
let impl_data = impl_cdata.data;
let item = lookup_item(local_did.node, impl_data);
let nm = item_name(item);
- if alt name { some(n) { n == nm } none { true } } {
+ if alt name { some(n) => { n == nm } none => { true } } {
let base_tps = item_ty_param_count(item);
vec::push(result, @{
did: local_did, ident: nm,
let bounds = item_ty_param_bounds(mth, tcx, cdata);
let name = item_name(mth);
let ty = doc_type(mth, tcx, cdata);
- let fty = alt ty::get(ty).struct { ty::ty_fn(f) { f }
- _ {
+ let fty = alt ty::get(ty).struct {
+ ty::ty_fn(f) => f,
+ _ => {
tcx.diag.handler().bug(
~"get_trait_methods: id has non-function type");
} };
vec::push(result, {ident: name, tps: bounds, fty: fty,
self_ty: self_ty,
purity: alt check item_family(mth) {
- 'u' { ast::unsafe_fn }
- 'f' { ast::impure_fn }
- 'p' { ast::pure_fn }
+ 'u' => ast::unsafe_fn,
+ 'f' => ast::impure_fn,
+ 'p' => ast::pure_fn
}, vis: ast::public});
}
@result
fn family_has_type_params(fam_ch: char) -> bool {
alt check fam_ch {
- 'c' | 'T' | 'm' | 'n' | 'g' | 'h' | 'j' { false }
+ 'c' | 'T' | 'm' | 'n' | 'g' | 'h' | 'j' => false,
'f' | 'u' | 'p' | 'F' | 'U' | 'P' | 'y' | 't' | 'v' | 'i' | 'I' | 'C'
| 'a' | 'S'
- { true }
+ => true
}
}
fn family_names_type(fam_ch: char) -> bool {
- alt fam_ch { 'y' | 't' | 'I' { true } _ { false } }
+ alt fam_ch { 'y' | 't' | 'I' => true, _ => false }
}
fn read_path(d: ebml::doc) -> {path: ~str, pos: uint} {
fn describe_def(items: ebml::doc, id: ast::def_id) -> ~str {
if id.crate != ast::local_crate { return ~"external"; }
let it = alt maybe_find_item(id.node, items) {
- some(it) { it }
- none { fail (fmt!{"describe_def: item not found %?", id}); }
+ some(it) => it,
+ none => fail (fmt!{"describe_def: item not found %?", id})
};
return item_family_to_str(item_family(it));
}
fn item_family_to_str(fam: char) -> ~str {
alt check fam {
- 'c' { return ~"const"; }
- 'f' { return ~"fn"; }
- 'u' { return ~"unsafe fn"; }
- 'p' { return ~"pure fn"; }
- 'F' { return ~"foreign fn"; }
- 'U' { return ~"unsafe foreign fn"; }
- 'P' { return ~"pure foreign fn"; }
- 'y' { return ~"type"; }
- 'T' { return ~"foreign type"; }
- 't' { return ~"type"; }
- 'm' { return ~"mod"; }
- 'n' { return ~"foreign mod"; }
- 'v' { return ~"enum"; }
- 'i' { return ~"impl"; }
- 'I' { return ~"trait"; }
- 'C' { return ~"class"; }
- 'S' { return ~"struct"; }
- 'g' { return ~"public field"; }
- 'j' { return ~"private field"; }
- 'N' { return ~"inherited field"; }
+ 'c' => return ~"const",
+ 'f' => return ~"fn",
+ 'u' => return ~"unsafe fn",
+ 'p' => return ~"pure fn",
+ 'F' => return ~"foreign fn",
+ 'U' => return ~"unsafe foreign fn",
+ 'P' => return ~"pure foreign fn",
+ 'y' => return ~"type",
+ 'T' => return ~"foreign type",
+ 't' => return ~"type",
+ 'm' => return ~"mod",
+ 'n' => return ~"foreign mod",
+ 'v' => return ~"enum",
+ 'i' => return ~"impl",
+ 'I' => return ~"trait",
+ 'C' => return ~"class",
+ 'S' => return ~"struct",
+ 'g' => return ~"public field",
+ 'j' => return ~"private field",
+ 'N' => return ~"inherited field"
}
}
fn get_attributes(md: ebml::doc) -> ~[ast::attribute] {
let mut attrs: ~[ast::attribute] = ~[];
alt ebml::maybe_get_doc(md, tag_attributes) {
- option::some(attrs_d) {
+ option::some(attrs_d) => {
for ebml::tagged_docs(attrs_d, tag_attribute) |attr_doc| {
let meta_items = get_meta_items(attr_doc);
// Currently it's only possible to have a single meta item on
span: ast_util::dummy_sp()});
};
}
- option::none { }
+ option::none => ()
}
return attrs;
}
let attrs = decoder::get_crate_attributes(data);
return alt attr::last_meta_item_value_str_by_name(
attr::find_linkage_metas(attrs), ~"vers") {
- some(ver) { ver }
- none { @~"0.0" }
+ some(ver) => ver,
+ none => @~"0.0"
};
}
}
alt cdata.cnum_map.find(did.crate) {
- option::some(n) { return {crate: n, node: did.node}; }
- option::none { fail ~"didn't find a crate in the cnum_map"; }
+ option::some(n) => return {crate: n, node: did.node},
+ option::none => fail ~"didn't find a crate in the cnum_map"
}
}
fn encode_mutability(ebml_w: ebml::writer, mt: class_mutability) {
do ebml_w.wr_tag(tag_class_mut) {
- ebml_w.writer.write(&[alt mt { class_immutable { 'i' }
- class_mutable { 'm' } } as u8]);
- }
+ let val = alt mt {
+ class_immutable => 'i',
+ class_mutable => 'm'
+ };
+ ebml_w.writer.write(&[val as u8]);
+ }
}
type entry<T> = {val: T, pos: uint};
items: ~[@class_member], path: ~[ident], &index: ~[entry<~str>]) {
for items.each |it| {
alt ast_util::class_member_visibility(it) {
- private { again; }
- public | inherited {
+ private => again,
+ public | inherited => {
let (id, ident) = alt it.node {
- instance_var(v, _, _, vid, _) { (vid, v) }
- class_method(it) { (it.id, it.ident) }
+ instance_var(v, _, _, vid, _) => (vid, v),
+ class_method(it) => (it.id, it.ident)
};
add_to_index(ebml_w, path, index, ident);
encode_named_def_id(ebml_w, ident, local_def(id));
add_to_index(ebml_w, path, index, it.ident);
}
alt it.node {
- item_const(_, _) {
+ item_const(_, _) => {
encode_named_def_id(ebml_w, it.ident, local_def(it.id));
}
- item_fn(_, tps, _) {
+ item_fn(_, tps, _) => {
encode_named_def_id(ebml_w, it.ident, local_def(it.id));
}
- item_mod(_mod) {
+ item_mod(_mod) => {
do ebml_w.wr_tag(tag_paths_data_mod) {
encode_name_and_def_id(ebml_w, it.ident, it.id);
encode_module_item_paths(ebml_w, ecx, _mod,
index);
}
}
- item_foreign_mod(nmod) {
+ item_foreign_mod(nmod) => {
do ebml_w.wr_tag(tag_paths_data_mod) {
encode_name_and_def_id(ebml_w, it.ident, it.id);
encode_foreign_module_item_paths(
vec::append_one(path, it.ident), index);
}
}
- item_ty(_, tps) {
+ item_ty(_, tps) => {
do ebml_w.wr_tag(tag_paths_data_item) {
encode_name_and_def_id(ebml_w, it.ident, it.id);
}
}
- item_class(_, _, items, m_ctor, m_dtor) {
+ item_class(_, _, items, m_ctor, m_dtor) => {
do ebml_w.wr_tag(tag_paths_data_item) {
encode_name_and_def_id(ebml_w, it.ident, it.id);
}
none => {
// Nothing to do.
}
- some(ctor) {
+ some(ctor) => {
encode_named_def_id(ebml_w, it.ident,
local_def(ctor.node.id));
}
index);
}
}
- item_enum(variants, _) {
+ item_enum(variants, _) => {
do ebml_w.wr_tag(tag_paths_data_item) {
encode_name_and_def_id(ebml_w, it.ident, it.id);
}
encode_enum_variant_paths(ebml_w, variants, path, index);
}
- item_trait(*) {
+ item_trait(*) => {
do ebml_w.wr_tag(tag_paths_data_item) {
encode_name_and_def_id(ebml_w, it.ident, it.id);
}
}
- item_impl(*) {}
- item_mac(*) { fail ~"item macros unimplemented" }
+ item_impl(*) => {}
+ item_mac(*) => fail ~"item macros unimplemented"
}
}
}
fn encode_symbol(ecx: @encode_ctxt, ebml_w: ebml::writer, id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol);
let sym = alt ecx.item_symbols.find(id) {
- some(x) { x }
- none {
+ some(x) => x,
+ none => {
ecx.diag.handler().bug(
fmt!{"encode_symbol: id not found %d", id});
}
name: ast_map::path_elt) {
fn encode_path_elt(ebml_w: ebml::writer, elt: ast_map::path_elt) {
let (tag, name) = alt elt {
- ast_map::path_mod(name) { (tag_path_elt_mod, name) }
- ast_map::path_name(name) { (tag_path_elt_name, name) }
+ ast_map::path_mod(name) => (tag_path_elt_mod, name),
+ ast_map::path_name(name) => (tag_path_elt_name, name)
};
ebml_w.wr_tagged_str(tag, *name);
ebml_w.start_tag(tag_mod_impl);
alt ecx.tcx.items.find(did.node) {
- some(ast_map::node_item(it@@{node: cl@item_class(*),_},_)) {
+ some(ast_map::node_item(it@@{node: cl@item_class(*),_},_)) => {
/* If did stands for a trait
ref, we need to map it to its parent class */
ebml_w.wr_str(def_to_str(local_def(it.id)));
}
- _ {
+ _ => {
// Must be a re-export, then!
// ...or a trait ref
ebml_w.wr_str(def_to_str(did));
fn encode_visibility(ebml_w: ebml::writer, visibility: visibility) {
encode_family(ebml_w, alt visibility {
- public { 'g' } private { 'j' } inherited { 'N' }
+ public => 'g',
+ private => 'j',
+ inherited => 'N'
});
}
/* We encode both private and public fields -- need to include
private fields to get the offsets right */
alt ci.node {
- instance_var(nm, _, mt, id, vis) {
+ instance_var(nm, _, mt, id, vis) => {
vec::push(*index, {val: id, pos: ebml_w.writer.tell()});
vec::push(*global_index, {val: id, pos: ebml_w.writer.tell()});
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(id));
ebml_w.end_tag();
}
- class_method(m) {
+ class_method(m) => {
alt m.vis {
- public | inherited {
+ public | inherited => {
vec::push(*index, {val: m.id, pos: ebml_w.writer.tell()});
vec::push(*global_index,
{val: m.id, pos: ebml_w.writer.tell()});
should_inline(m.attrs), id, m,
vec::append(class_tps, m.tps));
}
- _ { /* don't encode private methods */ }
+ _ => { /* don't encode private methods */ }
}
}
}
encode_type(ecx, ebml_w, its_ty);
encode_path(ebml_w, path, ast_map::path_name(ident));
alt item {
- some(it) {
+ some(it) => {
ecx.encode_inlined_item(ecx, ebml_w, path, it);
}
- none {
+ none => {
encode_symbol(ecx, ebml_w, id);
}
}
fn purity_fn_family(p: purity) -> char {
alt p {
- unsafe_fn { 'u' }
- pure_fn { 'p' }
- impure_fn { 'f' }
- extern_fn { 'F' }
+ unsafe_fn => 'u',
+ pure_fn => 'p',
+ impure_fn => 'f',
+ extern_fn => 'F'
}
}
fn should_inline(attrs: ~[attribute]) -> bool {
alt attr::find_inline_attr(attrs) {
- attr::ia_none | attr::ia_never { false }
- attr::ia_hint | attr::ia_always { true }
+ attr::ia_none | attr::ia_never => false,
+ attr::ia_hint | attr::ia_always => true
}
}
let tcx = ecx.tcx;
let must_write =
alt item.node {
- item_enum(_, _) | item_impl(*) | item_trait(*) | item_class(*) {
- true
- }
- _ {
- false
- }
+ item_enum(_, _) | item_impl(*)
+ | item_trait(*) | item_class(*) => true,
+ _ => false
};
if !must_write && !reachable(ecx, item.id) { return; }
let add_to_index = |copy ebml_w| add_to_index_(item, ebml_w, index);
alt item.node {
- item_const(_, _) {
+ item_const(_, _) => {
add_to_index();
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
encode_path(ebml_w, path, ast_map::path_name(item.ident));
ebml_w.end_tag();
}
- item_fn(decl, tps, _) {
+ item_fn(decl, tps, _) => {
add_to_index();
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
}
ebml_w.end_tag();
}
- item_mod(m) {
+ item_mod(m) => {
add_to_index();
encode_info_for_mod(ecx, ebml_w, m, item.id, path, item.ident);
}
- item_foreign_mod(_) {
+ item_foreign_mod(_) => {
add_to_index();
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
encode_path(ebml_w, path, ast_map::path_name(item.ident));
ebml_w.end_tag();
}
- item_ty(_, tps) {
+ item_ty(_, tps) => {
add_to_index();
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
encode_region_param(ecx, ebml_w, item);
ebml_w.end_tag();
}
- item_enum(variants, tps) {
+ item_enum(variants, tps) => {
add_to_index();
do ebml_w.wr_tag(tag_items_data_item) {
encode_def_id(ebml_w, local_def(item.id));
encode_enum_variant_info(ecx, ebml_w, item.id, variants,
path, index, tps);
}
- item_class(tps, traits, items, ctor, m_dtor) {
+ item_class(tps, traits, items, ctor, m_dtor) => {
/* First, encode the fields and methods
These come first because we need to write them to make
the index, and the index needs to be in the item for the
encode_def_id(ebml_w, local_def(item.id));
alt ctor {
- none {
- encode_family(ebml_w, 'S');
- }
- some(_) {
- encode_family(ebml_w, 'C');
- }
+ none => encode_family(ebml_w, 'S'),
+ some(_) => encode_family(ebml_w, 'C')
}
encode_type_param_bounds(ebml_w, ecx, tps);
}
for ms.each |m| {
alt m.vis {
- private { /* do nothing */ }
- public | inherited {
+ private => { /* do nothing */ }
+ public | inherited => {
/* Write the info that's needed when viewing this class
as a trait */
ebml_w.start_tag(tag_item_trait_method);
encode_index(ebml_w, bkts, write_int);
ebml_w.end_tag();
}
- item_impl(tps, traits, _, methods) {
+ item_impl(tps, traits, _, methods) => {
add_to_index();
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
vec::append(tps, m.tps));
}
}
- item_trait(tps, traits, ms) {
+ item_trait(tps, traits, ms) => {
add_to_index();
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
let mut i = 0u;
for vec::each(*ty::trait_methods(tcx, local_def(item.id))) |mty| {
alt ms[i] {
- required(ty_m) {
+ required(ty_m) => {
ebml_w.start_tag(tag_item_trait_method);
encode_name(ebml_w, mty.ident);
encode_type_param_bounds(ebml_w, ecx, ty_m.tps);
encode_self_type(ebml_w, mty.self_ty);
ebml_w.end_tag();
}
- provided(m) {
+ provided(m) => {
encode_info_for_method(ecx, ebml_w, path,
should_inline(m.attrs), item.id,
m, m.tps);
}
ebml_w.end_tag();
}
- item_mac(*) { fail ~"item macros unimplemented" }
+ item_mac(*) => fail ~"item macros unimplemented"
}
}
ebml_w.start_tag(tag_items_data_item);
alt nitem.node {
- foreign_item_fn(fn_decl, tps) {
+ foreign_item_fn(fn_decl, tps) => {
encode_def_id(ebml_w, local_def(nitem.id));
encode_family(ebml_w, purity_fn_family(fn_decl.purity));
encode_type_param_bounds(ebml_w, ecx, tps);
visit_item: |i, cx, v, copy ebml_w| {
visit::visit_item(i, cx, v);
alt check ecx.tcx.items.get(i.id) {
- ast_map::node_item(_, pt) {
+ ast_map::node_item(_, pt) => {
encode_info_for_item(ecx, ebml_w, i, index, *pt);
/* encode ctor, then encode items */
alt i.node {
- item_class(tps, _, _, some(ctor), m_dtor) {
+ item_class(tps, _, _, some(ctor), m_dtor) => {
debug!{"encoding info for ctor %s %d", *i.ident,
ctor.node.id};
vec::push(*index, {
local_def(i.id))) }
else { none }, tps, ctor.node.dec);
}
- _ {}
+ _ => {}
}
}
}
visit_foreign_item: |ni, cx, v, copy ebml_w| {
visit::visit_foreign_item(ni, cx, v);
alt check ecx.tcx.items.get(ni.id) {
- ast_map::node_foreign_item(_, abi, pt) {
+ ast_map::node_foreign_item(_, abi, pt) => {
encode_info_for_foreign_item(ecx, ebml_w, ni,
index, *pt, abi);
}
fn encode_meta_item(ebml_w: ebml::writer, mi: meta_item) {
alt mi.node {
- meta_word(name) {
+ meta_word(name) => {
ebml_w.start_tag(tag_meta_item_word);
ebml_w.start_tag(tag_meta_item_name);
ebml_w.writer.write(str::bytes(*name));
ebml_w.end_tag();
ebml_w.end_tag();
}
- meta_name_value(name, value) {
+ meta_name_value(name, value) => {
alt value.node {
- lit_str(value) {
+ lit_str(value) => {
ebml_w.start_tag(tag_meta_item_name_value);
ebml_w.start_tag(tag_meta_item_name);
ebml_w.writer.write(str::bytes(*name));
ebml_w.end_tag();
ebml_w.end_tag();
}
- _ {/* FIXME (#623): encode other variants */ }
+ _ => {/* FIXME (#623): encode other variants */ }
}
}
- meta_list(name, items) {
+ meta_list(name, items) => {
ebml_w.start_tag(tag_meta_item_list);
ebml_w.start_tag(tag_meta_item_name);
ebml_w.writer.write(str::bytes(*name));
attr
} else {
alt attr.node.value.node {
- meta_list(n, l) {
+ meta_list(n, l) => {
found_link_attr = true;;
synthesize_link_attr(ecx, l)
}
- _ { attr }
+ _ => attr
}
});
}
vec::push(paths,
make_target_lib_path(self.sysroot, self.target_triple));
alt get_cargo_lib_path_nearest() {
- result::ok(p) { vec::push(paths, p) }
- result::err(p) { }
+ result::ok(p) => vec::push(paths, p),
+ result::err(p) => ()
}
alt get_cargo_lib_path() {
- result::ok(p) { vec::push(paths, p) }
- result::err(p) { }
+ result::ok(p) => vec::push(paths, p),
+ result::err(p) => ()
}
paths
}
fn get_default_sysroot() -> path {
alt os::self_exe_path() {
- option::some(p) { path::normalize(path::connect(p, ~"..")) }
- option::none {
- fail ~"can't determine value for sysroot";
- }
+ option::some(p) => path::normalize(path::connect(p, ~"..")),
+ option::none => fail ~"can't determine value for sysroot"
}
}
fn get_sysroot(maybe_sysroot: option<path>) -> path {
alt maybe_sysroot {
- option::some(sr) { sr }
- option::none { get_default_sysroot() }
+ option::some(sr) => sr,
+ option::none => get_default_sysroot()
}
}
fn get_cargo_root() -> result<path, ~str> {
alt os::getenv(~"CARGO_ROOT") {
- some(_p) { result::ok(_p) }
- none {
- alt os::homedir() {
- some(_q) { result::ok(path::connect(_q, ~".cargo")) }
- none { result::err(~"no CARGO_ROOT or home directory") }
- }
+ some(_p) => result::ok(_p),
+ none => alt os::homedir() {
+ some(_q) => result::ok(path::connect(_q, ~".cargo")),
+ none => result::err(~"no CARGO_ROOT or home directory")
}
}
}
fn load_library_crate(cx: ctxt) -> {ident: ~str, data: @~[u8]} {
alt find_library_crate(cx) {
- some(t) { return t; }
- none {
+ some(t) => return t,
+ none => {
cx.diag.span_fatal(
cx.span, fmt!{"can't find crate for `%s`", *cx.ident});
}
fn libname(cx: ctxt) -> {prefix: ~str, suffix: ~str} {
if cx.static { return {prefix: ~"lib", suffix: ~".rlib"}; }
alt cx.os {
- os_win32 { return {prefix: ~"", suffix: ~".dll"}; }
- os_macos { return {prefix: ~"lib", suffix: ~".dylib"}; }
- os_linux { return {prefix: ~"lib", suffix: ~".so"}; }
- os_freebsd { return {prefix: ~"lib", suffix: ~".so"}; }
+ os_win32 => return {prefix: ~"", suffix: ~".dll"},
+ os_macos => return {prefix: ~"lib", suffix: ~".dylib"},
+ os_linux => return {prefix: ~"lib", suffix: ~".so"},
+ os_freebsd => return {prefix: ~"lib", suffix: ~".so"}
}
}
} else {
debug!{"%s is a candidate", path};
alt get_metadata_section(cx.os, path) {
- option::some(cvec) {
+ option::some(cvec) => {
if !crate_matches(cvec, cx.metas, cx.hash) {
debug!{"skipping %s, metadata doesn't match", path};
option::none::<()>
option::none::<()>
}
}
- _ {
+ _ => {
debug!{"could not load metadata for %s", path};
option::none::<()>
}
fn crate_name_from_metas(metas: ~[@ast::meta_item]) -> @~str {
let name_items = attr::find_meta_items_by_name(metas, ~"name");
alt vec::last_opt(name_items) {
- some(i) {
+ some(i) => {
alt attr::get_meta_item_value_str(i) {
- some(n) { n }
+ some(n) => n,
// FIXME (#2406): Probably want a warning here since the user
// is using the wrong type of meta item.
- _ { fail }
+ _ => fail
}
}
- none { fail ~"expected to find the crate name" }
+ none => fail ~"expected to find the crate name"
}
}
});
if mb as int == 0 { return option::none::<@~[u8]>; }
let of = alt mk_object_file(mb) {
- option::some(of) { of }
- _ { return option::none::<@~[u8]>; }
+ option::some(of) => of,
+ _ => return option::none::<@~[u8]>
};
let si = mk_section_iter(of.llof);
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
fn meta_section_name(os: os) -> ~str {
alt os {
- os_macos { ~"__DATA,__note.rustc" }
- os_win32 { ~".note.rustc" }
- os_linux { ~".note.rustc" }
- os_freebsd { ~".note.rustc" }
+ os_macos => ~"__DATA,__note.rustc",
+ os_win32 => ~".note.rustc",
+ os_linux => ~".note.rustc",
+ os_freebsd => ~".note.rustc"
}
}
// A diagnostic function for dumping crate metadata to an output stream
fn list_file_metadata(os: os, path: ~str, out: io::writer) {
alt get_metadata_section(os, path) {
- option::some(bytes) { decoder::list_crate_metadata(bytes, out); }
- option::none {
+ option::some(bytes) => decoder::list_crate_metadata(bytes, out),
+ option::none => {
out.write_str(~"could not find metadata in " + path + ~".\n");
}
}
fn parse_ret_ty(st: @pstate, conv: conv_did) -> (ast::ret_style, ty::t) {
alt peek(st) {
- '!' { next(st); (ast::noreturn, ty::mk_bot(st.tcx)) }
- _ { (ast::return_val, parse_ty(st, conv)) }
+ '!' => { next(st); (ast::noreturn, ty::mk_bot(st.tcx)) }
+ _ => (ast::return_val, parse_ty(st, conv))
}
}
vec::push(idents, parse_ident_(st, is_last));
loop {
alt peek(st) {
- ':' { next(st); next(st); }
- c {
+ ':' => { next(st); next(st); }
+ c => {
if c == '(' {
return @{span: ast_util::dummy_sp(),
global: false, idents: idents,
fn parse_proto(c: char) -> ast::proto {
alt c {
- '~' { ast::proto_uniq }
- '@' { ast::proto_box }
- '&' { ast::proto_block }
- 'n' { ast::proto_bare }
- _ { fail ~"illegal fn type kind " + str::from_char(c); }
+ '~' => ast::proto_uniq,
+ '@' => ast::proto_box,
+ '&' => ast::proto_block,
+ 'n' => ast::proto_bare,
+ _ => fail ~"illegal fn type kind " + str::from_char(c)
}
}
}
alt check next(st) {
- '~' { ty::vstore_uniq }
- '@' { ty::vstore_box }
- '&' { ty::vstore_slice(parse_region(st)) }
+ '~' => ty::vstore_uniq,
+ '@' => ty::vstore_box,
+ '&' => ty::vstore_slice(parse_region(st))
}
}
fn parse_bound_region(st: @pstate) -> ty::bound_region {
alt check next(st) {
- 's' { ty::br_self }
- 'a' { ty::br_anon }
- '[' { ty::br_named(@parse_str(st, ']')) }
- 'c' {
+ 's' => ty::br_self,
+ 'a' => ty::br_anon,
+ '[' => ty::br_named(@parse_str(st, ']')),
+ 'c' => {
let id = parse_int(st);
assert next(st) == '|';
ty::br_cap_avoid(id, @parse_bound_region(st))
fn parse_region(st: @pstate) -> ty::region {
alt check next(st) {
- 'b' {
+ 'b' => {
ty::re_bound(parse_bound_region(st))
}
- 'f' {
+ 'f' => {
assert next(st) == '[';
let id = parse_int(st);
assert next(st) == '|';
assert next(st) == ']';
ty::re_free(id, br)
}
- 's' {
+ 's' => {
let id = parse_int(st);
assert next(st) == '|';
ty::re_scope(id)
}
- 't' {
+ 't' => {
ty::re_static
}
}
fn parse_opt<T>(st: @pstate, f: fn() -> T) -> option<T> {
alt check next(st) {
- 'n' { none }
- 's' { some(f()) }
+ 'n' => none,
+ 's' => some(f())
}
}
fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
alt check next(st) {
- 'n' { return ty::mk_nil(st.tcx); }
- 'z' { return ty::mk_bot(st.tcx); }
- 'b' { return ty::mk_bool(st.tcx); }
- 'i' { return ty::mk_int(st.tcx); }
- 'u' { return ty::mk_uint(st.tcx); }
- 'l' { return ty::mk_float(st.tcx); }
- 'M' {
+ 'n' => return ty::mk_nil(st.tcx),
+ 'z' => return ty::mk_bot(st.tcx),
+ 'b' => return ty::mk_bool(st.tcx),
+ 'i' => return ty::mk_int(st.tcx),
+ 'u' => return ty::mk_uint(st.tcx),
+ 'l' => return ty::mk_float(st.tcx),
+ 'M' => {
alt check next(st) {
- 'b' { return ty::mk_mach_uint(st.tcx, ast::ty_u8); }
- 'w' { return ty::mk_mach_uint(st.tcx, ast::ty_u16); }
- 'l' { return ty::mk_mach_uint(st.tcx, ast::ty_u32); }
- 'd' { return ty::mk_mach_uint(st.tcx, ast::ty_u64); }
- 'B' { return ty::mk_mach_int(st.tcx, ast::ty_i8); }
- 'W' { return ty::mk_mach_int(st.tcx, ast::ty_i16); }
- 'L' { return ty::mk_mach_int(st.tcx, ast::ty_i32); }
- 'D' { return ty::mk_mach_int(st.tcx, ast::ty_i64); }
- 'f' { return ty::mk_mach_float(st.tcx, ast::ty_f32); }
- 'F' { return ty::mk_mach_float(st.tcx, ast::ty_f64); }
+ 'b' => return ty::mk_mach_uint(st.tcx, ast::ty_u8),
+ 'w' => return ty::mk_mach_uint(st.tcx, ast::ty_u16),
+ 'l' => return ty::mk_mach_uint(st.tcx, ast::ty_u32),
+ 'd' => return ty::mk_mach_uint(st.tcx, ast::ty_u64),
+ 'B' => return ty::mk_mach_int(st.tcx, ast::ty_i8),
+ 'W' => return ty::mk_mach_int(st.tcx, ast::ty_i16),
+ 'L' => return ty::mk_mach_int(st.tcx, ast::ty_i32),
+ 'D' => return ty::mk_mach_int(st.tcx, ast::ty_i64),
+ 'f' => return ty::mk_mach_float(st.tcx, ast::ty_f32),
+ 'F' => return ty::mk_mach_float(st.tcx, ast::ty_f64)
}
}
- 'c' { return ty::mk_char(st.tcx); }
- 't' {
+ 'c' => return ty::mk_char(st.tcx),
+ 't' => {
assert (next(st) == '[');
let def = parse_def(st, conv);
let substs = parse_substs(st, conv);
assert next(st) == ']';
return ty::mk_enum(st.tcx, def, substs);
}
- 'x' {
+ 'x' => {
assert next(st) == '[';
let def = parse_def(st, conv);
let substs = parse_substs(st, conv);
assert next(st) == ']';
return ty::mk_trait(st.tcx, def, substs);
}
- 'p' {
+ 'p' => {
let did = parse_def(st, conv);
return ty::mk_param(st.tcx, parse_int(st) as uint, did);
}
- 's' {
+ 's' => {
return ty::mk_self(st.tcx);
}
- '@' { return ty::mk_box(st.tcx, parse_mt(st, conv)); }
- '~' { return ty::mk_uniq(st.tcx, parse_mt(st, conv)); }
- '*' { return ty::mk_ptr(st.tcx, parse_mt(st, conv)); }
- '&' {
+ '@' => return ty::mk_box(st.tcx, parse_mt(st, conv)),
+ '~' => return ty::mk_uniq(st.tcx, parse_mt(st, conv)),
+ '*' => return ty::mk_ptr(st.tcx, parse_mt(st, conv)),
+ '&' => {
let r = parse_region(st);
let mt = parse_mt(st, conv);
return ty::mk_rptr(st.tcx, r, mt);
}
- 'U' { return ty::mk_unboxed_vec(st.tcx, parse_mt(st, conv)); }
- 'V' {
+ 'U' => return ty::mk_unboxed_vec(st.tcx, parse_mt(st, conv)),
+ 'V' => {
let mt = parse_mt(st, conv);
let v = parse_vstore(st);
return ty::mk_evec(st.tcx, mt, v);
}
- 'v' {
+ 'v' => {
let v = parse_vstore(st);
return ty::mk_estr(st.tcx, v);
}
- 'R' {
+ 'R' => {
assert (next(st) == '[');
let mut fields: ~[ty::field] = ~[];
while peek(st) != ']' {
st.pos = st.pos + 1u;
return ty::mk_rec(st.tcx, fields);
}
- 'T' {
+ 'T' => {
assert (next(st) == '[');
let mut params = ~[];
while peek(st) != ']' { vec::push(params, parse_ty(st, conv)); }
st.pos = st.pos + 1u;
return ty::mk_tup(st.tcx, params);
}
- 'f' {
+ 'f' => {
parse_ty_rust_fn(st, conv)
}
- 'X' {
+ 'X' => {
return ty::mk_var(st.tcx, ty::tv_vid(parse_int(st) as uint));
}
- 'Y' { return ty::mk_type(st.tcx); }
- 'C' {
+ 'Y' => return ty::mk_type(st.tcx),
+ 'C' => {
let ck = alt check next(st) {
- '&' { ty::ck_block }
- '@' { ty::ck_box }
- '~' { ty::ck_uniq }
+ '&' => ty::ck_block,
+ '@' => ty::ck_box,
+ '~' => ty::ck_uniq
};
return ty::mk_opaque_closure_ptr(st.tcx, ck);
}
- '#' {
+ '#' => {
let pos = parse_hex(st);
assert (next(st) == ':');
let len = parse_hex(st);
assert (next(st) == '#');
alt st.tcx.rcache.find({cnum: st.crate, pos: pos, len: len}) {
- some(tt) { return tt; }
- none {
+ some(tt) => return tt,
+ none => {
let ps = @{pos: pos with *st};
let tt = parse_ty(ps, conv);
st.tcx.rcache.insert({cnum: st.crate, pos: pos, len: len}, tt);
}
}
}
- '"' {
+ '"' => {
let def = parse_def(st, conv);
let inner = parse_ty(st, conv);
ty::mk_with_id(st.tcx, inner, def)
}
- 'B' { ty::mk_opaque_box(st.tcx) }
- 'a' {
+ 'B' => ty::mk_opaque_box(st.tcx),
+ 'a' => {
debug!{"saw a class"};
assert (next(st) == '[');
debug!{"saw a ["};
assert (next(st) == ']');
return ty::mk_class(st.tcx, did, substs);
}
- c { error!{"unexpected char in type string: %c", c}; fail;}
+ c => { error!{"unexpected char in type string: %c", c}; fail;}
}
}
fn parse_mt(st: @pstate, conv: conv_did) -> ty::mt {
let mut m;
alt peek(st) {
- 'm' { next(st); m = ast::m_mutbl; }
- '?' { next(st); m = ast::m_const; }
- _ { m = ast::m_imm; }
+ 'm' => { next(st); m = ast::m_mutbl; }
+ '?' => { next(st); m = ast::m_const; }
+ _ => { m = ast::m_imm; }
}
return {ty: parse_ty(st, conv), mutbl: m};
}
fn parse_purity(c: char) -> purity {
alt check c {
- 'u' {unsafe_fn}
- 'p' {pure_fn}
- 'i' {impure_fn}
- 'c' {extern_fn}
+ 'u' => unsafe_fn,
+ 'p' => pure_fn,
+ 'i' => impure_fn,
+ 'c' => extern_fn
}
}
let mut inputs: ~[ty::arg] = ~[];
while peek(st) != ']' {
let mode = alt check peek(st) {
- '&' { ast::by_mutbl_ref }
- '-' { ast::by_move }
- '+' { ast::by_copy }
- '=' { ast::by_ref }
- '#' { ast::by_val }
+ '&' => ast::by_mutbl_ref,
+ '-' => ast::by_move,
+ '+' => ast::by_copy,
+ '=' => ast::by_ref,
+ '#' => ast::by_val
};
st.pos += 1u;
vec::push(inputs, {mode: ast::expl(mode), ty: parse_ty(st, conv)});
let def_part = vec::slice(buf, colon_idx + 1u, len);
let crate_num = alt uint::parse_buf(crate_part, 10u) {
- some(cn) { cn as int }
- none { fail (fmt!{"internal error: parse_def_id: crate number \
- expected, but found %?", crate_part}); }
+ some(cn) => cn as int,
+ none => fail (fmt!{"internal error: parse_def_id: crate number \
+ expected, but found %?", crate_part})
};
let def_num = alt uint::parse_buf(def_part, 10u) {
- some(dn) { dn as int }
- none { fail (fmt!{"internal error: parse_def_id: id expected, but \
- found %?", def_part}); }
+ some(dn) => dn as int,
+ none => fail (fmt!{"internal error: parse_def_id: id expected, but \
+ found %?", def_part})
};
return {crate: crate_num, node: def_num};
}
let mut bounds = ~[];
loop {
vec::push(bounds, alt check next(st) {
- 'S' { ty::bound_send }
- 'C' { ty::bound_copy }
- 'K' { ty::bound_const }
- 'O' { ty::bound_owned }
- 'I' { ty::bound_trait(parse_ty(st, conv)) }
- '.' { break; }
+ 'S' => ty::bound_send,
+ 'C' => ty::bound_copy,
+ 'K' => ty::bound_const,
+ 'O' => ty::bound_owned,
+ 'I' => ty::bound_trait(parse_ty(st, conv)),
+ '.' => break
});
}
@bounds
fn cx_uses_abbrevs(cx: @ctxt) -> bool {
alt cx.abbrevs {
- ac_no_abbrevs { return false; }
- ac_use_abbrevs(_) { return true; }
+ ac_no_abbrevs => return false,
+ ac_use_abbrevs(_) => return true
}
}
fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) {
alt cx.abbrevs {
- ac_no_abbrevs {
+ ac_no_abbrevs => {
let result_str = alt cx.tcx.short_names_cache.find(t) {
- some(s) { *s }
- none {
+ some(s) => *s,
+ none => {
let buf = io::mem_buffer();
enc_sty(io::mem_buffer_writer(buf), cx, ty::get(t).struct);
cx.tcx.short_names_cache.insert(t, @io::mem_buffer_str(buf));
};
w.write_str(result_str);
}
- ac_use_abbrevs(abbrevs) {
+ ac_use_abbrevs(abbrevs) => {
alt abbrevs.find(t) {
- some(a) { w.write_str(*a.s); return; }
- none {
+ some(a) => { w.write_str(*a.s); return; }
+ none => {
let pos = w.tell();
alt ty::type_def_id(t) {
- some(def_id) {
+ some(def_id) => {
// Do not emit node ids that map to unexported names. Those
// are not helpful.
if def_id.crate != local_crate ||
w.write_char('|');
}
}
- _ {}
+ _ => {}
}
enc_sty(w, cx, ty::get(t).struct);
let end = w.tell();
}
fn enc_mt(w: io::writer, cx: @ctxt, mt: ty::mt) {
alt mt.mutbl {
- m_imm { }
- m_mutbl { w.write_char('m'); }
- m_const { w.write_char('?'); }
+ m_imm => (),
+ m_mutbl => w.write_char('m'),
+ m_const => w.write_char('?')
}
enc_ty(w, cx, mt.ty);
}
fn enc_opt<T>(w: io::writer, t: option<T>, enc_f: fn(T)) {
alt t {
- none { w.write_char('n') }
- some(v) {
+ none => w.write_char('n'),
+ some(v) => {
w.write_char('s');
enc_f(v);
}
fn enc_region(w: io::writer, cx: @ctxt, r: ty::region) {
alt r {
- ty::re_bound(br) {
+ ty::re_bound(br) => {
w.write_char('b');
enc_bound_region(w, br);
}
- ty::re_free(id, br) {
+ ty::re_free(id, br) => {
w.write_char('f');
w.write_char('[');
w.write_int(id);
enc_bound_region(w, br);
w.write_char(']');
}
- ty::re_scope(nid) {
+ ty::re_scope(nid) => {
w.write_char('s');
w.write_int(nid);
w.write_char('|');
}
- ty::re_static {
+ ty::re_static => {
w.write_char('t');
}
- ty::re_var(_) {
+ ty::re_var(_) => {
// these should not crop up after typeck
cx.diag.handler().bug(~"Cannot encode region variables");
}
fn enc_bound_region(w: io::writer, br: ty::bound_region) {
alt br {
- ty::br_self { w.write_char('s') }
- ty::br_anon { w.write_char('a') }
- ty::br_named(s) {
+ ty::br_self => w.write_char('s'),
+ ty::br_anon => w.write_char('a'),
+ ty::br_named(s) => {
w.write_char('[');
w.write_str(*s);
w.write_char(']')
}
- ty::br_cap_avoid(id, br) {
+ ty::br_cap_avoid(id, br) => {
w.write_char('c');
w.write_int(id);
w.write_char('|');
fn enc_vstore(w: io::writer, cx: @ctxt, v: ty::vstore) {
w.write_char('/');
alt v {
- ty::vstore_fixed(u) {
+ ty::vstore_fixed(u) => {
w.write_uint(u);
w.write_char('|');
}
- ty::vstore_uniq {
+ ty::vstore_uniq => {
w.write_char('~');
}
- ty::vstore_box {
+ ty::vstore_box => {
w.write_char('@');
}
- ty::vstore_slice(r) {
+ ty::vstore_slice(r) => {
w.write_char('&');
enc_region(w, cx, r);
}
fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
alt st {
- ty::ty_nil { w.write_char('n'); }
- ty::ty_bot { w.write_char('z'); }
- ty::ty_bool { w.write_char('b'); }
- ty::ty_int(t) {
+ ty::ty_nil => w.write_char('n'),
+ ty::ty_bot => w.write_char('z'),
+ ty::ty_bool => w.write_char('b'),
+ ty::ty_int(t) => {
alt t {
- ty_i { w.write_char('i'); }
- ty_char { w.write_char('c'); }
- ty_i8 { w.write_str(&"MB"); }
- ty_i16 { w.write_str(&"MW"); }
- ty_i32 { w.write_str(&"ML"); }
- ty_i64 { w.write_str(&"MD"); }
+ ty_i => w.write_char('i'),
+ ty_char => w.write_char('c'),
+ ty_i8 => w.write_str(&"MB"),
+ ty_i16 => w.write_str(&"MW"),
+ ty_i32 => w.write_str(&"ML"),
+ ty_i64 => w.write_str(&"MD")
}
}
- ty::ty_uint(t) {
+ ty::ty_uint(t) => {
alt t {
- ty_u { w.write_char('u'); }
- ty_u8 { w.write_str(&"Mb"); }
- ty_u16 { w.write_str(&"Mw"); }
- ty_u32 { w.write_str(&"Ml"); }
- ty_u64 { w.write_str(&"Md"); }
+ ty_u => w.write_char('u'),
+ ty_u8 => w.write_str(&"Mb"),
+ ty_u16 => w.write_str(&"Mw"),
+ ty_u32 => w.write_str(&"Ml"),
+ ty_u64 => w.write_str(&"Md")
}
}
- ty::ty_float(t) {
+ ty::ty_float(t) => {
alt t {
- ty_f { w.write_char('l'); }
- ty_f32 { w.write_str(&"Mf"); }
- ty_f64 { w.write_str(&"MF"); }
+ ty_f => w.write_char('l'),
+ ty_f32 => w.write_str(&"Mf"),
+ ty_f64 => w.write_str(&"MF"),
}
}
- ty::ty_enum(def, substs) {
+ ty::ty_enum(def, substs) => {
w.write_str(&"t[");
w.write_str(cx.ds(def));
w.write_char('|');
enc_substs(w, cx, substs);
w.write_char(']');
}
- ty::ty_trait(def, substs) {
+ ty::ty_trait(def, substs) => {
w.write_str(&"x[");
w.write_str(cx.ds(def));
w.write_char('|');
enc_substs(w, cx, substs);
w.write_char(']');
}
- ty::ty_tup(ts) {
+ ty::ty_tup(ts) => {
w.write_str(&"T[");
for ts.each |t| { enc_ty(w, cx, t); }
w.write_char(']');
}
- ty::ty_box(mt) { w.write_char('@'); enc_mt(w, cx, mt); }
- ty::ty_uniq(mt) { w.write_char('~'); enc_mt(w, cx, mt); }
- ty::ty_ptr(mt) { w.write_char('*'); enc_mt(w, cx, mt); }
- ty::ty_rptr(r, mt) {
+ ty::ty_box(mt) => { w.write_char('@'); enc_mt(w, cx, mt); }
+ ty::ty_uniq(mt) => { w.write_char('~'); enc_mt(w, cx, mt); }
+ ty::ty_ptr(mt) => { w.write_char('*'); enc_mt(w, cx, mt); }
+ ty::ty_rptr(r, mt) => {
w.write_char('&');
enc_region(w, cx, r);
enc_mt(w, cx, mt);
}
- ty::ty_evec(mt, v) {
+ ty::ty_evec(mt, v) => {
w.write_char('V');
enc_mt(w, cx, mt);
enc_vstore(w, cx, v);
}
- ty::ty_estr(v) {
+ ty::ty_estr(v) => {
w.write_char('v');
enc_vstore(w, cx, v);
}
- ty::ty_unboxed_vec(mt) { w.write_char('U'); enc_mt(w, cx, mt); }
- ty::ty_rec(fields) {
+ ty::ty_unboxed_vec(mt) => { w.write_char('U'); enc_mt(w, cx, mt); }
+ ty::ty_rec(fields) => {
w.write_str(&"R[");
for fields.each |field| {
w.write_str(*field.ident);
}
w.write_char(']');
}
- ty::ty_fn(f) {
+ ty::ty_fn(f) => {
enc_ty_fn(w, cx, f);
}
- ty::ty_var(id) {
+ ty::ty_var(id) => {
w.write_char('X');
w.write_uint(id.to_uint());
}
- ty::ty_var_integral(id) {
+ ty::ty_var_integral(id) => {
w.write_char('X');
w.write_char('I');
w.write_uint(id.to_uint());
}
- ty::ty_param({idx: id, def_id: did}) {
+ ty::ty_param({idx: id, def_id: did}) => {
w.write_char('p');
w.write_str(cx.ds(did));
w.write_char('|');
w.write_str(uint::str(id));
}
- ty::ty_self {
+ ty::ty_self => {
w.write_char('s');
}
- ty::ty_type { w.write_char('Y'); }
- ty::ty_opaque_closure_ptr(ty::ck_block) { w.write_str(&"C&"); }
- ty::ty_opaque_closure_ptr(ty::ck_box) { w.write_str(&"C@"); }
- ty::ty_opaque_closure_ptr(ty::ck_uniq) { w.write_str(&"C~"); }
- ty::ty_opaque_box { w.write_char('B'); }
- ty::ty_class(def, substs) {
+ ty::ty_type => w.write_char('Y'),
+ ty::ty_opaque_closure_ptr(ty::ck_block) => w.write_str(&"C&"),
+ ty::ty_opaque_closure_ptr(ty::ck_box) => w.write_str(&"C@"),
+ ty::ty_opaque_closure_ptr(ty::ck_uniq) => w.write_str(&"C~"),
+ ty::ty_opaque_box => w.write_char('B'),
+ ty::ty_class(def, substs) => {
debug!{"~~~~ %s", ~"a["};
w.write_str(&"a[");
let s = cx.ds(def);
}
fn enc_proto(w: io::writer, proto: proto) {
alt proto {
- proto_uniq { w.write_str(&"f~"); }
- proto_box { w.write_str(&"f@"); }
- proto_block { w.write_str(~"f&"); }
- proto_bare { w.write_str(&"fn"); }
+ proto_uniq => w.write_str(&"f~"),
+ proto_box => w.write_str(&"f@"),
+ proto_block => w.write_str(~"f&"),
+ proto_bare => w.write_str(&"fn")
}
}
fn enc_mode(w: io::writer, cx: @ctxt, m: mode) {
alt ty::resolved_mode(cx.tcx, m) {
- by_mutbl_ref { w.write_char('&'); }
- by_move { w.write_char('-'); }
- by_copy { w.write_char('+'); }
- by_ref { w.write_char('='); }
- by_val { w.write_char('#'); }
+ by_mutbl_ref => w.write_char('&'),
+ by_move => w.write_char('-'),
+ by_copy => w.write_char('+'),
+ by_ref => w.write_char('='),
+ by_val => w.write_char('#')
}
}
fn enc_purity(w: io::writer, p: purity) {
alt p {
- pure_fn { w.write_char('p'); }
- impure_fn { w.write_char('i'); }
- unsafe_fn { w.write_char('u'); }
- extern_fn { w.write_char('c'); }
+ pure_fn => w.write_char('p'),
+ impure_fn => w.write_char('i'),
+ unsafe_fn => w.write_char('u'),
+ extern_fn => w.write_char('c')
}
}
}
w.write_char(']');
alt ft.ret_style {
- noreturn { w.write_char('!'); }
- _ { enc_ty(w, cx, ft.output); }
+ noreturn => w.write_char('!'),
+ _ => enc_ty(w, cx, ft.output)
}
}
fn enc_bounds(w: io::writer, cx: @ctxt, bs: @~[ty::param_bound]) {
for vec::each(*bs) |bound| {
alt bound {
- ty::bound_send { w.write_char('S'); }
- ty::bound_copy { w.write_char('C'); }
- ty::bound_const { w.write_char('K'); }
- ty::bound_owned { w.write_char('O'); }
- ty::bound_trait(tp) {
+ ty::bound_send => w.write_char('S'),
+ ty::bound_copy => w.write_char('C'),
+ ty::bound_const => w.write_char('K'),
+ ty::bound_owned => w.write_char('O'),
+ ty::bound_trait(tp) => {
w.write_char('I');
enc_ty(w, cx, tp);
}
par_doc: ebml::doc) -> option<ast::inlined_item> {
let dcx = @{cdata: cdata, tcx: tcx, maps: maps};
alt par_doc.opt_child(c::tag_ast) {
- none { none }
- some(ast_doc) {
+ none => none,
+ some(ast_doc) => {
debug!{"> Decoding inlined fn: %s::?", ast_map::path_to_str(path)};
let ast_dsr = ebml::ebml_deserializer(ast_doc);
let from_id_range = ast_util::deserialize_id_range(ast_dsr);
debug!{"< Decoded inlined fn: %s::%s",
ast_map::path_to_str(path), *ii.ident()};
alt ii {
- ast::ii_item(i) {
+ ast::ii_item(i) => {
debug!{">>> DECODED ITEM >>>\n%s\n<<< DECODED ITEM <<<",
syntax::print::pprust::item_to_str(i)};
}
- _ { }
+ _ => { }
}
some(ii)
}
let stmts_sans_items = do vec::filter(blk.stmts) |stmt| {
alt stmt.node {
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
- ast::stmt_decl(@{node: ast::decl_local(_), span: _}, _) { true }
- ast::stmt_decl(@{node: ast::decl_item(_), span: _}, _) { false }
+ ast::stmt_decl(@{node: ast::decl_local(_), span: _}, _) => true,
+ ast::stmt_decl(@{node: ast::decl_item(_), span: _}, _) => false
}
};
let blk_sans_items = { stmts: stmts_sans_items with blk };
});
alt ii {
- ast::ii_item(i) {
+ ast::ii_item(i) => {
ast::ii_item(fld.fold_item(i).get()) //hack: we're not dropping items
}
- ast::ii_method(d, m) {
+ ast::ii_method(d, m) => {
ast::ii_method(d, fld.fold_method(m))
}
- ast::ii_foreign(i) {
+ ast::ii_foreign(i) => {
ast::ii_foreign(fld.fold_foreign_item(i))
}
- ast::ii_ctor(ctor, nm, tps, parent_id) {
+ ast::ii_ctor(ctor, nm, tps, parent_id) => {
let ctor_body = fld.fold_block(ctor.node.body);
let ctor_decl = fold::fold_fn_decl(ctor.node.dec, fld);
ast::ii_ctor({node: {body: ctor_body, dec: ctor_decl
with ctor.node}
with ctor}, nm, tps, parent_id)
}
- ast::ii_dtor(dtor, nm, tps, parent_id) {
+ ast::ii_dtor(dtor, nm, tps, parent_id) => {
let dtor_body = fld.fold_block(dtor.node.body);
ast::ii_dtor({node: {body: dtor_body
with dtor.node}
});
alt ii {
- ast::ii_item(i) {
+ ast::ii_item(i) => {
ast::ii_item(fld.fold_item(i).get())
}
- ast::ii_method(d, m) {
+ ast::ii_method(d, m) => {
ast::ii_method(xcx.tr_def_id(d), fld.fold_method(m))
}
- ast::ii_foreign(i) {
+ ast::ii_foreign(i) => {
ast::ii_foreign(fld.fold_foreign_item(i))
}
- ast::ii_ctor(ctor, nm, tps, parent_id) {
+ ast::ii_ctor(ctor, nm, tps, parent_id) => {
let ctor_body = fld.fold_block(ctor.node.body);
let ctor_attrs = fld.fold_attributes(ctor.node.attrs);
let ctor_decl = fold::fold_fn_decl(ctor.node.dec, fld);
with ctor.node}
with ctor}, nm, new_params, new_parent)
}
- ast::ii_dtor(dtor, nm, tps, parent_id) {
+ ast::ii_dtor(dtor, nm, tps, parent_id) => {
let dtor_body = fld.fold_block(dtor.node.body);
let dtor_attrs = fld.fold_attributes(dtor.node.attrs);
let new_params = fold::fold_ty_params(tps, fld);
impl of tr for ast::def {
fn tr(xcx: extended_decode_ctxt) -> ast::def {
alt self {
- ast::def_fn(did, p) { ast::def_fn(did.tr(xcx), p) }
- ast::def_self(nid) { ast::def_self(xcx.tr_id(nid)) }
- ast::def_mod(did) { ast::def_mod(did.tr(xcx)) }
- ast::def_foreign_mod(did) { ast::def_foreign_mod(did.tr(xcx)) }
- ast::def_const(did) { ast::def_const(did.tr(xcx)) }
- ast::def_arg(nid, m) { ast::def_arg(xcx.tr_id(nid), m) }
- ast::def_local(nid, b) { ast::def_local(xcx.tr_id(nid), b) }
- ast::def_variant(e_did, v_did) {
+ ast::def_fn(did, p) => ast::def_fn(did.tr(xcx), p),
+ ast::def_self(nid) => ast::def_self(xcx.tr_id(nid)),
+ ast::def_mod(did) => ast::def_mod(did.tr(xcx)),
+ ast::def_foreign_mod(did) => ast::def_foreign_mod(did.tr(xcx)),
+ ast::def_const(did) => ast::def_const(did.tr(xcx)),
+ ast::def_arg(nid, m) => ast::def_arg(xcx.tr_id(nid), m),
+ ast::def_local(nid, b) => ast::def_local(xcx.tr_id(nid), b),
+ ast::def_variant(e_did, v_did) => {
ast::def_variant(e_did.tr(xcx), v_did.tr(xcx))
}
- ast::def_ty(did) { ast::def_ty(did.tr(xcx)) }
- ast::def_prim_ty(p) { ast::def_prim_ty(p) }
- ast::def_ty_param(did, v) { ast::def_ty_param(did.tr(xcx), v) }
- ast::def_binding(nid, bm) { ast::def_binding(xcx.tr_id(nid), bm) }
- ast::def_use(did) { ast::def_use(did.tr(xcx)) }
- ast::def_upvar(nid1, def, nid2) {
+ ast::def_ty(did) => ast::def_ty(did.tr(xcx)),
+ ast::def_prim_ty(p) => ast::def_prim_ty(p),
+ ast::def_ty_param(did, v) => ast::def_ty_param(did.tr(xcx), v),
+ ast::def_binding(nid, bm) => ast::def_binding(xcx.tr_id(nid), bm),
+ ast::def_use(did) => ast::def_use(did.tr(xcx)),
+ ast::def_upvar(nid1, def, nid2) => {
ast::def_upvar(xcx.tr_id(nid1), @(*def).tr(xcx), xcx.tr_id(nid2))
}
- ast::def_class(did, has_constructor) {
+ ast::def_class(did, has_constructor) => {
ast::def_class(did.tr(xcx), has_constructor)
}
- ast::def_region(nid) { ast::def_region(xcx.tr_id(nid)) }
- ast::def_typaram_binder(nid) {
+ ast::def_region(nid) => ast::def_region(xcx.tr_id(nid)),
+ ast::def_typaram_binder(nid) => {
ast::def_typaram_binder(xcx.tr_id(nid))
}
}
impl of tr for method_origin {
fn tr(xcx: extended_decode_ctxt) -> method_origin {
alt self {
- typeck::method_static(did) {
+ typeck::method_static(did) => {
typeck::method_static(did.tr(xcx))
}
- typeck::method_param(mp) {
+ typeck::method_param(mp) => {
typeck::method_param({trait_id:mp.trait_id.tr(xcx) with mp})
}
- typeck::method_trait(did, m) {
+ typeck::method_trait(did, m) => {
typeck::method_trait(did.tr(xcx), m)
}
}
vtable_origin: typeck::vtable_origin) {
do ebml_w.emit_enum(~"vtable_origin") {
alt vtable_origin {
- typeck::vtable_static(def_id, tys, vtable_res) {
+ typeck::vtable_static(def_id, tys, vtable_res) => {
do ebml_w.emit_enum_variant(~"vtable_static", 0u, 3u) {
do ebml_w.emit_enum_variant_arg(0u) {
ebml_w.emit_def_id(def_id)
}
}
}
- typeck::vtable_param(pn, bn) {
+ typeck::vtable_param(pn, bn) => {
do ebml_w.emit_enum_variant(~"vtable_param", 1u, 2u) {
do ebml_w.emit_enum_variant_arg(0u) {
ebml_w.emit_uint(pn);
}
}
}
- typeck::vtable_trait(def_id, tys) {
+ typeck::vtable_trait(def_id, tys) => {
do ebml_w.emit_enum_variant(~"vtable_trait", 1u, 3u) {
do ebml_w.emit_enum_variant_arg(0u) {
ebml_w.emit_def_id(def_id)
do self.read_enum(~"vtable_origin") {
do self.read_enum_variant |i| {
alt check i {
- 0u {
+ 0u => {
typeck::vtable_static(
do self.read_enum_variant_arg(0u) {
self.read_def_id(xcx)
}
)
}
- 1u {
+ 1u => {
typeck::vtable_param(
do self.read_enum_variant_arg(0u) {
self.read_uint()
}
)
}
- 2u {
+ 2u => {
typeck::vtable_trait(
do self.read_enum_variant_arg(0u) {
self.read_def_id(xcx)
}
});
alt (item_out, item_exp) {
- (ast::ii_item(item_out), ast::ii_item(item_exp)) {
+ (ast::ii_item(item_out), ast::ii_item(item_exp)) => {
assert pprust::item_to_str(item_out) == pprust::item_to_str(item_exp);
}
- _ { fail; }
+ _ => fail
}
}
fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
if !cx.allow_block {
alt ty::get(ty::expr_ty(cx.tcx, ex)).struct {
- ty::ty_fn({proto: p, _}) if is_blockish(p) {
+ ty::ty_fn({proto: p, _}) if is_blockish(p) => {
cx.tcx.sess.span_err(ex.span,
~"expressions with stack closure type \
can only appear in callee or (by-ref) argument position");
}
- _ {}
+ _ => {}
}
}
let outer = cx.allow_block;
alt ex.node {
- expr_call(f, args, _) {
+ expr_call(f, args, _) => {
cx.allow_block = true;
v.visit_expr(f, cx, v);
let mut i = 0u;
i += 1u;
}
}
- expr_loop_body(body) | expr_do_body(body) {
+ expr_loop_body(body) | expr_do_body(body) => {
cx.allow_block = true;
v.visit_expr(body, cx, v);
}
- _ {
+ _ => {
cx.allow_block = false;
visit::visit_expr(ex, cx, v);
}
impl error_methods for borrowck_ctxt {
fn report_if_err(bres: bckres<()>) {
alt bres {
- ok(()) { }
- err(e) { self.report(e); }
+ ok(()) => (),
+ err(e) => self.report(e)
}
}
fn add_to_mutbl_map(cmt: cmt) {
alt cmt.cat {
- cat_local(id) | cat_arg(id) {
+ cat_local(id) | cat_arg(id) => {
self.mutbl_map.insert(id, ());
}
- cat_stack_upvar(cmt) {
+ cat_stack_upvar(cmt) => {
self.add_to_mutbl_map(cmt);
}
- _ {}
+ _ => ()
}
}
}
impl to_str_methods for borrowck_ctxt {
fn cat_to_repr(cat: categorization) -> ~str {
alt cat {
- cat_special(sk_method) { ~"method" }
- cat_special(sk_static_item) { ~"static_item" }
- cat_special(sk_self) { ~"self" }
- cat_special(sk_heap_upvar) { ~"heap-upvar" }
- cat_stack_upvar(_) { ~"stack-upvar" }
- cat_rvalue { ~"rvalue" }
- cat_local(node_id) { fmt!{"local(%d)", node_id} }
- cat_binding(node_id) { fmt!{"binding(%d)", node_id} }
- cat_arg(node_id) { fmt!{"arg(%d)", node_id} }
- cat_deref(cmt, derefs, ptr) {
+ cat_special(sk_method) => ~"method",
+ cat_special(sk_static_item) => ~"static_item",
+ cat_special(sk_self) => ~"self",
+ cat_special(sk_heap_upvar) => ~"heap-upvar",
+ cat_stack_upvar(_) => ~"stack-upvar",
+ cat_rvalue => ~"rvalue",
+ cat_local(node_id) => fmt!{"local(%d)", node_id},
+ cat_binding(node_id) => fmt!{"binding(%d)", node_id},
+ cat_arg(node_id) => fmt!{"arg(%d)", node_id},
+ cat_deref(cmt, derefs, ptr) => {
fmt!{"%s->(%s, %u)", self.cat_to_repr(cmt.cat),
self.ptr_sigil(ptr), derefs}
}
- cat_comp(cmt, comp) {
+ cat_comp(cmt, comp) => {
fmt!{"%s.%s", self.cat_to_repr(cmt.cat), self.comp_to_repr(comp)}
}
- cat_discr(cmt, _) { self.cat_to_repr(cmt.cat) }
+ cat_discr(cmt, _) => self.cat_to_repr(cmt.cat)
}
}
fn mut_to_str(mutbl: ast::mutability) -> ~str {
alt mutbl {
- m_mutbl { ~"mutable" }
- m_const { ~"const" }
- m_imm { ~"immutable" }
+ m_mutbl => ~"mutable",
+ m_const => ~"const",
+ m_imm => ~"immutable"
}
}
fn ptr_sigil(ptr: ptr_kind) -> ~str {
alt ptr {
- uniq_ptr { ~"~" }
- gc_ptr { ~"@" }
- region_ptr(_) { ~"&" }
- unsafe_ptr { ~"*" }
+ uniq_ptr => ~"~",
+ gc_ptr => ~"@",
+ region_ptr(_) => ~"&",
+ unsafe_ptr => ~"*"
}
}
fn comp_to_repr(comp: comp_kind) -> ~str {
alt comp {
- comp_field(fld, _) { *fld }
- comp_index(*) { ~"[]" }
- comp_tuple { ~"()" }
- comp_variant(_) { ~"<enum>" }
+ comp_field(fld, _) => *fld,
+ comp_index(*) => ~"[]",
+ comp_tuple => ~"()",
+ comp_variant(_) => ~"<enum>"
}
}
fn lp_to_str(lp: @loan_path) -> ~str {
alt *lp {
- lp_local(node_id) {
+ lp_local(node_id) => {
fmt!{"local(%d)", node_id}
}
- lp_arg(node_id) {
+ lp_arg(node_id) => {
fmt!{"arg(%d)", node_id}
}
- lp_deref(lp, ptr) {
+ lp_deref(lp, ptr) => {
fmt!{"%s->(%s)", self.lp_to_str(lp),
self.ptr_sigil(ptr)}
}
- lp_comp(lp, comp) {
+ lp_comp(lp, comp) => {
fmt!{"%s.%s", self.lp_to_str(lp),
self.comp_to_repr(comp)}
}
fn cmt_to_str(cmt: cmt) -> ~str {
let mut_str = self.mut_to_str(cmt.mutbl);
alt cmt.cat {
- cat_special(sk_method) { ~"method" }
- cat_special(sk_static_item) { ~"static item" }
- cat_special(sk_self) { ~"self reference" }
- cat_special(sk_heap_upvar) {
+ cat_special(sk_method) => ~"method",
+ cat_special(sk_static_item) => ~"static item",
+ cat_special(sk_self) => ~"self reference",
+ cat_special(sk_heap_upvar) => {
~"captured outer variable in a heap closure"
}
- cat_rvalue { ~"non-lvalue" }
- cat_local(_) { mut_str + ~" local variable" }
- cat_binding(_) { ~"pattern binding" }
- cat_arg(_) { ~"argument" }
- cat_deref(_, _, pk) { fmt!{"dereference of %s %s pointer",
- mut_str, self.ptr_sigil(pk)} }
- cat_stack_upvar(_) {
+ cat_rvalue => ~"non-lvalue",
+ cat_local(_) => mut_str + ~" local variable",
+ cat_binding(_) => ~"pattern binding",
+ cat_arg(_) => ~"argument",
+ cat_deref(_, _, pk) => fmt!{"dereference of %s %s pointer",
+ mut_str, self.ptr_sigil(pk)},
+ cat_stack_upvar(_) => {
~"captured outer " + mut_str + ~" variable in a stack closure"
}
- cat_comp(_, comp_field(*)) { mut_str + ~" field" }
- cat_comp(_, comp_tuple) { ~"tuple content" }
- cat_comp(_, comp_variant(_)) { ~"enum content" }
- cat_comp(_, comp_index(t, _)) {
+ cat_comp(_, comp_field(*)) => mut_str + ~" field",
+ cat_comp(_, comp_tuple) => ~"tuple content",
+ cat_comp(_, comp_variant(_)) => ~"enum content",
+ cat_comp(_, comp_index(t, _)) => {
alt ty::get(t).struct {
- ty::ty_evec(*) {
- mut_str + ~" vec content"
- }
-
- ty::ty_estr(*) {
- mut_str + ~" str content"
- }
-
- _ { mut_str + ~" indexed content" }
+ ty::ty_evec(*) => mut_str + ~" vec content",
+ ty::ty_estr(*) => mut_str + ~" str content",
+ _ => mut_str + ~" indexed content"
}
}
- cat_discr(cmt, _) {
+ cat_discr(cmt, _) => {
self.cmt_to_str(cmt)
}
}
fn bckerr_code_to_str(code: bckerr_code) -> ~str {
alt code {
- err_mutbl(req, act) {
+ err_mutbl(req, act) => {
fmt!{"creating %s alias to aliasable, %s memory",
self.mut_to_str(req), self.mut_to_str(act)}
}
- err_mut_uniq {
+ err_mut_uniq => {
~"unique value in aliasable, mutable location"
}
- err_mut_variant {
+ err_mut_variant => {
~"enum variant in aliasable, mutable location"
}
- err_root_not_permitted {
+ err_root_not_permitted => {
// note: I don't expect users to ever see this error
// message, reasons are discussed in attempt_root() in
// preserve.rs.
~"rooting is not permitted"
}
- err_out_of_root_scope(super_scope, sub_scope) {
+ err_out_of_root_scope(super_scope, sub_scope) => {
fmt!{"managed value would have to be rooted for lifetime %s, \
but can only be rooted for lifetime %s",
self.region_to_str(sub_scope),
self.region_to_str(super_scope)}
}
- err_out_of_scope(super_scope, sub_scope) {
+ err_out_of_scope(super_scope, sub_scope) => {
fmt!{"borrowed pointer has lifetime %s, \
but the borrowed value only has lifetime %s",
self.region_to_str(sub_scope),
// mutable structure.
fn inherent_mutability(ck: comp_kind) -> mutability {
alt ck {
- comp_tuple | comp_variant(_) {m_imm}
- comp_field(_, m) | comp_index(_, m) {m}
+ comp_tuple | comp_variant(_) => m_imm,
+ comp_field(_, m) | comp_index(_, m) => m
}
}
alt ty::get(t).struct {
ty::ty_uniq(*) |
ty::ty_evec(_, ty::vstore_uniq) |
- ty::ty_estr(ty::vstore_uniq) {
+ ty::ty_estr(ty::vstore_uniq) => {
some(deref_ptr(uniq_ptr))
}
ty::ty_rptr(r, _) |
ty::ty_evec(_, ty::vstore_slice(r)) |
- ty::ty_estr(ty::vstore_slice(r)) {
+ ty::ty_estr(ty::vstore_slice(r)) => {
some(deref_ptr(region_ptr(r)))
}
ty::ty_box(*) |
ty::ty_evec(_, ty::vstore_box) |
- ty::ty_estr(ty::vstore_box) {
+ ty::ty_estr(ty::vstore_box) => {
some(deref_ptr(gc_ptr))
}
- ty::ty_ptr(*) {
+ ty::ty_ptr(*) => {
some(deref_ptr(unsafe_ptr))
}
- ty::ty_enum(did, _) {
+ ty::ty_enum(did, _) => {
some(deref_comp(comp_variant(did)))
}
- ty::ty_evec(mt, ty::vstore_fixed(_)) {
+ ty::ty_evec(mt, ty::vstore_fixed(_)) => {
some(deref_comp(comp_index(t, mt.mutbl)))
}
- ty::ty_estr(ty::vstore_fixed(_)) {
+ ty::ty_estr(ty::vstore_fixed(_)) => {
some(deref_comp(comp_index(t, m_imm)))
}
- _ {
- none
- }
+ _ => none
}
}
fn deref_kind(tcx: ty::ctxt, t: ty::t) -> deref_kind {
alt opt_deref_kind(t) {
- some(k) {k}
- none {
+ some(k) => k,
+ none => {
tcx.sess.bug(
fmt!{"deref_cat() invoked on non-derefable type %s",
ty_to_str(tcx, t)});
// a borrowed expression must be either an @, ~, or a @vec, ~vec
let expr_ty = ty::expr_ty(self.tcx, expr);
alt ty::get(expr_ty).struct {
- ty::ty_evec(*) | ty::ty_estr(*) {
+ ty::ty_evec(*) | ty::ty_estr(*) => {
self.cat_index(expr, expr)
}
- ty::ty_uniq(*) | ty::ty_box(*) | ty::ty_rptr(*) {
+ ty::ty_uniq(*) | ty::ty_box(*) | ty::ty_rptr(*) => {
let cmt = self.cat_expr(expr);
self.cat_deref(expr, cmt, 0u, true).get()
}
}
*/
- _ {
+ _ => {
self.tcx.sess.span_bug(
expr.span,
fmt!{"Borrowing of non-derefable type `%s`",
let tcx = self.tcx;
let expr_ty = tcx.ty(expr);
alt expr.node {
- ast::expr_unary(ast::deref, e_base) {
+ ast::expr_unary(ast::deref, e_base) => {
if self.method_map.contains_key(expr.id) {
return self.cat_rvalue(expr, expr_ty);
}
let base_cmt = self.cat_expr(e_base);
alt self.cat_deref(expr, base_cmt, 0u, true) {
- some(cmt) { return cmt; }
- none {
+ some(cmt) => return cmt,
+ none => {
tcx.sess.span_bug(
e_base.span,
fmt!{"Explicit deref of non-derefable type `%s`",
}
}
- ast::expr_field(base, f_name, _) {
+ ast::expr_field(base, f_name, _) => {
if self.method_map.contains_key(expr.id) {
return self.cat_method_ref(expr, expr_ty);
}
self.cat_field(expr, base_cmt, f_name)
}
- ast::expr_index(base, _) {
+ ast::expr_index(base, _) => {
if self.method_map.contains_key(expr.id) {
return self.cat_rvalue(expr, expr_ty);
}
self.cat_index(expr, base)
}
- ast::expr_path(_) {
+ ast::expr_path(_) => {
let def = self.tcx.def_map.get(expr.id);
self.cat_def(expr.id, expr.span, expr_ty, def)
}
ast::expr_block(*) | ast::expr_loop(*) | ast::expr_alt(*) |
ast::expr_lit(*) | ast::expr_break | ast::expr_mac(*) |
ast::expr_again | ast::expr_rec(*) | ast::expr_struct(*) |
- ast::expr_unary_move(*) | ast::expr_repeat(*) {
+ ast::expr_unary_move(*) | ast::expr_repeat(*) => {
return self.cat_rvalue(expr, expr_ty);
}
}
ast::def_use(_) | ast::def_variant(*) |
ast::def_ty(_) | ast::def_prim_ty(_) |
ast::def_ty_param(*) | ast::def_class(*) |
- ast::def_typaram_binder(*) | ast::def_region(_) {
+ ast::def_typaram_binder(*) | ast::def_region(_) => {
@{id:id, span:span,
cat:cat_special(sk_static_item), lp:none,
mutbl:m_imm, ty:expr_ty}
}
- ast::def_arg(vid, mode) {
+ ast::def_arg(vid, mode) => {
// Idea: make this could be rewritten to model by-ref
// stuff as `&const` and `&mut`?
// m: mutability of the argument
// lp: loan path, must be none for aliasable things
let {m,lp} = alt ty::resolved_mode(self.tcx, mode) {
- ast::by_mutbl_ref {
+ ast::by_mutbl_ref => {
{m: m_mutbl, lp: none}
}
- ast::by_move | ast::by_copy {
+ ast::by_move | ast::by_copy => {
{m: m_imm, lp: some(@lp_arg(vid))}
}
- ast::by_ref {
+ ast::by_ref => {
{m: m_imm, lp: none}
}
- ast::by_val {
+ ast::by_val => {
// by-value is this hybrid mode where we have a
// pointer but we do not own it. This is not
// considered loanable because, for example, a by-ref
mutbl:m, ty:expr_ty}
}
- ast::def_self(_) {
+ ast::def_self(_) => {
@{id:id, span:span,
cat:cat_special(sk_self), lp:none,
mutbl:m_imm, ty:expr_ty}
}
- ast::def_upvar(upvid, inner, fn_node_id) {
+ ast::def_upvar(upvid, inner, fn_node_id) => {
let ty = ty::node_id_to_type(self.tcx, fn_node_id);
let proto = ty::ty_fn_proto(ty);
alt proto {
- ast::proto_block {
+ ast::proto_block => {
let upcmt = self.cat_def(id, span, expr_ty, *inner);
@{id:id, span:span,
cat:cat_stack_upvar(upcmt), lp:upcmt.lp,
mutbl:upcmt.mutbl, ty:upcmt.ty}
}
- ast::proto_bare | ast::proto_uniq | ast::proto_box {
+ ast::proto_bare | ast::proto_uniq | ast::proto_box => {
// FIXME #2152 allow mutation of moved upvars
@{id:id, span:span,
cat:cat_special(sk_heap_upvar), lp:none,
}
}
- ast::def_local(vid, mutbl) {
+ ast::def_local(vid, mutbl) => {
let m = if mutbl {m_mutbl} else {m_imm};
@{id:id, span:span,
cat:cat_local(vid), lp:some(@lp_local(vid)),
mutbl:m, ty:expr_ty}
}
- ast::def_binding(vid, ast::bind_by_value) {
+ ast::def_binding(vid, ast::bind_by_value) => {
// by-value bindings are basically local variables
@{id:id, span:span,
cat:cat_local(vid), lp:some(@lp_local(vid)),
mutbl:m_imm, ty:expr_ty}
}
- ast::def_binding(pid, ast::bind_by_ref) {
+ ast::def_binding(pid, ast::bind_by_ref) => {
// bindings are "special" since they are implicit pointers.
// lookup the mutability for this binding that we found in
fn cat_field<N:ast_node>(node: N, base_cmt: cmt,
f_name: ast::ident) -> cmt {
let f_mutbl = alt field_mutbl(self.tcx, base_cmt.ty, f_name) {
- some(f_mutbl) { f_mutbl }
- none {
+ some(f_mutbl) => f_mutbl,
+ none => {
self.tcx.sess.span_bug(
node.span(),
fmt!{"Cannot find field `%s` in type `%s`",
expl: bool) -> option<cmt> {
do ty::deref(self.tcx, base_cmt.ty, expl).map |mt| {
alt deref_kind(self.tcx, base_cmt.ty) {
- deref_ptr(ptr) {
+ deref_ptr(ptr) => {
let lp = do base_cmt.lp.chain |l| {
// Given that the ptr itself is loanable, we can
// loan out deref'd uniq ptrs as the data they are
mutbl:m, ty:mt.ty}
}
- deref_comp(comp) {
+ deref_comp(comp) => {
let lp = base_cmt.lp.map(|l| @lp_comp(l, comp) );
let m = self.inherited_mutability(base_cmt.mutbl, mt.mutbl);
@{id:node.id(), span:node.span(),
let base_cmt = self.cat_autoderef(base);
let mt = alt ty::index(self.tcx, base_cmt.ty) {
- some(mt) { mt }
- none {
+ some(mt) => mt,
+ none => {
self.tcx.sess.span_bug(
expr.span,
fmt!{"Explicit index of non-index type `%s`",
};
return alt deref_kind(self.tcx, base_cmt.ty) {
- deref_ptr(ptr) {
+ deref_ptr(ptr) => {
// (a) the contents are loanable if the base is loanable
// and this is a *unique* vector
let deref_lp = alt ptr {
comp(expr, deref_cmt, base_cmt.ty, m, mt.ty)
}
- deref_comp(_) {
+ deref_comp(_) => {
// fixed-length vectors have no deref
comp(expr, base_cmt, base_cmt.ty, mt.mutbl, mt.ty)
}
loop {
ctr += 1u;
alt self.cat_deref(base, cmt, ctr, false) {
- none { return cmt; }
- some(cmt1) { cmt = cmt1; }
+ none => return cmt,
+ some(cmt1) => cmt = cmt1
}
}
}
f_name: ast::ident) -> option<ast::mutability> {
// Need to refactor so that records/class fields can be treated uniformly.
alt ty::get(base_ty).struct {
- ty::ty_rec(fields) {
+ ty::ty_rec(fields) => {
for fields.each |f| {
if f.ident == f_name {
return some(f.mt.mutbl);
}
}
}
- ty::ty_class(did, substs) {
+ ty::ty_class(did, substs) => {
for ty::lookup_class_fields(tcx, did).each |fld| {
if fld.ident == f_name {
let m = alt fld.mutability {
- ast::class_mutable { ast::m_mutbl }
- ast::class_immutable { ast::m_imm }
+ ast::class_mutable => ast::m_mutbl,
+ ast::class_immutable => ast::m_imm
};
return some(m);
}
}
}
- _ { }
+ _ => { }
}
return none;
// the liveness pass guarantees that immutable local variables
// are only assigned once; but it doesn't consider &mut
alt self {
- at_straight_up {true}
- at_swap {true}
- at_mutbl_ref {false}
+ at_straight_up => true,
+ at_swap => true,
+ at_mutbl_ref => false
}
}
fn ing_form(desc: ~str) -> ~str {
alt self {
- at_straight_up { ~"assigning to " + desc }
- at_swap { ~"swapping to and from " + desc }
- at_mutbl_ref { ~"taking mut reference to " + desc }
+ at_straight_up => ~"assigning to " + desc,
+ at_swap => ~"swapping to and from " + desc,
+ at_mutbl_ref => ~"taking mut reference to " + desc
}
}
}
fn purity(scope_id: ast::node_id) -> option<purity_cause> {
let default_purity = alt self.declared_purity {
// an unsafe declaration overrides all
- ast::unsafe_fn { return none; }
+ ast::unsafe_fn => return none,
// otherwise, remember what was declared as the
// default, but we must scan for requirements
// imposed by the borrow check
- ast::pure_fn { some(pc_pure_fn) }
- ast::extern_fn | ast::impure_fn { none }
+ ast::pure_fn => some(pc_pure_fn),
+ ast::extern_fn | ast::impure_fn => none
};
// scan to see if this scope or any enclosing scope requires
let pure_map = self.req_maps.pure_map;
loop {
alt pure_map.find(scope_id) {
- none {}
- some(e) {return some(pc_cmt(e));}
+ none => (),
+ some(e) => return some(pc_cmt(e))
}
alt region_map.find(scope_id) {
- none { return default_purity; }
- some(next_scope_id) { scope_id = next_scope_id; }
+ none => return default_purity,
+ some(next_scope_id) => scope_id = next_scope_id
}
}
}
}
alt region_map.find(scope_id) {
- none { return; }
- some(next_scope_id) { scope_id = next_scope_id; }
+ none => return,
+ some(next_scope_id) => scope_id = next_scope_id,
}
}
}
// (d) B is not a fn.
alt opt_expr {
- some(expr) {
+ some(expr) => {
alt expr.node {
- ast::expr_path(_) if pc == pc_pure_fn {
+ ast::expr_path(_) if pc == pc_pure_fn => {
let def = self.tcx().def_map.get(expr.id);
let did = ast_util::def_id_of_def(def);
let is_fn_arg =
if is_fn_arg { return; } // case (a) above
}
ast::expr_fn_block(*) | ast::expr_fn(*) |
- ast::expr_loop_body(*) | ast::expr_do_body(*) {
+ ast::expr_loop_body(*) | ast::expr_do_body(*) => {
if self.is_stack_closure(expr.id) {
// case (b) above
return;
}
}
- _ {}
+ _ => ()
}
}
- none {}
+ none => ()
}
let callee_ty = ty::node_id_to_type(tcx, callee_id);
alt ty::get(callee_ty).struct {
- ty::ty_fn(fn_ty) {
+ ty::ty_fn(fn_ty) => {
alt fn_ty.purity {
- ast::pure_fn { return; } // case (c) above
- ast::impure_fn | ast::unsafe_fn | ast::extern_fn {
+ ast::pure_fn => return, // case (c) above
+ ast::impure_fn | ast::unsafe_fn | ast::extern_fn => {
self.report_purity_error(
pc, callee_span,
fmt!{"access to %s function",
}
}
}
- _ { return; } // case (d) above
+ _ => return, // case (d) above
}
}
let fn_ty = ty::node_id_to_type(self.tcx(), id);
let proto = ty::ty_fn_proto(fn_ty);
alt proto {
- ast::proto_block {true}
- ast::proto_bare | ast::proto_uniq | ast::proto_box {false}
+ ast::proto_block => true,
+ ast::proto_bare | ast::proto_uniq | ast::proto_box => false
}
}
fn is_allowed_pure_arg(expr: @ast::expr) -> bool {
return alt expr.node {
- ast::expr_path(_) {
+ ast::expr_path(_) => {
let def = self.tcx().def_map.get(expr.id);
let did = ast_util::def_id_of_def(def);
did.crate == ast::local_crate &&
(*self.fn_args).contains(did.node)
}
- ast::expr_fn_block(*) | ast::expr_fn(*) {
+ ast::expr_fn_block(*) | ast::expr_fn(*) => {
self.is_stack_closure(expr.id)
}
- _ {false}
+ _ => false
};
}
fn check_for_conflicting_loans(scope_id: ast::node_id) {
let new_loanss = alt self.req_maps.req_loan_map.find(scope_id) {
- none { return; }
- some(loanss) { loanss }
+ none => return,
+ some(loanss) => loanss
};
let par_scope_id = self.tcx().region_map.get(scope_id);
if old_loan.lp != new_loan.lp { again; }
alt (old_loan.mutbl, new_loan.mutbl) {
(m_const, _) | (_, m_const) |
- (m_mutbl, m_mutbl) | (m_imm, m_imm) {
+ (m_mutbl, m_mutbl) | (m_imm, m_imm) => {
/*ok*/
}
- (m_mutbl, m_imm) | (m_imm, m_mutbl) {
+ (m_mutbl, m_imm) | (m_imm, m_mutbl) => {
self.bccx.span_err(
new_loan.cmt.span,
fmt!{"loan of %s as %s \
fn is_local_variable(cmt: cmt) -> bool {
alt cmt.cat {
- cat_local(_) {true}
- _ {false}
+ cat_local(_) => true,
+ _ => false
}
}
fn is_self_field(cmt: cmt) -> bool {
alt cmt.cat {
- cat_comp(cmt_base, comp_field(*)) {
+ cat_comp(cmt_base, comp_field(*)) => {
alt cmt_base.cat {
- cat_special(sk_self) { true }
- _ { false }
+ cat_special(sk_self) => true,
+ _ => false
}
}
- _ { false }
+ _ => false
}
}
// are only assigned once
} else {
alt cmt.mutbl {
- m_mutbl { /*ok*/ }
- m_const | m_imm {
+ m_mutbl => { /*ok*/ }
+ m_const | m_imm => {
self.bccx.span_err(
ex.span,
at.ing_form(self.bccx.cmt_to_str(cmt)));
// assigned, because it is uniquely tied to this function and
// is not visible from the outside
alt self.purity(ex.id) {
- none {}
- some(pc) {
+ none => (),
+ some(pc) => {
if cmt.lp.is_none() {
self.report_purity_error(
pc, ex.span, at.ing_form(self.bccx.cmt_to_str(cmt)));
for self.walk_loans_of(ex.id, lp) |loan| {
alt loan.mutbl {
- m_mutbl | m_const { /*ok*/ }
- m_imm {
+ m_mutbl | m_const => { /*ok*/ }
+ m_imm => {
self.bccx.span_err(
ex.span,
fmt!{"%s prohibited due to outstanding loan",
// let y = &x; // x loaned out as immutable
// x.f = none; // changes type of y.f, which appears to be imm
alt *lp {
- lp_comp(lp_base, ck) if inherent_mutability(ck) != m_mutbl {
+ lp_comp(lp_base, ck) if inherent_mutability(ck) != m_mutbl => {
self.check_for_loan_conflicting_with_assignment(
at, ex, cmt, lp_base);
}
- lp_comp(*) | lp_local(*) | lp_arg(*) | lp_deref(*) {}
+ lp_comp(*) | lp_local(*) | lp_arg(*) | lp_deref(*) => ()
}
}
fn report_purity_error(pc: purity_cause, sp: span, msg: ~str) {
alt pc {
- pc_pure_fn {
+ pc_pure_fn => {
self.tcx().sess.span_err(
sp,
fmt!{"%s prohibited in pure context", msg});
}
- pc_cmt(e) {
+ pc_cmt(e) => {
if self.reported.insert(e.cmt.id, ()) {
self.tcx().sess.span_err(
e.cmt.span,
alt cmt.cat {
// Rvalues, locals, and arguments can be moved:
- cat_rvalue | cat_local(_) | cat_arg(_) { }
+ cat_rvalue | cat_local(_) | cat_arg(_) => {}
// We allow moving out of static items because the old code
// did. This seems consistent with permitting moves out of
// rvalues, I guess.
- cat_special(sk_static_item) { }
+ cat_special(sk_static_item) => {}
- cat_deref(_, _, unsafe_ptr) {
- }
+ cat_deref(_, _, unsafe_ptr) => {}
// Nothing else.
- _ {
+ _ => {
self.bccx.span_err(
cmt.span,
fmt!{"moving out of %s", self.bccx.cmt_to_str(cmt)});
// check for a conflicting loan:
let lp = alt cmt.lp {
- none { return; }
- some(lp) { lp }
+ none => return,
+ some(lp) => lp
};
for self.walk_loans_of(cmt.id, lp) |loan| {
self.bccx.span_err(
fn check_last_use(expr: @ast::expr) {
let cmt = self.bccx.cat_expr(expr);
let lp = alt cmt.lp {
- none { return; }
- some(lp) { lp }
+ none => return,
+ some(lp) => lp
};
for self.walk_loans_of(cmt.id, lp) |_loan| {
debug!{"Removing last use entry %? due to outstanding loan",
callee_span: span,
args: ~[@ast::expr]) {
alt self.purity(expr.id) {
- none {}
- some(pc) {
+ none => {}
+ some(pc) => {
self.check_pure_callee_or_arg(
pc, callee, callee_id, callee_span);
for args.each |arg| {
ty::node_id_to_type(self.tcx(), callee_id));
do vec::iter2(args, arg_tys) |arg, arg_ty| {
alt ty::resolved_mode(self.tcx(), arg_ty.mode) {
- ast::by_move {
+ ast::by_move => {
self.check_move_out(arg);
}
- ast::by_mutbl_ref {
+ ast::by_mutbl_ref => {
self.check_assignment(at_mutbl_ref, arg);
}
- ast::by_ref | ast::by_copy | ast::by_val {
+ ast::by_ref | ast::by_copy | ast::by_val => {
}
}
}
// able to "see" into those functions anyway, so it
// wouldn't be very helpful.
alt fk {
- visit::fk_ctor(*) {
+ visit::fk_ctor(*) => {
self.in_ctor = true;
self.declared_purity = decl.purity;
self.fn_args = @decl.inputs.map(|i| i.id );
}
visit::fk_anon(*) |
- visit::fk_fn_block(*) if is_stack_closure {
+ visit::fk_fn_block(*) if is_stack_closure => {
self.in_ctor = false;
// inherits the purity/fn_args from enclosing ctxt
}
visit::fk_anon(*) | visit::fk_fn_block(*) |
visit::fk_method(*) | visit::fk_item_fn(*) |
- visit::fk_dtor(*) {
+ visit::fk_dtor(*) => {
self.in_ctor = false;
self.declared_purity = decl.purity;
self.fn_args = @decl.inputs.map(|i| i.id );
&&self: check_loan_ctxt,
vt: visit::vt<check_loan_ctxt>) {
alt local.node.init {
- some({op: ast::init_move, expr: expr}) {
+ some({op: ast::init_move, expr: expr}) => {
self.check_move_out(expr);
}
- some({op: ast::init_assign, _}) | none {}
+ some({op: ast::init_assign, _}) | none => {}
}
visit::visit_local(local, self, vt);
}
self.check_for_conflicting_loans(expr.id);
alt expr.node {
- ast::expr_path(*) if self.bccx.last_use_map.contains_key(expr.id) {
+ ast::expr_path(*) if self.bccx.last_use_map.contains_key(expr.id) => {
self.check_last_use(expr);
}
- ast::expr_swap(l, r) {
+ ast::expr_swap(l, r) => {
self.check_assignment(at_swap, l);
self.check_assignment(at_swap, r);
}
- ast::expr_move(dest, src) {
+ ast::expr_move(dest, src) => {
self.check_assignment(at_straight_up, dest);
self.check_move_out(src);
}
- ast::expr_unary_move(src) {
+ ast::expr_unary_move(src) => {
self.check_move_out(src);
}
ast::expr_assign(dest, _) |
- ast::expr_assign_op(_, dest, _) {
+ ast::expr_assign_op(_, dest, _) => {
self.check_assignment(at_straight_up, dest);
}
ast::expr_fn(_, _, _, cap_clause) |
- ast::expr_fn_block(_, _, cap_clause) {
+ ast::expr_fn_block(_, _, cap_clause) => {
for (*cap_clause).each |cap_item| {
if cap_item.is_move {
let def = self.tcx().def_map.get(cap_item.id);
}
}
}
- ast::expr_addr_of(mutbl, base) {
+ ast::expr_addr_of(mutbl, base) => {
alt mutbl {
- m_const { /*all memory is const*/ }
- m_mutbl {
+ m_const => { /*all memory is const*/ }
+ m_mutbl => {
// If we are taking an &mut ptr, make sure the memory
// being pointed at is assignable in the first place:
self.check_assignment(at_mutbl_ref, base);
}
- m_imm {
+ m_imm => {
// XXX explain why no check is req'd here
}
}
}
- ast::expr_call(f, args, _) {
+ ast::expr_call(f, args, _) => {
self.check_call(expr, some(f), f.id, f.span, args);
}
ast::expr_index(_, rval) |
ast::expr_binary(_, _, rval)
- if self.bccx.method_map.contains_key(expr.id) {
+ if self.bccx.method_map.contains_key(expr.id) => {
self.check_call(expr,
none,
expr.callee_id,
~[rval]);
}
ast::expr_unary(*) | ast::expr_index(*)
- if self.bccx.method_map.contains_key(expr.id) {
+ if self.bccx.method_map.contains_key(expr.id) => {
self.check_call(expr,
none,
expr.callee_id,
expr.span,
~[]);
}
- _ { }
+ _ => { }
}
visit::visit_expr(expr, self, vt);
self.check_for_conflicting_loans(blk.node.id);
alt blk.node.rules {
- ast::default_blk {
+ ast::default_blk => {
}
- ast::unchecked_blk {
+ ast::unchecked_blk => {
self.declared_purity = ast::impure_fn;
}
- ast::unsafe_blk {
+ ast::unsafe_blk => {
self.declared_purity = ast::unsafe_fn;
}
}
self.root_ub = body.node.id;
alt fk {
- visit::fk_anon(*) | visit::fk_fn_block(*) {}
+ visit::fk_anon(*) | visit::fk_fn_block(*) => {}
visit::fk_item_fn(*) | visit::fk_method(*) |
- visit::fk_ctor(*) | visit::fk_dtor(*) {
+ visit::fk_ctor(*) | visit::fk_dtor(*) => {
self.item_ub = body.node.id;
}
}
// Special checks for various kinds of expressions:
alt ex.node {
- ast::expr_addr_of(mutbl, base) {
+ ast::expr_addr_of(mutbl, base) => {
let base_cmt = self.bccx.cat_expr(base);
// make sure that the thing we are pointing out stays valid
// for the lifetime `scope_r` of the resulting ptr:
let scope_r =
alt check ty::get(tcx.ty(ex)).struct {
- ty::ty_rptr(r, _) { r }
+ ty::ty_rptr(r, _) => r
};
self.guarantee_valid(base_cmt, mutbl, scope_r);
visit::visit_expr(ex, self, vt);
}
- ast::expr_call(f, args, _) {
+ ast::expr_call(f, args, _) => {
let arg_tys = ty::ty_fn_args(ty::expr_ty(self.tcx(), f));
let scope_r = ty::re_scope(ex.id);
do vec::iter2(args, arg_tys) |arg, arg_ty| {
alt ty::resolved_mode(self.tcx(), arg_ty.mode) {
- ast::by_mutbl_ref {
+ ast::by_mutbl_ref => {
let arg_cmt = self.bccx.cat_expr(arg);
self.guarantee_valid(arg_cmt, m_mutbl, scope_r);
}
- ast::by_ref {
+ ast::by_ref => {
let arg_cmt = self.bccx.cat_expr(arg);
self.guarantee_valid(arg_cmt, m_imm, scope_r);
}
- ast::by_val {
+ ast::by_val => {
// Rust's by-val does not actually give ownership to
// the callee. This means that if a pointer type is
// passed, it is effectively a borrow, and so the
//
alt opt_deref_kind(arg_ty.ty) {
some(deref_ptr(region_ptr(_))) |
- some(deref_ptr(unsafe_ptr)) {
+ some(deref_ptr(unsafe_ptr)) => {
/* region pointers are (by induction) guaranteed */
/* unsafe pointers are the user's problem */
}
some(deref_comp(_)) |
- none {
+ none => {
/* not a pointer, no worries */
}
- some(deref_ptr(_)) {
+ some(deref_ptr(_)) => {
let arg_cmt = self.bccx.cat_borrow_of_expr(arg);
self.guarantee_valid(arg_cmt, m_const, scope_r);
}
}
}
- ast::by_move | ast::by_copy {}
+ ast::by_move | ast::by_copy => {}
}
}
visit::visit_expr(ex, self, vt);
}
- ast::expr_alt(ex_v, arms, _) {
+ ast::expr_alt(ex_v, arms, _) => {
let cmt = self.bccx.cat_expr(ex_v);
for arms.each |arm| {
for arm.pats.each |pat| {
ast::expr_index(rcvr, _) |
ast::expr_binary(_, rcvr, _) |
- ast::expr_unary(_, rcvr) if self.bccx.method_map.contains_key(ex.id) {
+ ast::expr_unary(_, rcvr)
+ if self.bccx.method_map.contains_key(ex.id) => {
// Receivers in method calls are always passed by ref.
//
// Here, in an overloaded operator, the call is this expression,
}
ast::expr_field(rcvr, _, _)
- if self.bccx.method_map.contains_key(ex.id) {
+ if self.bccx.method_map.contains_key(ex.id) => {
// Receivers in method calls are always passed by ref.
//
// Here, the field a.b is in fact a closure. Eventually, this
}
// see explanation attached to the `root_ub` field:
- ast::expr_while(cond, body) {
+ ast::expr_while(cond, body) => {
// during the condition, can only root for the condition
self.root_ub = cond.id;
vt.visit_expr(cond, self, vt);
}
// see explanation attached to the `root_ub` field:
- ast::expr_loop(body) {
+ ast::expr_loop(body) => {
self.root_ub = body.node.id;
visit::visit_expr(ex, self, vt);
}
// duration of the reference: if there is an attempt to move
// it within that scope, the loan will be detected and an
// error will be reported.
- some(_) {
+ some(_) => {
alt self.bccx.loan(cmt, scope_r, req_mutbl) {
err(e) => { self.bccx.report(e); }
ok(loans) if loans.len() == 0 => {}
// also check that the mutability of the desired pointer
// matches with the actual mutability (but if an immutable
// pointer is desired, that is ok as long as we are pure)
- none {
+ none => {
let result: bckres<preserve_condition> = {
do self.check_mutbl(req_mutbl, cmt).chain |pc1| {
do self.bccx.preserve(cmt, scope_r,
};
alt result {
- ok(pc_ok) {
+ ok(pc_ok) => {
// we were able guarantee the validity of the ptr,
// perhaps by rooting or because it is immutably
// rooted. good.
self.bccx.stable_paths += 1;
}
- ok(pc_if_pure(e)) {
+ ok(pc_if_pure(e)) => {
// we are only able to guarantee the validity if
// the scope is pure
alt scope_r {
fn add_loans(scope_id: ast::node_id, loans: @dvec<loan>) {
alt self.req_maps.req_loan_map.find(scope_id) {
- some(l) {
+ some(l) => {
(*l).push(loans);
}
- none {
+ none => {
self.req_maps.req_loan_map.insert(
scope_id, @dvec::from_vec(~[mut loans]));
}
let tcx = self.tcx();
alt pat.node {
- ast::pat_wild {
+ ast::pat_wild => {
// _
}
- ast::pat_enum(_, none) {
+ ast::pat_enum(_, none) => {
// variant(*)
}
- ast::pat_enum(_, some(subpats)) {
+ ast::pat_enum(_, some(subpats)) => {
// variant(x, y, z)
let enum_did = alt self.bccx.tcx.def_map
.find(pat.id) {
- some(ast::def_variant(enum_did, _)) {enum_did}
- e {tcx.sess.span_bug(pat.span,
- fmt!{"resolved to %?, \
- not variant", e})}
+ some(ast::def_variant(enum_did, _)) => enum_did,
+ e => tcx.sess.span_bug(pat.span,
+ fmt!{"resolved to %?, \
+ not variant", e})
};
for subpats.each |subpat| {
}
}
- ast::pat_ident(_, _, none) if self.pat_is_variant(pat) {
+ ast::pat_ident(_, _, none) if self.pat_is_variant(pat) => {
// nullary variant
debug!{"nullary variant"};
}
- ast::pat_ident(_, id, o_pat) {
+ ast::pat_ident(_, id, o_pat) => {
// XXX: Needs to take by-ref/by-val into account.
// x or x @ p --- `x` must remain valid for the scope of the alt
}
}
- ast::pat_rec(field_pats, _) {
+ ast::pat_rec(field_pats, _) => {
// {f1: p1, ..., fN: pN}
for field_pats.each |fp| {
let cmt_field = self.bccx.cat_field(fp.pat, cmt, fp.ident);
}
}
- ast::pat_tup(subpats) {
+ ast::pat_tup(subpats) => {
// (p1, ..., pN)
for subpats.each |subpat| {
let subcmt = self.bccx.cat_tuple_elt(subpat, cmt);
}
}
- ast::pat_box(subpat) | ast::pat_uniq(subpat) {
+ ast::pat_box(subpat) | ast::pat_uniq(subpat) => {
// @p1, ~p1
alt self.bccx.cat_deref(subpat, cmt, 0u, true) {
- some(subcmt) {
+ some(subcmt) => {
self.gather_pat(subcmt, subpat, arm_id, alt_id);
}
- none {
+ none => {
tcx.sess.span_bug(pat.span, ~"Non derefable type");
}
}
}
- ast::pat_lit(_) | ast::pat_range(_, _) { /*always ok*/ }
+ ast::pat_lit(_) | ast::pat_range(_, _) => { /*always ok*/ }
}
}
}
alt cmt.cat {
- cat_binding(_) | cat_rvalue | cat_special(_) {
+ cat_binding(_) | cat_rvalue | cat_special(_) => {
// should never be loanable
self.bccx.tcx.sess.span_bug(
cmt.span,
~"rvalue with a non-none lp");
}
- cat_local(local_id) | cat_arg(local_id) {
+ cat_local(local_id) | cat_arg(local_id) => {
let local_scope_id = self.tcx().region_map.get(local_id);
self.ok_with_loan_of(cmt, ty::re_scope(local_scope_id), req_mutbl)
}
- cat_stack_upvar(cmt) {
+ cat_stack_upvar(cmt) => {
self.loan(cmt, req_mutbl) // NDM correct?
}
- cat_discr(base, _) {
+ cat_discr(base, _) => {
self.loan(base, req_mutbl)
}
cat_comp(cmt_base, comp_field(*)) |
cat_comp(cmt_base, comp_index(*)) |
- cat_comp(cmt_base, comp_tuple) {
+ cat_comp(cmt_base, comp_tuple) => {
// For most components, the type of the embedded data is
// stable. Therefore, the base structure need only be
// const---unless the component must be immutable. In
// overwritten and the component along with it.
self.loan_stable_comp(cmt, cmt_base, req_mutbl)
}
- cat_comp(cmt_base, comp_variant(enum_did)) {
+ cat_comp(cmt_base, comp_variant(enum_did)) => {
// For enums, the memory is unstable if there are multiple
// variants, because if the enum value is overwritten then
// the memory changes type.
self.loan_unstable_deref(cmt, cmt_base, req_mutbl)
}
}
- cat_deref(cmt_base, _, uniq_ptr) {
+ cat_deref(cmt_base, _, uniq_ptr) => {
// For unique pointers, the memory being pointed out is
// unstable because if the unique pointer is overwritten
// then the memory is freed.
}
cat_deref(cmt1, _, unsafe_ptr) |
cat_deref(cmt1, _, gc_ptr) |
- cat_deref(cmt1, _, region_ptr(_)) {
+ cat_deref(cmt1, _, region_ptr(_)) => {
// Aliased data is simply not lendable.
self.bccx.tcx.sess.span_bug(
cmt.span,
cmt_base: cmt,
req_mutbl: ast::mutability) -> bckres<()> {
let base_mutbl = alt req_mutbl {
- m_imm { m_imm }
- m_const | m_mutbl { m_const }
+ m_imm => m_imm,
+ m_const | m_mutbl => m_const
};
do self.loan(cmt_base, base_mutbl).chain |_ok| {
let _i = indenter();
alt cmt.cat {
- cat_special(sk_self) | cat_special(sk_heap_upvar) {
+ cat_special(sk_self) | cat_special(sk_heap_upvar) => {
self.compare_scope(cmt, ty::re_scope(self.item_ub))
}
- cat_special(sk_static_item) | cat_special(sk_method) {
+ cat_special(sk_static_item) | cat_special(sk_method) => {
ok(pc_ok)
}
- cat_rvalue {
+ cat_rvalue => {
// when we borrow an rvalue, we can keep it rooted but only
// up to the root_ub point
// FIXME(#2977)--need to update trans!
self.compare_scope(cmt, scope_region)
}
- cat_stack_upvar(cmt) {
+ cat_stack_upvar(cmt) => {
self.preserve(cmt)
}
- cat_local(local_id) {
+ cat_local(local_id) => {
// Normally, local variables are lendable, and so this
// case should never trigger. However, if we are
// preserving an expression like a.b where the field `b`
let local_scope_id = self.tcx().region_map.get(local_id);
self.compare_scope(cmt, ty::re_scope(local_scope_id))
}
- cat_binding(local_id) {
+ cat_binding(local_id) => {
// Bindings are these kind of weird implicit pointers (cc
// #2329). We require (in gather_loans) that they be
// rooted in an immutable location.
let local_scope_id = self.tcx().region_map.get(local_id);
self.compare_scope(cmt, ty::re_scope(local_scope_id))
}
- cat_arg(local_id) {
+ cat_arg(local_id) => {
// This can happen as not all args are lendable (e.g., &&
// modes). In that case, the caller guarantees stability
// for at least the scope of the fn. This is basically a
}
cat_comp(cmt_base, comp_field(*)) |
cat_comp(cmt_base, comp_index(*)) |
- cat_comp(cmt_base, comp_tuple) {
+ cat_comp(cmt_base, comp_tuple) => {
// Most embedded components: if the base is stable, the
// type never changes.
self.preserve(cmt_base)
}
- cat_comp(cmt_base, comp_variant(enum_did)) {
+ cat_comp(cmt_base, comp_variant(enum_did)) => {
if ty::enum_is_univariant(self.tcx(), enum_did) {
self.preserve(cmt_base)
} else {
self.require_imm(cmt, cmt_base, err_mut_variant)
}
}
- cat_deref(cmt_base, _, uniq_ptr) {
+ cat_deref(cmt_base, _, uniq_ptr) => {
// Overwriting the base could cause this memory to be
// freed, so require imm.
self.require_imm(cmt, cmt_base, err_mut_uniq)
}
- cat_deref(_, _, region_ptr(region)) {
+ cat_deref(_, _, region_ptr(region)) => {
// References are always "stable" for lifetime `region` by
// induction (when the reference of type &MT was created,
// the memory must have been stable).
self.compare_scope(cmt, region)
}
- cat_deref(_, _, unsafe_ptr) {
+ cat_deref(_, _, unsafe_ptr) => {
// Unsafe pointers are the user's problem
ok(pc_ok)
}
- cat_deref(base, derefs, gc_ptr) {
+ cat_deref(base, derefs, gc_ptr) => {
// GC'd pointers of type @MT: if this pointer lives in
// immutable, stable memory, then everything is fine. But
// otherwise we have no guarantee the pointer will stay
ok(pc_ok) => {
ok(pc_ok)
}
- ok(pc_if_pure(_)) {
+ ok(pc_if_pure(_)) => {
debug!{"must root @T, otherwise purity req'd"};
self.attempt_root(cmt, base, derefs)
}
self.attempt_root(cmt, base, derefs)
}
}
- cat_discr(base, alt_id) {
+ cat_discr(base, alt_id) => {
// Subtle: in an alt, we must ensure that each binding
// variable remains valid for the duration of the arm in
// which it appears, presuming that this arm is taken.
// named and add that
let implicit_mode = alt fn_proto {
- ast::proto_block { cap_ref }
- ast::proto_bare | ast::proto_box | ast::proto_uniq { cap_copy }
+ ast::proto_block => cap_ref,
+ ast::proto_bare | ast::proto_box | ast::proto_uniq => cap_copy
};
do vec::iter(*freevars) |fvar| {
let fvar_def_id = ast_util::def_id_of_def(fvar.def).node;
alt cap_map.find(fvar_def_id) {
- option::some(_) { /* was explicitly named, do nothing */ }
- option::none {
+ option::some(_) => { /* was explicitly named, do nothing */ }
+ option::none => {
cap_map.insert(fvar_def_id, {def:fvar.def,
span: fvar.span,
cap_item: none,
fn check_expr(tcx: ty::ctxt, ex: @expr, &&s: (), v: visit::vt<()>) {
visit::visit_expr(ex, s, v);
alt ex.node {
- expr_alt(scrut, arms, mode) {
+ expr_alt(scrut, arms, mode) => {
check_arms(tcx, arms);
/* Check for exhaustiveness */
// Check for empty enum, because is_useful only works on inhabited
return;
}
alt ty::get(pat_ty).struct {
- ty_enum(did, _) {
+ ty_enum(did, _) => {
if (*enum_variants(tcx, did)).is_empty() && arms.is_empty() {
return;
}
}
- _ { /* We assume only enum types can be uninhabited */ }
+ _ => { /* We assume only enum types can be uninhabited */ }
}
if mode == alt_exhaustive {
check_exhaustive(tcx, ex.span, arms);
}
}
- _ { }
+ _ => ()
}
}
for arm.pats.each |pat| {
let v = ~[pat];
alt is_useful(tcx, seen, v) {
- not_useful {
+ not_useful => {
tcx.sess.span_err(pat.span, ~"unreachable pattern");
}
- _ {}
+ _ => ()
}
if option::is_none(arm.guard) { vec::push(seen, v); }
}
fn check_exhaustive(tcx: ty::ctxt, sp: span, pats: ~[@pat]) {
assert(pats.is_not_empty());
let ext = alt is_useful(tcx, vec::map(pats, |p| ~[p]), ~[wild()]) {
- not_useful { return; } // This is good, wildcard pattern isn't reachable
- useful_ { none }
- useful(ty, ctor) {
+ not_useful => return, // This is good, wildcard pattern isn't reachable
+ useful_ => none,
+ useful(ty, ctor) => {
alt ty::get(ty).struct {
- ty::ty_bool {
+ ty::ty_bool => {
alt check ctor {
- val(const_int(1i64)) { some(@~"true") }
- val(const_int(0i64)) { some(@~"false") }
+ val(const_int(1i64)) => some(@~"true"),
+ val(const_int(0i64)) => some(@~"false")
}
}
- ty::ty_enum(id, _) {
- let vid = alt check ctor { variant(id) { id } };
+ ty::ty_enum(id, _) => {
+ let vid = alt check ctor { variant(id) => id };
alt check vec::find(*ty::enum_variants(tcx, id),
|v| v.id == vid) {
- some(v) { some(v.name) }
+ some(v) => some(v.name)
}
}
- _ { none }
+ _ => none
}
}
};
let msg = ~"non-exhaustive patterns" + alt ext {
- some(s) { ~": " + *s + ~" not covered" }
- none { ~"" }
+ some(s) => ~": " + *s + ~" not covered",
+ none => ~""
};
tcx.sess.span_err(sp, msg);
}
if m.len() == 0u { return useful_; }
if m[0].len() == 0u { return not_useful; }
let real_pat = alt vec::find(m, |r| r[0].id != 0) {
- some(r) { r[0] } none { v[0] }
+ some(r) => r[0], none => v[0]
};
let left_ty = if real_pat.id == 0 { ty::mk_nil(tcx) }
else { ty::node_id_to_type(tcx, real_pat.id) };
alt pat_ctor_id(tcx, v[0]) {
- none {
+ none => {
alt missing_ctor(tcx, m, left_ty) {
- none {
+ none => {
alt ty::get(left_ty).struct {
- ty::ty_bool {
+ ty::ty_bool => {
alt is_useful_specialized(tcx, m, v, val(const_int(1i64)),
0u, left_ty){
- not_useful {
+ not_useful => {
is_useful_specialized(tcx, m, v, val(const_int(0i64)),
0u, left_ty)
}
- u { u }
+ u => u
}
}
- ty::ty_enum(eid, _) {
+ ty::ty_enum(eid, _) => {
for (*ty::enum_variants(tcx, eid)).each |va| {
alt is_useful_specialized(tcx, m, v, variant(va.id),
va.args.len(), left_ty) {
- not_useful {}
- u { return u; }
+ not_useful => (),
+ u => return u
}
}
not_useful
}
- _ {
+ _ => {
let arity = ctor_arity(tcx, single, left_ty);
is_useful_specialized(tcx, m, v, single, arity, left_ty)
}
}
}
- some(ctor) {
+ some(ctor) => {
alt is_useful(tcx, vec::filter_map(m, |r| default(tcx, r) ),
vec::tail(v)) {
- useful_ { useful(left_ty, ctor) }
- u { u }
+ useful_ => useful(left_ty, ctor),
+ u => u
}
}
}
}
- some(v0_ctor) {
+ some(v0_ctor) => {
let arity = ctor_arity(tcx, v0_ctor, left_ty);
is_useful_specialized(tcx, m, v, v0_ctor, arity, left_ty)
}
arity: uint, lty: ty::t) -> useful {
let ms = vec::filter_map(m, |r| specialize(tcx, r, ctor, arity, lty) );
alt is_useful(tcx, ms, option::get(specialize(tcx, v, ctor, arity, lty))){
- useful_ { useful(lty, ctor) }
- u { u }
+ useful_ => useful(lty, ctor),
+ u => u
}
}
pat_wild => { none }
pat_ident(_, _, _) | pat_enum(_, _) => {
alt tcx.def_map.find(pat.id) {
- some(def_variant(_, id)) { some(variant(id)) }
- _ { none }
+ some(def_variant(_, id)) => some(variant(id)),
+ _ => none
}
}
pat_lit(expr) => { some(val(eval_const_expr(tcx, expr))) }
fn missing_ctor(tcx: ty::ctxt, m: matrix, left_ty: ty::t) -> option<ctor> {
alt ty::get(left_ty).struct {
- ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_tup(_) | ty::ty_rec(_) {
+ ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_tup(_) | ty::ty_rec(_) => {
for m.each |r| {
if !is_wild(tcx, r[0]) { return none; }
}
return some(single);
}
- ty::ty_enum(eid, _) {
+ ty::ty_enum(eid, _) => {
let mut found = ~[];
for m.each |r| {
do option::iter(pat_ctor_id(tcx, r[0])) |id| {
fail;
} else { none }
}
- ty::ty_nil { none }
- ty::ty_bool {
+ ty::ty_nil => none,
+ ty::ty_bool => {
let mut true_found = false, false_found = false;
for m.each |r| {
alt check pat_ctor_id(tcx, r[0]) {
- none {}
- some(val(const_int(1i64))) { true_found = true; }
- some(val(const_int(0i64))) { false_found = true; }
+ none => (),
+ some(val(const_int(1i64))) => true_found = true,
+ some(val(const_int(0i64))) => false_found = true
}
}
if true_found && false_found { none }
else if true_found { some(val(const_int(0i64))) }
else { some(val(const_int(1i64))) }
}
- _ { some(single) }
+ _ => some(single)
}
}
fn ctor_arity(tcx: ty::ctxt, ctor: ctor, ty: ty::t) -> uint {
alt ty::get(ty).struct {
- ty::ty_tup(fs) { fs.len() }
- ty::ty_rec(fs) { fs.len() }
- ty::ty_box(_) | ty::ty_uniq(_) { 1u }
- ty::ty_enum(eid, _) {
- let id = alt check ctor { variant(id) { id } };
+ ty::ty_tup(fs) => fs.len(),
+ ty::ty_rec(fs) => fs.len(),
+ ty::ty_box(_) | ty::ty_uniq(_) => 1u,
+ ty::ty_enum(eid, _) => {
+ let id = alt check ctor { variant(id) => id };
alt check vec::find(*ty::enum_variants(tcx, eid), |v| v.id == id ) {
- some(v) { v.args.len() }
+ some(v) => v.args.len()
}
}
- _ { 0u }
+ _ => 0u
}
}
left_ty: ty::t) -> option<~[@pat]> {
let r0 = raw_pat(r[0]);
alt r0.node {
- pat_wild { some(vec::append(vec::from_elem(arity, wild()),
- vec::tail(r))) }
- pat_ident(_, _, _) {
+ pat_wild => some(vec::append(vec::from_elem(arity, wild()),
+ vec::tail(r))),
+ pat_ident(_, _, _) => {
alt tcx.def_map.find(r0.id) {
- some(def_variant(_, id)) {
+ some(def_variant(_, id)) => {
if variant(id) == ctor_id { some(vec::tail(r)) }
else { none }
}
- _ { some(vec::append(vec::from_elem(arity, wild()), vec::tail(r))) }
+ _ => some(vec::append(vec::from_elem(arity, wild()), vec::tail(r)))
}
}
- pat_enum(_, args) {
+ pat_enum(_, args) => {
alt check tcx.def_map.get(r0.id) {
- def_variant(_, id) if variant(id) == ctor_id {
+ def_variant(_, id) if variant(id) == ctor_id => {
let args = alt args {
- some(args) { args }
- none { vec::from_elem(arity, wild()) }
+ some(args) => args,
+ none => vec::from_elem(arity, wild())
};
some(vec::append(args, vec::tail(r)))
}
- def_variant(_, _) { none }
+ def_variant(_, _) => none
}
}
- pat_rec(flds, _) {
+ pat_rec(flds, _) => {
let ty_flds = alt check ty::get(left_ty).struct {
- ty::ty_rec(flds) { flds }
+ ty::ty_rec(flds) => flds
};
let args = vec::map(ty_flds, |ty_f| {
alt vec::find(flds, |f| f.ident == ty_f.ident ) {
- some(f) { f.pat } _ { wild() }
+ some(f) => f.pat, _ => wild()
}
});
some(vec::append(args, vec::tail(r)))
}
- pat_tup(args) { some(vec::append(args, vec::tail(r))) }
- pat_box(a) | pat_uniq(a) { some(vec::append(~[a], vec::tail(r))) }
- pat_lit(expr) {
+ pat_tup(args) => some(vec::append(args, vec::tail(r))),
+ 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 {
- 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 }
+ 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 }
}
- pat_range(lo, hi) {
+ pat_range(lo, hi) => {
let (c_lo, c_hi) = alt check ctor_id {
- val(v) { (v, v) }
- range(lo, hi) { (lo, hi) }
- single { return some(vec::tail(r)); }
+ val(v) => (v, v),
+ range(lo, hi) => (lo, hi),
+ single => return some(vec::tail(r)),
};
let v_lo = eval_const_expr(tcx, lo),
v_hi = eval_const_expr(tcx, hi);
fn is_refutable(tcx: ty::ctxt, pat: @pat) -> bool {
alt tcx.def_map.find(pat.id) {
- some(def_variant(enum_id, var_id)) {
+ some(def_variant(enum_id, var_id)) => {
if vec::len(*ty::enum_variants(tcx, enum_id)) != 1u { return true; }
}
- _ {}
+ _ => ()
}
alt pat.node {
def_map: resolve3::DefMap,
it: @item, &&_is_const: bool, v: visit::vt<bool>) {
alt it.node {
- item_const(_, ex) {
+ item_const(_, ex) => {
v.visit_expr(ex, true, v);
check_item_recursion(sess, ast_map, def_map, it);
}
- item_enum(vs, _) {
+ item_enum(vs, _) => {
for vs.each |var| {
do option::iter(var.node.disr_expr) |ex| {
v.visit_expr(ex, true, v);
}
}
}
- _ { visit::visit_item(it, false, v); }
+ _ => visit::visit_item(it, false, v)
}
}
fn is_str(e: @expr) -> bool {
alt e.node {
expr_vstore(@{node: expr_lit(@{node: lit_str(_), _}), _},
- vstore_uniq) { true }
- _ { false }
+ vstore_uniq) => true,
+ _ => false
}
}
alt p.node {
// Let through plain ~-string literals here
- pat_lit(a) { if !is_str(a) { v.visit_expr(a, true, v); } }
- pat_range(a, b) {
+ pat_lit(a) => if !is_str(a) { v.visit_expr(a, true, v); }
+ pat_range(a, b) => {
if !is_str(a) { v.visit_expr(a, true, v); }
if !is_str(b) { v.visit_expr(b, true, v); }
}
- _ { visit::visit_pat(p, false, v); }
+ _ => visit::visit_pat(p, false, v)
}
}
if is_const {
alt e.node {
expr_unary(box(_), _) | expr_unary(uniq(_), _) |
- expr_unary(deref, _){
+ expr_unary(deref, _) => {
sess.span_err(e.span,
~"disallowed operator in constant expression");
return;
}
- expr_lit(@{node: lit_str(_), _}) { }
- expr_binary(_, _, _) | expr_unary(_, _) {
+ expr_lit(@{node: lit_str(_), _}) => { }
+ expr_binary(_, _, _) | expr_unary(_, _) => {
if method_map.contains_key(e.id) {
sess.span_err(e.span, ~"user-defined operators are not \
allowed in constant expressions");
}
}
- expr_lit(_) {}
- expr_cast(_, _) {
+ expr_lit(_) => (),
+ expr_cast(_, _) => {
let ety = ty::expr_ty(tcx, e);
if !ty::type_is_numeric(ety) {
sess.span_err(e.span, ~"can not cast to `" +
~"` in a constant expression");
}
}
- expr_path(_) {
+ expr_path(_) => {
alt def_map.find(e.id) {
- some(def_const(def_id)) {
+ some(def_const(def_id)) => {
if !ast_util::is_local(def_id) {
sess.span_err(
e.span, ~"paths in constants may only refer to \
crate-local constants");
}
}
- _ {
+ _ => {
sess.span_err(
e.span,
~"paths in constants may only refer to constants");
expr_vec(_, m_imm) |
expr_addr_of(m_imm, _) |
expr_tup(*) |
- expr_rec(*) { }
- expr_addr_of(*) {
+ expr_rec(*) => { }
+ expr_addr_of(*) => {
sess.span_err(
e.span,
~"borrowed pointers in constants may only refer to \
immutable values");
}
- _ {
+ _ => {
sess.span_err(e.span,
~"constant contains unimplemented expression type");
return;
}
}
alt e.node {
- expr_lit(@{node: lit_int(v, t), _}) {
+ expr_lit(@{node: lit_int(v, t), _}) => {
if t != ty_char {
if (v as u64) > ast_util::int_ty_max(
if t == ty_i { sess.targ_cfg.int_type } else { t }) {
}
}
}
- expr_lit(@{node: lit_uint(v, t), _}) {
+ expr_lit(@{node: lit_uint(v, t), _}) => {
if v > ast_util::uint_ty_max(
if t == ty_u { sess.targ_cfg.uint_type } else { t }) {
sess.span_err(e.span, ~"literal out of range for its type");
}
}
- _ {}
+ _ => ()
}
visit::visit_expr(e, is_const, v);
}
fn visit_expr(e: @expr, &&env: env, v: visit::vt<env>) {
alt e.node {
- expr_path(path) {
+ expr_path(path) => {
alt env.def_map.find(e.id) {
- some(def_const(def_id)) {
+ some(def_const(def_id)) => {
alt check env.ast_map.get(def_id.node) {
- ast_map::node_item(it, _) {
+ ast_map::node_item(it, _) => {
v.visit_item(it, env, v);
}
}
}
- _ { }
+ _ => ()
}
}
- _ { }
+ _ => ()
}
visit::visit_expr(e, env, v);
}
},
visit_expr: |e: @expr, cx: ctx, v: visit::vt<ctx>| {
alt e.node {
- expr_while(e, b) {
+ expr_while(e, b) => {
v.visit_expr(e, cx, v);
v.visit_block(b, {in_loop: true with cx}, v);
}
- expr_loop(b) {
+ expr_loop(b) => {
v.visit_block(b, {in_loop: true with cx}, v);
}
- expr_fn(_, _, _, _) {
+ expr_fn(_, _, _, _) => {
visit::visit_expr(e, {in_loop: false, can_ret: true}, v);
}
- expr_fn_block(_, b, _) {
+ expr_fn_block(_, b, _) => {
v.visit_block(b, {in_loop: false, can_ret: false}, v);
}
- expr_loop_body(@{node: expr_fn_block(_, b, _), _}) {
+ expr_loop_body(@{node: expr_fn_block(_, b, _), _}) => {
let blk = is_blockish(ty::ty_fn_proto(ty::expr_ty(tcx, e)));
v.visit_block(b, {in_loop: true, can_ret: blk}, v);
}
- expr_break {
+ expr_break => {
if !cx.in_loop {
tcx.sess.span_err(e.span, ~"`break` outside of loop");
}
}
- expr_again {
+ expr_again => {
if !cx.in_loop {
tcx.sess.span_err(e.span, ~"`again` outside of loop");
}
}
- expr_ret(oe) {
+ expr_ret(oe) => {
if !cx.can_ret {
tcx.sess.span_err(e.span, ~"`ret` in block function");
}
visit::visit_expr_opt(oe, cx, v);
}
- _ { visit::visit_expr(e, cx, v); }
+ _ => visit::visit_expr(e, cx, v)
}
}
with *visit::default_visitor()
fn join(a: constness, b: constness) -> constness {
alt (a,b) {
- (integral_const, integral_const) { integral_const }
+ (integral_const, integral_const) => integral_const,
(integral_const, general_const)
| (general_const, integral_const)
- | (general_const, general_const) { general_const }
- _ { non_const }
+ | (general_const, general_const) => general_const,
+ _ => non_const
}
}
tcx: ty::ctxt) -> constness {
let did = ast_util::local_def(e.id);
alt tcx.ccache.find(did) {
- some(x) { x }
- none {
+ some(x) => x,
+ none => {
let cn =
alt e.node {
- ast::expr_lit(lit) {
+ ast::expr_lit(lit) => {
alt lit.node {
ast::lit_str(*) |
- ast::lit_float(*) { general_const }
- _ { integral_const }
+ ast::lit_float(*) => general_const,
+ _ => integral_const
}
}
ast::expr_copy(inner) |
- ast::expr_unary(_, inner) {
+ ast::expr_unary(_, inner) => {
classify(inner, def_map, tcx)
}
- ast::expr_binary(_, a, b) {
+ ast::expr_binary(_, a, b) => {
join(classify(a, def_map, tcx),
classify(b, def_map, tcx))
}
ast::expr_tup(es) |
- ast::expr_vec(es, ast::m_imm) {
+ ast::expr_vec(es, ast::m_imm) => {
join_all(vec::map(es, |e| classify(e, def_map, tcx)))
}
- ast::expr_vstore(e, vstore) {
+ ast::expr_vstore(e, vstore) => {
alt vstore {
ast::vstore_fixed(_) |
- ast::vstore_slice(_) { classify(e, def_map, tcx) }
+ ast::vstore_slice(_) => classify(e, def_map, tcx),
ast::vstore_uniq |
- ast::vstore_box { non_const }
+ ast::vstore_box => non_const
}
}
- ast::expr_rec(fs, none) {
+ ast::expr_rec(fs, none) => {
let cs = do vec::map(fs) |f| {
if f.node.mutbl == ast::m_imm {
classify(f.node.expr, def_map, tcx)
join_all(cs)
}
- ast::expr_cast(base, _) {
+ ast::expr_cast(base, _) => {
let ty = ty::expr_ty(tcx, e);
let base = classify(base, def_map, tcx);
if ty::type_is_integral(ty) {
}
}
- ast::expr_field(base, _, _) {
+ ast::expr_field(base, _, _) => {
classify(base, def_map, tcx)
}
- ast::expr_index(base, idx) {
+ ast::expr_index(base, idx) => {
join(classify(base, def_map, tcx),
classify(idx, def_map, tcx))
}
- ast::expr_addr_of(ast::m_imm, base) {
+ ast::expr_addr_of(ast::m_imm, base) => {
classify(base, def_map, tcx)
}
// FIXME: #1272, we can probably do something CCI-ish
// surrounding nonlocal constants. But we don't yet.
- ast::expr_path(_) {
+ ast::expr_path(_) => {
alt def_map.find(e.id) {
- some(ast::def_const(def_id)) {
+ some(ast::def_const(def_id)) => {
if ast_util::is_local(def_id) {
let ty = ty::expr_ty(tcx, e);
if ty::type_is_integral(ty) {
non_const
}
}
- some(_) {
+ some(_) => {
non_const
}
- none {
+ none => {
tcx.sess.span_bug(e.span,
~"unknown path when \
classifying constants");
}
}
- _ { non_const }
+ _ => non_const
};
tcx.ccache.insert(did, cn);
cn
import middle::ty;
fn fromb(b: bool) -> const_val { const_int(b as i64) }
alt check e.node {
- expr_unary(neg, inner) {
+ expr_unary(neg, inner) => {
alt check eval_const_expr(tcx, inner) {
- const_float(f) { const_float(-f) }
- const_int(i) { const_int(-i) }
- const_uint(i) { const_uint(-i) }
+ const_float(f) => const_float(-f),
+ const_int(i) => const_int(-i),
+ const_uint(i) => const_uint(-i)
}
}
- expr_unary(not, inner) {
+ expr_unary(not, inner) => {
alt check eval_const_expr(tcx, inner) {
- const_int(i) { const_int(!i) }
- const_uint(i) { const_uint(!i) }
+ const_int(i) => const_int(!i),
+ const_uint(i) => const_uint(!i)
}
}
- expr_binary(op, a, b) {
+ expr_binary(op, a, b) => {
alt check (eval_const_expr(tcx, a), eval_const_expr(tcx, b)) {
- (const_float(a), const_float(b)) {
+ (const_float(a), const_float(b)) => {
alt check op {
- add { const_float(a + b) } subtract { const_float(a - b) }
- mul { const_float(a * b) } div { const_float(a / b) }
- rem { const_float(a % b) } eq { fromb(a == b) }
- lt { fromb(a < b) } le { fromb(a <= b) } ne { fromb(a != b) }
- ge { fromb(a >= b) } gt { fromb(a > b) }
+ add => const_float(a + b),
+ subtract => const_float(a - b),
+ mul => const_float(a * b),
+ div => const_float(a / b),
+ rem => const_float(a % b),
+ eq => fromb(a == b),
+ lt => fromb(a < b),
+ le => fromb(a <= b),
+ ne => fromb(a != b),
+ ge => fromb(a >= b),
+ gt => fromb(a > b)
}
}
- (const_int(a), const_int(b)) {
+ (const_int(a), const_int(b)) => {
alt check op {
- add { const_int(a + b) } subtract { const_int(a - b) }
- mul { const_int(a * b) } div { const_int(a / b) }
- rem { const_int(a % b) } and | bitand { const_int(a & b) }
- or | bitor { const_int(a | b) } bitxor { const_int(a ^ b) }
- shl { const_int(a << b) } shr { const_int(a >> b) }
- eq { fromb(a == b) } lt { fromb(a < b) }
- le { fromb(a <= b) } ne { fromb(a != b) }
- ge { fromb(a >= b) } gt { fromb(a > b) }
+ add => const_int(a + b),
+ subtract => const_int(a - b),
+ mul => const_int(a * b),
+ div => const_int(a / b),
+ rem => const_int(a % b),
+ and | bitand => const_int(a & b),
+ or | bitor => const_int(a | b),
+ bitxor => const_int(a ^ b),
+ shl => const_int(a << b),
+ shr => const_int(a >> b),
+ eq => fromb(a == b),
+ lt => fromb(a < b),
+ le => fromb(a <= b),
+ ne => fromb(a != b),
+ ge => fromb(a >= b),
+ gt => fromb(a > b)
}
}
- (const_uint(a), const_uint(b)) {
+ (const_uint(a), const_uint(b)) => {
alt check op {
- add { const_uint(a + b) } subtract { const_uint(a - b) }
- mul { const_uint(a * b) } div { const_uint(a / b) }
- rem { const_uint(a % b) } and | bitand { const_uint(a & b) }
- or | bitor { const_uint(a | b) } bitxor { const_uint(a ^ b) }
- shl { const_uint(a << b) } shr { const_uint(a >> b) }
- eq { fromb(a == b) } lt { fromb(a < b) }
- le { fromb(a <= b) } ne { fromb(a != b) }
- ge { fromb(a >= b) } gt { fromb(a > b) }
+ add => const_uint(a + b),
+ subtract => const_uint(a - b),
+ mul => const_uint(a * b),
+ div => const_uint(a / b),
+ rem => const_uint(a % b),
+ and | bitand => const_uint(a & b),
+ or | bitor => const_uint(a | b),
+ bitxor => const_uint(a ^ b),
+ shl => const_uint(a << b),
+ shr => const_uint(a >> b),
+ eq => fromb(a == b),
+ lt => fromb(a < b),
+ le => fromb(a <= b),
+ ne => fromb(a != b),
+ ge => fromb(a >= b),
+ gt => fromb(a > b)
}
}
// shifts can have any integral type as their rhs
- (const_int(a), const_uint(b)) {
+ (const_int(a), const_uint(b)) => {
alt check op {
- shl { const_int(a << b) } shr { const_int(a >> b) }
+ shl => const_int(a << b),
+ shr => const_int(a >> b)
}
}
- (const_uint(a), const_int(b)) {
+ (const_uint(a), const_int(b)) => {
alt check op {
- shl { const_uint(a << b) } shr { const_uint(a >> b) }
+ shl => const_uint(a << b),
+ shr => const_uint(a >> b)
}
}
}
}
- expr_cast(base, _) {
+ expr_cast(base, _) => {
let ety = ty::expr_ty(tcx, e);
let base = eval_const_expr(tcx, base);
alt check ty::get(ety).struct {
- ty::ty_float(_) {
+ ty::ty_float(_) => {
alt check base {
- const_uint(u) { const_float(u as f64) }
- const_int(i) { const_float(i as f64) }
- const_float(_) { base }
+ const_uint(u) => const_float(u as f64),
+ const_int(i) => const_float(i as f64),
+ const_float(_) => base
}
}
- ty::ty_uint(_) {
+ ty::ty_uint(_) => {
alt check base {
- const_uint(_) { base }
- const_int(i) { const_uint(i as u64) }
- const_float(f) { const_uint(f as u64) }
+ const_uint(_) => base,
+ const_int(i) => const_uint(i as u64),
+ const_float(f) => const_uint(f as u64)
}
}
- ty::ty_int(_) | ty::ty_bool {
+ ty::ty_int(_) | ty::ty_bool => {
alt check base {
- const_uint(u) { const_int(u as i64) }
- const_int(_) { base }
- const_float(f) { const_int(f as i64) }
+ const_uint(u) => const_int(u as i64),
+ const_int(_) => base,
+ const_float(f) => const_int(f as i64)
}
}
}
}
- expr_lit(lit) { lit_to_const(lit) }
+ expr_lit(lit) => lit_to_const(lit),
// If we have a vstore, just keep going; it has to be a string
- expr_vstore(e, _) { eval_const_expr(tcx, e) }
+ expr_vstore(e, _) => eval_const_expr(tcx, e)
}
}
fn lit_to_const(lit: @lit) -> const_val {
alt lit.node {
- lit_str(s) { const_str(*s) }
- lit_int(n, _) { const_int(n) }
- lit_uint(n, _) { const_uint(n) }
- lit_int_unsuffixed(n) { const_int(n) }
- lit_float(n, _) { const_float(option::get(float::from_str(*n)) as f64) }
- lit_nil { const_int(0i64) }
- lit_bool(b) { const_int(b as i64) }
+ lit_str(s) => const_str(*s),
+ lit_int(n, _) => const_int(n),
+ lit_uint(n, _) => const_uint(n),
+ lit_int_unsuffixed(n) => const_int(n),
+ lit_float(n, _) => const_float(option::get(float::from_str(*n)) as f64),
+ lit_nil => const_int(0i64),
+ lit_bool(b) => const_int(b as i64)
}
}
fn compare_const_vals(a: const_val, b: const_val) -> int {
alt (a, b) {
- (const_int(a), const_int(b)) {
+ (const_int(a), const_int(b)) => {
if a == b {
0
} else if a < b {
1
}
}
- (const_uint(a), const_uint(b)) {
+ (const_uint(a), const_uint(b)) => {
if a == b {
0
} else if a < b {
1
}
}
- (const_float(a), const_float(b)) {
+ (const_float(a), const_float(b)) => {
if a == b {
0
} else if a < b {
1
}
}
- (const_str(a), const_str(b)) {
+ (const_str(a), const_str(b)) => {
if a == b {
0
} else if a < b {
1
}
}
- _ {
- fail ~"compare_const_vals: ill-typed comparison";
- }
+ _ => fail ~"compare_const_vals: ill-typed comparison"
}
}
let walk_expr = fn@(expr: @ast::expr, &&depth: int, v: visit::vt<int>) {
alt expr.node {
- ast::expr_fn(proto, decl, _, _) {
+ ast::expr_fn(proto, decl, _, _) => {
if proto != ast::proto_bare {
visit::visit_expr(expr, depth + 1, v);
}
}
- ast::expr_fn_block(_, _, _) {
+ ast::expr_fn_block(_, _, _) => {
visit::visit_expr(expr, depth + 1, v);
}
- ast::expr_path(path) {
+ ast::expr_path(path) => {
let mut i = 0;
alt def_map.find(expr.id) {
- none { fail (~"Not found: " + path_to_str(path)) }
- some(df) {
+ none => fail (~"Not found: " + path_to_str(path)),
+ some(df) => {
let mut def = df;
while i < depth {
alt copy def {
- ast::def_upvar(_, inner, _) { def = *inner; }
- _ { break; }
+ ast::def_upvar(_, inner, _) => { def = *inner; }
+ _ => break
}
i += 1;
}
}
}
}
- _ { visit::visit_expr(expr, depth, v); }
+ _ => visit::visit_expr(expr, depth, v)
}
};
fn get_freevars(tcx: ty::ctxt, fid: ast::node_id) -> freevar_info {
alt tcx.freevars.find(fid) {
- none { fail ~"get_freevars: " + int::str(fid) + ~" has no freevars"; }
- some(d) { return d; }
+ none => fail ~"get_freevars: " + int::str(fid) + ~" has no freevars",
+ some(d) => return d
}
}
fn has_freevars(tcx: ty::ctxt, fid: ast::node_id) -> bool {
let fty = ty::node_id_to_type(cx.tcx, id);
alt ty::ty_fn_proto(fty) {
- proto_uniq { b(check_for_uniq) }
- proto_box { b(check_for_box) }
- proto_bare { b(check_for_bare) }
- proto_block { b(check_for_block) }
+ proto_uniq => b(check_for_uniq),
+ proto_box => b(check_for_box),
+ proto_bare => b(check_for_bare),
+ proto_block => b(check_for_block)
}
}
// variables. This list is used below to avoid checking and reporting
// on a given variable twice.
let cap_clause = alt fk {
- visit::fk_anon(_, cc) | visit::fk_fn_block(cc) { cc }
+ visit::fk_anon(_, cc) | visit::fk_fn_block(cc) => cc,
visit::fk_item_fn(*) | visit::fk_method(*) |
- visit::fk_ctor(*) | visit::fk_dtor(*) { @~[] }
+ visit::fk_ctor(*) | visit::fk_dtor(*) => @~[]
};
let captured_vars = do (*cap_clause).map |cap_item| {
let cap_def = cx.tcx.def_map.get(cap_item.id);
// a move and not a copy
let is_move = {
alt check cx.last_use_map.find(fn_id) {
- some(vars) {(*vars).contains(id)}
- none {false}
+ some(vars) => (*vars).contains(id),
+ none => false
}
};
fn check_block(b: blk, cx: ctx, v: visit::vt<ctx>) {
alt b.node.expr {
- some(ex) { maybe_copy(cx, ex); }
- _ {}
+ some(ex) => maybe_copy(cx, ex),
+ _ => ()
}
visit::visit_block(b, cx, v);
}
alt e.node {
expr_assign(_, ex) |
expr_unary(box(_), ex) | expr_unary(uniq(_), ex) |
- expr_ret(some(ex)) {
+ expr_ret(some(ex)) => {
maybe_copy(cx, ex);
}
- expr_cast(source, _) {
+ expr_cast(source, _) => {
maybe_copy(cx, source);
check_cast_for_escaping_regions(cx, source, e);
}
- expr_copy(expr) { check_copy_ex(cx, expr, false); }
+ expr_copy(expr) => check_copy_ex(cx, expr, false),
// Vector add copies, but not "implicitly"
- expr_assign_op(_, _, ex) { check_copy_ex(cx, ex, false) }
- expr_binary(add, ls, rs) {
+ expr_assign_op(_, _, ex) => check_copy_ex(cx, ex, false),
+ expr_binary(add, ls, rs) => {
check_copy_ex(cx, ls, false);
check_copy_ex(cx, rs, false);
}
- expr_rec(fields, def) {
+ expr_rec(fields, def) => {
for fields.each |field| { maybe_copy(cx, field.node.expr); }
alt def {
- some(ex) {
+ some(ex) => {
// All noncopyable fields must be overridden
let t = ty::expr_ty(cx.tcx, ex);
let ty_fields = alt ty::get(t).struct {
- ty::ty_rec(f) { f }
- _ { cx.tcx.sess.span_bug(ex.span, ~"bad expr type in record"); }
+ ty::ty_rec(f) => f,
+ _ => cx.tcx.sess.span_bug(ex.span, ~"bad expr type in record")
};
for ty_fields.each |tf| {
if !vec::any(fields, |f| f.node.ident == tf.ident ) &&
}
}
}
- _ {}
+ _ => {}
}
}
- expr_tup(exprs) | expr_vec(exprs, _) {
+ expr_tup(exprs) | expr_vec(exprs, _) => {
for exprs.each |expr| { maybe_copy(cx, expr); }
}
- expr_call(f, args, _) {
+ expr_call(f, args, _) => {
let mut i = 0u;
for ty::ty_fn_args(ty::expr_ty(cx.tcx, f)).each |arg_t| {
alt ty::arg_mode(cx.tcx, arg_t) {
- by_copy { maybe_copy(cx, args[i]); }
- by_ref | by_val | by_mutbl_ref | by_move { }
+ by_copy => maybe_copy(cx, args[i]),
+ by_ref | by_val | by_mutbl_ref | by_move => ()
}
i += 1u;
}
}
- expr_path(_) | expr_field(_, _, _) {
+ expr_path(_) | expr_field(_, _, _) => {
do option::iter(cx.tcx.node_type_substs.find(e.id)) |ts| {
let bounds = alt check e.node {
- expr_path(_) {
+ expr_path(_) => {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(e.id));
ty::lookup_item_type(cx.tcx, did).bounds
}
- expr_field(base, _, _) {
+ expr_field(base, _, _) => {
alt cx.method_map.get(e.id).origin {
- typeck::method_static(did) {
+ typeck::method_static(did) => {
// n.b.: When we encode class/impl methods, the bounds
// that we encode include both the class/impl bounds
// and then the method bounds themselves...
}
typeck::method_param({trait_id:trt_id,
method_num:n_mth, _}) |
- typeck::method_trait(trt_id, n_mth) {
+ typeck::method_trait(trt_id, n_mth) => {
// ...trait methods bounds, in contrast, include only the
// method bounds, so we must preprend the tps from the
// trait itself. This ought to be harmonized.
}
}
}
- _ { }
+ _ => { }
}
visit::visit_expr(e, cx, v);
}
fn check_stmt(stmt: @stmt, cx: ctx, v: visit::vt<ctx>) {
alt stmt.node {
- stmt_decl(@{node: decl_local(locals), _}, _) {
+ stmt_decl(@{node: decl_local(locals), _}, _) => {
for locals.each |local| {
alt local.node.init {
- some({op: init_assign, expr}) { maybe_copy(cx, expr); }
- _ {}
+ some({op: init_assign, expr}) => maybe_copy(cx, expr),
+ _ => {}
}
}
}
- _ {}
+ _ => {}
}
visit::visit_stmt(stmt, cx, v);
}
fn check_ty(aty: @ty, cx: ctx, v: visit::vt<ctx>) {
alt aty.node {
- ty_path(_, id) {
+ ty_path(_, id) => {
do option::iter(cx.tcx.node_type_substs.find(id)) |ts| {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(id));
let bounds = ty::lookup_item_type(cx.tcx, did).bounds;
}
}
}
- _ {}
+ _ => {}
}
visit::visit_ty(aty, cx, v);
}
fn is_nullary_variant(cx: ctx, ex: @expr) -> bool {
alt ex.node {
- expr_path(_) {
+ expr_path(_) => {
alt cx.tcx.def_map.get(ex.id) {
- def_variant(edid, vdid) {
+ def_variant(edid, vdid) => {
vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u
}
- _ { false }
+ _ => false
}
}
- _ { false }
+ _ => false
}
}
let msg = ~"mutable variables cannot be implicitly captured; \
use a capture clause";
alt def {
- def_local(_, is_mutbl) {
+ def_local(_, is_mutbl) => {
if is_mutbl {
cx.tcx.sess.span_err(sp, msg);
}
}
- def_arg(_, mode) {
+ def_arg(_, mode) => {
alt ty::resolved_mode(cx.tcx, mode) {
- by_ref | by_val | by_move | by_copy { /* ok */ }
- by_mutbl_ref {
+ by_ref | by_val | by_move | by_copy => { /* ok */ }
+ by_mutbl_ref => {
cx.tcx.sess.span_err(sp, msg);
}
}
}
- def_upvar(_, def1, _) {
+ def_upvar(_, def1, _) => {
check_imm_free_var(cx, *def1, sp);
}
- def_binding(*) | def_self(*) { /*ok*/ }
- _ {
+ def_binding(*) | def_self(*) => { /*ok*/ }
+ _ => {
cx.tcx.sess.span_bug(
sp,
fmt!{"unknown def for free variable: %?", def});
fn check_owned(tcx: ty::ctxt, ty: ty::t, sp: span) -> bool {
if !ty::kind_is_owned(ty::type_kind(tcx, ty)) {
alt ty::get(ty).struct {
- ty::ty_param(*) {
+ ty::ty_param(*) => {
tcx.sess.span_err(sp, ~"value may contain borrowed \
pointers; use `owned` bound");
}
- _ {
+ _ => {
tcx.sess.span_err(sp, ~"value may contain borrowed \
pointers");
}
}
}
}
- meta_word(*) | meta_list(*) {
+ meta_word(*) | meta_list(*) => {
// Skip.
}
}
dl_def(def_ty(did)) => {
def_id = did;
}
- dl_def(_) | dl_impl(_) | dl_field {
+ dl_def(_) | dl_impl(_) | dl_field => {
// Skip this.
again;
}
// type of thing.
fn int_to_lint(i: int) -> lint {
alt check i {
- 0 { ctypes }
- 1 { unused_imports }
- 2 { while_true }
- 3 { path_statement }
- 4 { implicit_copies }
- 5 { unrecognized_lint }
- 6 { non_implicitly_copyable_typarams }
- 7 { vecs_implicitly_copyable }
- 8 { deprecated_mode }
- 9 { non_camel_case_types }
+ 0 => ctypes,
+ 1 => unused_imports,
+ 2 => while_true,
+ 3 => path_statement,
+ 4 => implicit_copies,
+ 5 => unrecognized_lint,
+ 6 => non_implicitly_copyable_typarams,
+ 7 => vecs_implicitly_copyable,
+ 8 => deprecated_mode,
+ 9 => non_camel_case_types
}
}
fn level_to_str(lv: level) -> ~str {
alt lv {
- allow { ~"allow" }
- warn { ~"warn" }
- deny { ~"deny" }
- forbid { ~"forbid" }
+ allow => ~"allow",
+ warn => ~"warn",
+ deny => ~"deny",
+ forbid => ~"forbid"
}
}
fn get_lint_level(modes: lint_modes, lint: lint) -> level {
alt modes.find(lint as uint) {
- some(c) { c }
- none { allow }
+ some(c) => c,
+ none => allow
}
}
_expr_id: ast::node_id,
item_id: ast::node_id) -> level {
alt settings.settings_map.find(item_id) {
- some(modes) { get_lint_level(modes, lint_mode) }
- none { get_lint_level(settings.default_settings, lint_mode) }
+ some(modes) => get_lint_level(modes, lint_mode),
+ none => get_lint_level(settings.default_settings, lint_mode)
}
}
level_name));
for metas.each |meta| {
alt meta.node {
- ast::meta_list(_, metas) {
+ ast::meta_list(_, metas) => {
for metas.each |meta| {
alt meta.node {
- ast::meta_word(lintname) {
+ ast::meta_word(lintname) => {
vec::push(triples, (meta, level, lintname));
}
- _ {
+ _ => {
self.sess.span_err(
meta.span,
~"malformed lint attribute");
}
}
}
- _ {
+ _ => {
self.sess.span_err(meta.span,
~"malformed lint attribute");
}
for triples.each |pair| {
let (meta, level, lintname) = pair;
alt self.dict.find(*lintname) {
- none {
+ none => {
self.span_lint(
new_ctxt.get_level(unrecognized_lint),
meta.span,
fmt!{"unknown `%s` attribute: `%s`",
level_to_str(level), *lintname});
}
- some(lint) {
+ some(lint) => {
if new_ctxt.get_level(lint.lint) == forbid &&
level != forbid {
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
visit_expr: fn@(e: @ast::expr) {
alt e.node {
- ast::expr_while(cond, _) {
+ ast::expr_while(cond, _) => {
alt cond.node {
- ast::expr_lit(@{node: ast::lit_bool(true),_}) {
+ ast::expr_lit(@{node: ast::lit_bool(true),_}) => {
cx.sess.span_lint(
while_true, e.id, it.id,
e.span,
~"denote infinite loops with loop { ... }");
}
- _ {}
+ _ => ()
}
}
- _ {}
+ _ => ()
}
}
with *visit::default_simple_visitor()
let tys = vec::map(decl.inputs, |a| a.ty );
for vec::each(vec::append_one(tys, decl.output)) |ty| {
alt ty.node {
- ast::ty_path(_, id) {
+ ast::ty_path(_, id) => {
alt cx.def_map.get(id) {
- ast::def_prim_ty(ast::ty_int(ast::ty_i)) {
+ ast::def_prim_ty(ast::ty_int(ast::ty_i)) => {
cx.sess.span_lint(
ctypes, id, fn_id,
ty.span,
~"found rust type `int` in foreign module, while \
libc::c_int or libc::c_long should be used");
}
- ast::def_prim_ty(ast::ty_uint(ast::ty_u)) {
+ ast::def_prim_ty(ast::ty_uint(ast::ty_u)) => {
cx.sess.span_lint(
ctypes, id, fn_id,
ty.span,
~"found rust type `uint` in foreign module, while \
libc::c_uint or libc::c_ulong should be used");
}
- _ { }
+ _ => ()
}
}
- _ { }
+ _ => ()
}
}
}
alt it.node {
ast::item_foreign_mod(nmod) if attr::foreign_abi(it.attrs) !=
- either::right(ast::foreign_abi_rust_intrinsic) {
+ either::right(ast::foreign_abi_rust_intrinsic) => {
for nmod.items.each |ni| {
alt ni.node {
- ast::foreign_item_fn(decl, tps) {
+ ast::foreign_item_fn(decl, tps) => {
check_foreign_fn(cx, it.id, decl);
}
}
}
}
- _ {/* nothing to do */ }
+ _ => {/* nothing to do */ }
}
}
ast::stmt_semi(@{id: id,
callee_id: _,
node: ast::expr_path(@path),
- span: _}, _) {
+ span: _}, _) => {
cx.sess.span_lint(
path_statement, id, it.id,
s.span,
~"path statement with no effect");
}
- _ {}
+ _ => ()
}
}
with *visit::default_simple_visitor()
alt it.node {
ast::item_ty(*) | ast::item_class(*) |
- ast::item_trait(*) | ast::item_impl(*) {
+ ast::item_trait(*) | ast::item_impl(*) => {
check_case(cx, it.ident, it.id, it.id, it.span)
}
- ast::item_enum(variants, _) {
+ ast::item_enum(variants, _) => {
check_case(cx, it.ident, it.id, it.id, it.span);
for variants.each |variant| {
check_case(cx, variant.node.name,
variant.node.id, it.id, variant.span);
}
}
- _ { }
+ _ => ()
}
}
let fn_ty = ty::node_id_to_type(tcx, id);
alt check ty::get(fn_ty).struct {
- ty::ty_fn(fn_ty) {
+ ty::ty_fn(fn_ty) => {
let mut counter = 0;
do vec::iter2(fn_ty.inputs, decl.inputs) |arg_ty, arg_ast| {
counter += 1;
fmt!{"argument %d uses an explicit mode", counter});
}
- ast::infer(_) {
+ ast::infer(_) => {
let kind = ty::type_kind(tcx, arg_ty.ty);
if !ty::kind_is_safe_for_default_mode(kind) {
tcx.sess.span_lint(
fn relevant_def(def: def) -> option<relevant_def> {
alt def {
- def_self(_) {some(rdef_self)}
- def_arg(nid, _) | def_local(nid, _) {some(rdef_var(nid))}
- _ {none}
+ def_self(_) => some(rdef_self),
+ def_arg(nid, _) | def_local(nid, _) => some(rdef_var(nid)),
+ _ => none
}
}
self.num_vars += 1u;
alt vk {
- vk_local(node_id, _) | vk_arg(node_id, _, _) {
+ vk_local(node_id, _) | vk_arg(node_id, _, _) => {
self.variable_map.insert(node_id, v);
}
- vk_field(name) {
+ vk_field(name) => {
self.field_map.insert(name, v);
}
- vk_self | vk_implicit_ret {
+ vk_self | vk_implicit_ret => {
}
}
fn variable(node_id: node_id, span: span) -> variable {
alt self.variable_map.find(node_id) {
- some(var) {var}
- none {
+ some(var) => var,
+ none => {
self.tcx.sess.span_bug(
span, fmt!{"No variable registered for id %d", node_id});
}
fn variable_name(var: variable) -> ident {
alt self.var_kinds[*var] {
- vk_local(_, name) | vk_arg(_, name, _) {name}
- vk_field(name) {@(~"self." + *name)}
- vk_self {@~"self"}
- vk_implicit_return {@~"<implicit-ret>"}
+ vk_local(_, name) | vk_arg(_, name, _) => name,
+ vk_field(name) => @(~"self." + *name),
+ vk_self => @~"self",
+ vk_implicit_return => @~"<implicit-ret>"
}
}
fn captures(expr: @expr) -> @~[capture_info] {
alt self.capture_map.find(expr.id) {
- some(caps) {caps}
- none {
+ some(caps) => caps,
+ none => {
self.tcx.sess.span_bug(expr.span, ~"no registered caps");
}
}
alt vk {
vk_arg(id, name, by_move) |
vk_arg(id, name, by_copy) |
- vk_local(id, name) {
+ vk_local(id, name) => {
let v = alt self.last_use_map.find(expr_id) {
- some(v) { v }
- none {
+ some(v) => v,
+ none => {
let v = @dvec();
self.last_use_map.insert(expr_id, v);
v
(*v).push(id);
}
vk_arg(_, _, by_ref) | vk_arg(_, _, by_mutbl_ref) |
- vk_arg(_, _, by_val) | vk_self | vk_field(_) | vk_implicit_ret {
+ vk_arg(_, _, by_val) | vk_self | vk_field(_) | vk_implicit_ret => {
debug!{"--but it is not owned"};
}
}
visit::visit_fn(fk, decl, body, sp, id, fn_maps, v);
alt fk {
- visit::fk_ctor(_, _, _, _, class_did) {
+ visit::fk_ctor(_, _, _, _, class_did) => {
add_class_fields(fn_maps, class_did);
}
- _ {}
+ _ => {}
}
// Special nodes and variables:
fn visit_expr(expr: @expr, &&self: @ir_maps, vt: vt<@ir_maps>) {
alt expr.node {
// live nodes required for uses or definitions of variables:
- expr_path(_) {
+ expr_path(_) => {
let def = self.tcx.def_map.get(expr.id);
debug!{"expr %d: path that leads to %?", expr.id, def};
if relevant_def(def).is_some() {
visit::visit_expr(expr, self, vt);
}
expr_fn(_, _, _, cap_clause) |
- expr_fn_block(_, _, cap_clause) {
+ expr_fn_block(_, _, cap_clause) => {
// Make a live_node for each captured variable, with the span
// being the location that the variable is used. This results
// in better error messages than just pointing at the closure
let mut call_caps = ~[];
for cvs.each |cv| {
alt relevant_def(cv.def) {
- some(rv) {
+ some(rv) => {
let cv_ln = (*self).add_live_node(lnk_freevar(cv.span));
let is_move = alt cv.mode {
- cap_move | cap_drop {true} // var must be dead afterwards
- cap_copy | cap_ref {false} // var can still be used
+ cap_move | cap_drop => true, // var must be dead afterwards
+ cap_copy | cap_ref => false // var can still be used
};
vec::push(call_caps, {ln: cv_ln, is_move: is_move, rv: rv});
}
- none {}
+ none => {}
}
}
(*self).set_captures(expr.id, call_caps);
}
// live nodes required for interesting control flow:
- expr_if(*) | expr_alt(*) | expr_while(*) | expr_loop(*) {
+ expr_if(*) | expr_alt(*) | expr_while(*) | expr_loop(*) => {
(*self).add_live_node_for_node(expr.id, lnk_expr(expr.span));
visit::visit_expr(expr, self, vt);
}
- expr_binary(op, _, _) if ast_util::lazy_binop(op) {
+ expr_binary(op, _, _) if ast_util::lazy_binop(op) => {
(*self).add_live_node_for_node(expr.id, lnk_expr(expr.span));
visit::visit_expr(expr, self, vt);
}
fn live_node(node_id: node_id, span: span) -> live_node {
alt self.ir.live_node_map.find(node_id) {
- some(ln) {ln}
- none {
+ some(ln) => ln,
+ none => {
// This must be a mismatch between the ir_map construction
// above and the propagation code below; the two sets of
// code have to agree about which AST nodes are worth
fn variable_from_rdef(rv: relevant_def, span: span) -> variable {
alt rv {
- rdef_self {self.s.self_var}
- rdef_var(nid) {self.variable(nid, span)}
+ rdef_self => self.s.self_var,
+ rdef_var(nid) => self.variable(nid, span)
}
}
fn variable_from_path(expr: @expr) -> option<variable> {
alt expr.node {
- expr_path(_) {
+ expr_path(_) => {
let def = self.tcx.def_map.get(expr.id);
relevant_def(def).map(
|rdef| self.variable_from_rdef(rdef, expr.span)
)
}
- _ {none}
+ _ => none
}
}
fn variable_from_def_map(node_id: node_id,
span: span) -> option<variable> {
alt self.tcx.def_map.find(node_id) {
- some(def) {
+ some(def) => {
relevant_def(def).map(
|rdef| self.variable_from_rdef(rdef, span)
)
}
- none {
+ none => {
self.tcx.sess.span_bug(
span, ~"Not present in def map")
}
// inputs passed by & mode should be considered live on exit:
for decl.inputs.each |arg| {
alt ty::resolved_mode(self.tcx, arg.mode) {
- by_mutbl_ref | by_ref | by_val {
+ by_mutbl_ref | by_ref | by_val => {
// These are "non-owned" modes, so register a read at
// the end. This will prevent us from moving out of
// such variables but also prevent us from registering
let var = self.variable(arg.id, blk.span);
self.acc(self.s.exit_ln, var, ACC_READ);
}
- by_move | by_copy {
+ by_move | by_copy => {
// These are owned modes. If we don't use the
// variable, nobody will.
}
fn propagate_through_stmt(stmt: @stmt, succ: live_node) -> live_node {
alt stmt.node {
- stmt_decl(decl, _) {
+ stmt_decl(decl, _) => {
return self.propagate_through_decl(decl, succ);
}
- stmt_expr(expr, _) | stmt_semi(expr, _) {
+ stmt_expr(expr, _) | stmt_semi(expr, _) => {
return self.propagate_through_expr(expr, succ);
}
}
fn propagate_through_decl(decl: @decl, succ: live_node) -> live_node {
alt decl.node {
- decl_local(locals) {
+ decl_local(locals) => {
do locals.foldr(succ) |local, succ| {
self.propagate_through_local(local, succ)
}
}
- decl_item(_) {
+ decl_item(_) => {
succ
}
}
alt expr.node {
// Interesting cases with control flow or which gen/kill
- expr_path(_) {
+ expr_path(_) => {
self.access_path(expr, succ, ACC_READ | ACC_USE)
}
- expr_field(e, nm, _) {
+ expr_field(e, nm, _) => {
// If this is a reference to `self.f` inside of a ctor,
// then we treat it as a read of that variable.
// Otherwise, we ignore it and just propagate down to
// process `e`.
alt self.as_self_field(e, nm) {
- some((ln, var)) {
+ some((ln, var)) => {
self.init_from_succ(ln, succ);
self.acc(ln, var, ACC_READ | ACC_USE);
ln
}
- none {
+ none => {
self.propagate_through_expr(e, succ)
}
}
}
- expr_fn(*) | expr_fn_block(*) {
+ expr_fn(*) | expr_fn_block(*) => {
// the construction of a closure itself is not important,
// but we have to consider the closed over variables.
let caps = (*self.ir).captures(expr);
}
}
- expr_if(cond, then, els) {
+ expr_if(cond, then, els) => {
//
// (cond)
// |
self.propagate_through_expr(cond, ln)
}
- expr_while(cond, blk) {
+ expr_while(cond, blk) => {
self.propagate_through_loop(expr, some(cond), blk, succ)
}
- expr_loop(blk) {
+ expr_loop(blk) => {
self.propagate_through_loop(expr, none, blk, succ)
}
- expr_alt(e, arms, _) {
+ expr_alt(e, arms, _) => {
//
// (e)
// |
self.propagate_through_expr(e, ln)
}
- expr_ret(o_e) | expr_fail(o_e) { // ignore succ and subst exit_ln:
+ expr_ret(o_e) | expr_fail(o_e) => {
+ // ignore succ and subst exit_ln:
self.propagate_through_opt_expr(o_e, self.s.exit_ln)
}
- expr_break {
+ expr_break => {
if !self.break_ln.is_valid() {
self.tcx.sess.span_bug(
expr.span, ~"break with invalid break_ln");
self.break_ln
}
- expr_again {
+ expr_again => {
if !self.cont_ln.is_valid() {
self.tcx.sess.span_bug(
expr.span, ~"cont with invalid cont_ln");
self.cont_ln
}
- expr_move(l, r) | expr_assign(l, r) {
+ expr_move(l, r) | expr_assign(l, r) => {
// see comment on lvalues in
// propagate_through_lvalue_components()
let succ = self.write_lvalue(l, succ, ACC_WRITE);
self.propagate_through_expr(r, succ)
}
- expr_swap(l, r) {
+ expr_swap(l, r) => {
// see comment on lvalues in
// propagate_through_lvalue_components()
self.propagate_through_lvalue_components(l, succ)
}
- expr_assign_op(_, l, r) {
+ expr_assign_op(_, l, r) => {
// see comment on lvalues in
// propagate_through_lvalue_components()
let succ = self.write_lvalue(l, succ, ACC_WRITE|ACC_READ);
// Uninteresting cases: just propagate in rev exec order
- expr_vstore(expr, _) {
+ expr_vstore(expr, _) => {
self.propagate_through_expr(expr, succ)
}
- expr_vec(exprs, _) {
+ expr_vec(exprs, _) => {
self.propagate_through_exprs(exprs, succ)
}
self.propagate_through_expr(element, succ)
}
- expr_rec(fields, with_expr) {
+ expr_rec(fields, with_expr) => {
let succ = self.propagate_through_opt_expr(with_expr, succ);
do fields.foldr(succ) |field, succ| {
self.propagate_through_expr(field.node.expr, succ)
}
}
- expr_struct(_, fields) {
+ expr_struct(_, fields) => {
do fields.foldr(succ) |field, succ| {
self.propagate_through_expr(field.node.expr, succ)
}
}
- expr_call(f, args, _) {
+ expr_call(f, args, _) => {
// calling a fn with bot return type means that the fn
// will fail, and hence the successors can be ignored
let t_ret = ty::ty_fn_ret(ty::expr_ty(self.tcx, f));
self.propagate_through_expr(f, succ)
}
- expr_tup(exprs) {
+ expr_tup(exprs) => {
self.propagate_through_exprs(exprs, succ)
}
- expr_binary(op, l, r) if ast_util::lazy_binop(op) {
+ expr_binary(op, l, r) if ast_util::lazy_binop(op) => {
let r_succ = self.propagate_through_expr(r, succ);
let ln = self.live_node(expr.id, expr.span);
expr_log(_, l, r) |
expr_index(l, r) |
- expr_binary(_, l, r) {
+ expr_binary(_, l, r) => {
self.propagate_through_exprs(~[l, r], succ)
}
expr_loop_body(e) |
expr_do_body(e) |
expr_cast(e, _) |
- expr_unary(_, e) {
+ expr_unary(_, e) => {
self.propagate_through_expr(e, succ)
}
- expr_lit(*) {
+ expr_lit(*) => {
succ
}
- expr_block(blk) {
+ expr_block(blk) => {
self.propagate_through_block(blk, succ)
}
- expr_mac(*) {
+ expr_mac(*) => {
self.tcx.sess.span_bug(expr.span, ~"unexpanded macro");
}
}
// just ignore such cases and treat them as reads.
alt expr.node {
- expr_path(_) {
- succ
- }
-
- expr_field(e, nm, _) {
- alt self.as_self_field(e, nm) {
- some(_) {succ}
- none {self.propagate_through_expr(e, succ)}
- }
- }
-
- _ {
- self.propagate_through_expr(expr, succ)
+ expr_path(_) => succ,
+ expr_field(e, nm, _) => alt self.as_self_field(e, nm) {
+ some(_) => succ,
+ none => self.propagate_through_expr(e, succ)
}
+ _ => self.propagate_through_expr(expr, succ)
}
}
succ: live_node,
acc: uint) -> live_node {
alt expr.node {
- expr_path(_) {
- self.access_path(expr, succ, acc)
- }
-
- expr_field(e, nm, _) {
- alt self.as_self_field(e, nm) {
- some((ln, var)) {
+ expr_path(_) => self.access_path(expr, succ, acc),
+ expr_field(e, nm, _) => alt self.as_self_field(e, nm) {
+ some((ln, var)) => {
self.init_from_succ(ln, succ);
self.acc(ln, var, acc);
ln
- }
- none {
- succ
- }
}
+ none => succ
}
// We do not track other lvalues, so just propagate through
// to their subcomponents. Also, it may happen that
// non-lvalues occur here, because those are detected in the
// later pass borrowck.
- _ {succ}
+ _ => succ
}
}
fn access_path(expr: @expr, succ: live_node, acc: uint) -> live_node {
let def = self.tcx.def_map.get(expr.id);
alt relevant_def(def) {
- some(rdef_self) {
+ some(rdef_self) => {
// Accessing `self` is like accessing every field of
// the current object. This allows something like
// `self = ...;` (it will be considered a write to
}
ln
}
- some(rdef_var(nid)) {
+ some(rdef_var(nid)) => {
let ln = self.live_node(expr.id, expr.span);
if acc != 0u {
self.init_from_succ(ln, succ);
}
ln
}
- none {
- succ
- }
+ none => succ
}
}
// variable. we use the live_node id that will be assigned to
// the reference to self but the variable id for `f`.
alt expr.node {
- expr_path(_) {
+ expr_path(_) => {
let def = self.tcx.def_map.get(expr.id);
alt def {
- def_self(_) {
+ def_self(_) => {
// Note: the field_map is empty unless we are in a ctor
return self.ir.field_map.find(fld).map(|var| {
let ln = self.live_node(expr.id, expr.span);
(ln, var)
});
}
- _ { return none; }
+ _ => return none
}
}
- _ { return none; }
+ _ => return none
}
}
fn check_local(local: @local, &&self: @liveness, vt: vt<@liveness>) {
alt local.node.init {
- some({op: op, expr: expr}) {
+ some({op: op, expr: expr}) => {
// Initializer:
alt op {
- init_move {self.check_move_from_expr(expr, vt)}
- init_assign {}
+ init_move => self.check_move_from_expr(expr, vt),
+ init_assign => ()
}
self.warn_about_unused_or_dead_vars_in_pat(local.node.pat);
if !local.node.is_mutbl {
self.check_for_reassignments_in_pat(local.node.pat);
}
}
- none {
+ none => {
// No initializer: the variable might be unused; if not, it
// should not be live at this point.
do (*self).pat_bindings(local.node.pat) |ln, var, sp| {
if !self.warn_about_unused(sp, ln, var) {
alt (*self).live_on_exit(ln, var) {
- none { /* not live: good */ }
- some(lnk) {
+ none => { /* not live: good */ }
+ some(lnk) => {
self.report_illegal_read(
local.span, lnk, var,
possibly_uninitialized_variable);
fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) {
alt expr.node {
- expr_path(_) {
+ expr_path(_) => {
for (*self).variable_from_def_map(expr.id, expr.span).each |var| {
let ln = (*self).live_node(expr.id, expr.span);
self.consider_last_use(expr, ln, var);
visit::visit_expr(expr, self, vt);
}
- expr_fn(_, _, _, cap_clause) | expr_fn_block(_, _, cap_clause) {
+ expr_fn(_, _, _, cap_clause) | expr_fn_block(_, _, cap_clause) => {
let caps = (*self.ir).captures(expr);
for (*caps).each |cap| {
let var = (*self).variable_from_rdef(cap.rv, expr.span);
visit::visit_expr(expr, self, vt);
}
- expr_assign(l, r) {
+ expr_assign(l, r) => {
self.check_lvalue(l, vt);
vt.visit_expr(r, self, vt);
visit::visit_expr(expr, self, vt);
}
- expr_move(l, r) {
+ expr_move(l, r) => {
self.check_lvalue(l, vt);
self.check_move_from_expr(r, vt);
visit::visit_expr(expr, self, vt);
}
- expr_unary_move(r) {
+ expr_unary_move(r) => {
self.check_move_from_expr(r, vt);
visit::visit_expr(expr, self, vt);
}
- expr_assign_op(_, l, _) {
+ expr_assign_op(_, l, _) => {
self.check_lvalue(l, vt);
visit::visit_expr(expr, self, vt);
}
- expr_call(f, args, _) {
+ expr_call(f, args, _) => {
let targs = ty::ty_fn_args(ty::expr_ty(self.tcx, f));
vt.visit_expr(f, self, vt);
do vec::iter2(args, targs) |arg_expr, arg_ty| {
alt ty::resolved_mode(self.tcx, arg_ty.mode) {
- by_val | by_copy | by_ref | by_mutbl_ref{
+ by_val | by_copy | by_ref | by_mutbl_ref => {
vt.visit_expr(arg_expr, self, vt);
}
- by_move {
+ by_move => {
self.check_move_from_expr(arg_expr, vt);
}
}
expr_cast(*) | expr_unary(*) | expr_fail(*) |
expr_ret(*) | expr_break | expr_again | expr_lit(_) |
expr_block(*) | expr_swap(*) | expr_mac(*) | expr_addr_of(*) |
- expr_struct(*) | expr_repeat(*) {
+ expr_struct(*) | expr_repeat(*) => {
visit::visit_expr(expr, self, vt);
}
}
fn check_fields(sp: span, entry_ln: live_node) {
for self.ir.field_map.each |nm, var| {
alt (*self).live_on_entry(entry_ln, var) {
- none { /* ok */ }
- some(lnk_exit) {
+ none => { /* ok */ }
+ some(lnk_exit) => {
self.tcx.sess.span_err(
sp, fmt!{"field `self.%s` is never initialized", *nm});
}
- some(lnk) {
+ some(lnk) => {
self.report_illegal_read(
sp, lnk, var, possibly_uninitialized_field);
}
sp, ~"some control paths may return");
} else {
alt fk {
- visit::fk_ctor(*) {
+ visit::fk_ctor(*) => {
// ctors are written as though they are unit.
}
- _ {
+ _ => {
self.tcx.sess.span_err(
sp, ~"not all control paths return a value");
}
ln.to_str(), var.to_str()};
alt (*self).live_on_exit(ln, var) {
- none { }
- some(lnk) {
- self.report_illegal_move(span, lnk, var);
- }
+ none => {}
+ some(lnk) => self.report_illegal_move(span, lnk, var)
}
}
fn consider_last_use(expr: @expr, ln: live_node, var: variable) {
alt (*self).live_on_exit(ln, var) {
- some(_) {}
- none {
- (*self.ir).add_last_use(expr.id, var);
- }
+ some(_) => {}
+ none => (*self.ir).add_last_use(expr.id, var)
}
}
}
alt expr.node {
- expr_path(_) {
+ expr_path(_) => {
alt (*self).variable_from_path(expr) {
- some(var) {
+ some(var) => {
let ln = (*self).live_node(expr.id, expr.span);
self.check_move_from_var(expr.span, ln, var);
}
- none {}
+ none => {}
}
}
- expr_field(base, _, _) {
+ expr_field(base, _, _) => {
// Moving from x.y is allowed if x is never used later.
// (Note that the borrowck guarantees that anything
// being moved from is uniquely tied to the stack frame)
self.check_move_from_expr(base, vt);
}
- expr_index(base, idx) {
+ expr_index(base, idx) => {
// Moving from x[y] is allowed if x is never used later.
// (Note that the borrowck guarantees that anything
// being moved from is uniquely tied to the stack frame)
vt.visit_expr(idx, self, vt);
}
- _ {
+ _ => {
// For other kinds of lvalues, no checks are required,
// and any embedded expressions are actually rvalues
vt.visit_expr(expr, self, vt);
fn check_lvalue(expr: @expr, vt: vt<@liveness>) {
alt expr.node {
- expr_path(_) {
+ expr_path(_) => {
alt self.tcx.def_map.get(expr.id) {
- def_local(nid, false) {
+ def_local(nid, false) => {
// Assignment to an immutable variable or argument:
// only legal if there is no later assignment.
let ln = (*self).live_node(expr.id, expr.span);
self.check_for_reassignment(ln, var, expr.span);
self.warn_about_dead_assign(expr.span, ln, var);
}
- def {
+ def => {
alt relevant_def(def) {
- some(rdef_var(nid)) {
+ some(rdef_var(nid)) => {
let ln = (*self).live_node(expr.id, expr.span);
let var = (*self).variable(nid, expr.span);
self.warn_about_dead_assign(expr.span, ln, var);
}
- some(rdef_self) {}
- none {}
+ some(rdef_self) => {}
+ none => {}
}
}
}
}
- _ {
+ _ => {
// For other kinds of lvalues, no checks are required,
// and any embedded expressions are actually rvalues
visit::visit_expr(expr, self, vt);
fn check_for_reassignment(ln: live_node, var: variable,
orig_span: span) {
alt (*self).assigned_on_exit(ln, var) {
- some(lnk_expr(span)) {
+ some(lnk_expr(span)) => {
self.tcx.sess.span_err(
span,
~"re-assignment of immutable variable");
orig_span,
~"prior assignment occurs here");
}
- some(lnk) {
+ some(lnk) => {
self.tcx.sess.span_bug(
orig_span,
fmt!{"illegal writer: %?", lnk});
}
- none {}
+ none => {}
}
}
if lnk == lnk_exit {
let vk = self.ir.var_kinds[*var];
alt vk {
- vk_arg(_, name, _) {
+ vk_arg(_, name, _) => {
self.tcx.sess.span_err(
move_span,
fmt!{"illegal move from argument `%s`, which is not \
copy or move mode", *name});
return;
}
- vk_field(name) {
+ vk_field(name) => {
self.tcx.sess.span_err(
move_span,
fmt!{"illegal move from field `%s`", *name});
return;
}
- vk_self {
+ vk_self => {
self.tcx.sess.span_err(
move_span,
~"illegal move from self (cannot move out of a field of \
self)");
return;
}
- vk_local(*) | vk_implicit_ret {
+ vk_local(*) | vk_implicit_ret => {
self.tcx.sess.span_bug(
move_span,
fmt!{"illegal reader (%?) for `%?`",
var: variable,
rk: read_kind) {
let msg = alt rk {
- possibly_uninitialized_variable {~"possibly uninitialized variable"}
- possibly_uninitialized_field {~"possibly uninitialized field"}
- moved_variable {~"moved variable"}
+ possibly_uninitialized_variable => {
+ ~"possibly uninitialized variable"
+ }
+ possibly_uninitialized_field => ~"possibly uninitialized field",
+ moved_variable => ~"moved variable"
};
let name = (*self.ir).variable_name(var);
alt lnk {
- lnk_freevar(span) {
+ lnk_freevar(span) => {
self.tcx.sess.span_err(
span,
fmt!{"capture of %s: `%s`", msg, *name});
}
- lnk_expr(span) {
+ lnk_expr(span) => {
self.tcx.sess.span_err(
span,
fmt!{"use of %s: `%s`", msg, *name});
}
lnk_exit |
- lnk_vdef(_) {
+ lnk_vdef(_) => {
self.tcx.sess.span_bug(
chk_span,
fmt!{"illegal reader: %?", lnk});
for decl.inputs.each |arg| {
let var = (*self).variable(arg.id, arg.ty.span);
alt ty::resolved_mode(self.tcx, arg.mode) {
- by_mutbl_ref {
+ by_mutbl_ref => {
// for mutable reference arguments, something like
// x = 1;
// is not worth warning about, as it has visible
// side effects outside the fn.
alt (*self).assigned_on_entry(entry_ln, var) {
- some(_) { /*ok*/ }
- none {
+ some(_) => { /*ok*/ }
+ none => {
// but if it is not written, it ought to be used
self.warn_about_unused(sp, entry_ln, var);
}
}
}
- by_val | by_ref | by_move | by_copy {
+ by_val | by_ref | by_move | by_copy => {
self.warn_about_unused(sp, entry_ln, var);
}
}
fn pat_is_variant(dm: resolve3::DefMap, pat: @pat) -> bool {
alt pat.node {
- pat_enum(_, _) { true }
- pat_ident(_, _, none) {
- alt dm.find(pat.id) {
- some(def_variant(_, _)) { true }
- _ { false }
- }
+ pat_enum(_, _) => true,
+ pat_ident(_, _, none) => alt dm.find(pat.id) {
+ some(def_variant(_, _)) => true,
+ _ => false
}
- _ { false }
+ _ => false
}
}
it: fn(node_id, span, @path)) {
do walk_pat(pat) |p| {
alt p.node {
- pat_ident(_, pth, _) if !pat_is_variant(dm, p) {
+ pat_ident(_, pth, _) if !pat_is_variant(dm, p) => {
it(p.id, p.span, pth);
}
- _ {}
+ _ => {}
}
}
}
let mut subscope = subscope;
while superscope != subscope {
alt region_map.find(subscope) {
- none { return false; }
- some(scope) { subscope = scope; }
+ none => return false,
+ some(scope) => subscope = scope
}
}
return true;
let mut scope = scope;
loop {
alt region_map.find(scope) {
- none { return result; }
- some(superscope) {
+ none => return result,
+ some(superscope) => {
vec::push(result, superscope);
scope = superscope;
}
/// Extracts that current parent from cx, failing if there is none.
fn parent_id(cx: ctxt, span: span) -> ast::node_id {
alt cx.parent {
- none {
+ none => {
cx.sess.span_bug(span, ~"crate should not be parent here");
}
- some(parent_id) {
+ some(parent_id) => {
parent_id
}
}
/// Records the current parent (if any) as the parent of `child_id`.
fn record_parent(cx: ctxt, child_id: ast::node_id) {
alt cx.parent {
- none { /* no-op */ }
- some(parent_id) {
+ none => { /* no-op */ }
+ some(parent_id) => {
debug!{"parent of node %d is node %d", child_id, parent_id};
cx.region_map.insert(child_id, parent_id);
}
fn resolve_pat(pat: @ast::pat, cx: ctxt, visitor: visit::vt<ctxt>) {
alt pat.node {
- ast::pat_ident(_, path, _) {
+ ast::pat_ident(_, path, _) => {
let defn_opt = cx.def_map.find(pat.id);
alt defn_opt {
- some(ast::def_variant(_,_)) {
+ some(ast::def_variant(_,_)) => {
/* Nothing to do; this names a variant. */
}
- _ {
+ _ => {
/* This names a local. Bind it to the containing scope. */
record_parent(cx, pat.id);
}
}
}
- _ { /* no-op */ }
+ _ => { /* no-op */ }
}
visit::visit_pat(pat, cx, visitor);
let fn_cx = alt fk {
visit::fk_item_fn(*) | visit::fk_method(*) |
- visit::fk_ctor(*) | visit::fk_dtor(*) {
+ visit::fk_ctor(*) | visit::fk_dtor(*) => {
// Top-level functions are a root scope.
{parent: some(id) with cx}
}
- visit::fk_anon(*) | visit::fk_fn_block(*) {
+ visit::fk_anon(*) | visit::fk_fn_block(*) => {
// Closures continue with the inherited scope.
cx
}
// that flag to false when we enter a method.
fn region_is_relevant(r: @ast::region) -> bool {
alt r.node {
- ast::re_anon {self.anon_implies_rp}
- ast::re_named(@~"self") {true}
- ast::re_named(_) {false}
+ ast::re_anon => self.anon_implies_rp,
+ ast::re_named(@~"self") => true,
+ ast::re_named(_) => false
}
}
// then check whether it is region-parameterized and consider
// that as a direct dependency.
alt ty.node {
- ast::ty_path(_, id) {
+ ast::ty_path(_, id) => {
alt cx.def_map.get(id) {
- ast::def_ty(did) | ast::def_class(did, _) {
+ ast::def_ty(did) | ast::def_class(did, _) => {
if did.crate == ast::local_crate {
cx.add_dep(did.node, cx.item_id);
} else {
}
}
}
- _ {}
+ _ => {}
}
}
- _ {}
+ _ => {}
}
alt ty.node {
let id = cx.worklist.pop();
debug!{"popped %d from worklist", id};
alt cx.dep_map.find(id) {
- none {}
- some(vec) {
+ none => {}
+ some(vec) => {
for vec.each |to_id| {
cx.add_rp(to_id);
}
fn intern(string: @~str) -> Atom {
alt self.atoms.find(string) {
- none { /* fall through */ }
- some(atom) { return atom; }
+ none => { /* fall through */ }
+ some(atom) => return atom
}
let atom = Atom(self.atom_count);
fn target_for_namespace(namespace: Namespace) -> option<Target> {
alt namespace {
- ModuleNS { return copy self.module_target; }
- TypeNS { return copy self.type_target; }
- ValueNS { return copy self.value_target; }
+ ModuleNS => return copy self.module_target,
+ TypeNS => return copy self.type_target,
+ ValueNS => return copy self.value_target,
- ImplNS {
+ ImplNS => {
if (*self.impl_target).len() > 0u {
return some(copy *(*self.impl_target).get_elt(0u));
}
pure fn is_none<T>(x: option<T>) -> bool {
alt x {
- none { return true; }
- some(_) { return false; }
+ none => return true,
+ some(_) => return false
}
}
/// Returns the module node if applicable.
fn get_module_if_available() -> option<@Module> {
alt self.module_def {
- NoModuleDef { return none; }
- ModuleDef(module_) { return some(module_); }
+ NoModuleDef => return none,
+ ModuleDef(module_) => return some(module_)
}
}
*/
fn get_module() -> @Module {
alt self.module_def {
- NoModuleDef {
+ NoModuleDef => {
fail
~"get_module called on a node with no module definition!";
}
- ModuleDef(module_) {
+ ModuleDef(module_) => {
return module_;
}
}
fn defined_in_namespace(namespace: Namespace) -> bool {
alt namespace {
- ModuleNS { return self.module_def != NoModuleDef; }
- TypeNS { return self.type_def != none; }
- ValueNS { return self.value_def != none; }
- ImplNS { return self.impl_defs.len() >= 1u; }
+ ModuleNS => return self.module_def != NoModuleDef,
+ TypeNS => return self.type_def != none,
+ ValueNS => return self.value_def != none,
+ ImplNS => return self.impl_defs.len() >= 1u
}
}
fn def_for_namespace(namespace: Namespace) -> option<def> {
alt namespace {
- TypeNS {
- return self.type_def;
+ TypeNS => return self.type_def,
+ ValueNS => return self.value_def,
+ ModuleNS => alt self.module_def {
+ NoModuleDef => return none,
+ ModuleDef(module_) => alt module_.def_id {
+ none => return none,
+ some(def_id) => return some(def_mod(def_id))
}
- ValueNS {
- return self.value_def;
- }
- ModuleNS {
- alt self.module_def {
- NoModuleDef {
- return none;
- }
- ModuleDef(module_) {
- alt module_.def_id {
- none {
- return none;
- }
- some(def_id) {
- return some(def_mod(def_id));
- }
- }
- }
- }
- }
- ImplNS {
- // Danger: Be careful what you use this for! def_ty is not
- // necessarily the right def.
+ }
+ ImplNS => {
+ // Danger: Be careful what you use this for! def_ty is not
+ // necessarily the right def.
- if self.impl_defs.len() == 0u {
- return none;
- }
- return some(def_ty(self.impl_defs[0].did));
+ if self.impl_defs.len() == 0u {
+ return none;
}
+ return some(def_ty(self.impl_defs[0].did));
+ }
}
}
}
fn get_module_from_parent(reduced_graph_parent: ReducedGraphParent)
-> @Module {
alt reduced_graph_parent {
- ModuleReducedGraphParent(module_) {
+ ModuleReducedGraphParent(module_) => {
return module_;
}
}
let mut module_;
alt reduced_graph_parent {
- ModuleReducedGraphParent(parent_module) {
+ ModuleReducedGraphParent(parent_module) => {
module_ = parent_module;
}
}
// Add or reuse the child.
let new_parent = ModuleReducedGraphParent(module_);
alt module_.children.find(name) {
- none {
+ none => {
let child = @NameBindings();
module_.children.insert(name, child);
return (child, new_parent);
}
- some(child) {
+ some(child) => {
return (child, new_parent);
}
}
// Check each statement.
for block.node.stmts.each |statement| {
alt statement.node {
- stmt_decl(declaration, _) {
+ stmt_decl(declaration, _) => {
alt declaration.node {
- decl_item(_) {
+ decl_item(_) => {
return true;
}
- _ {
+ _ => {
// Keep searching.
}
}
}
- _ {
+ _ => {
// Keep searching.
}
}
fn get_parent_link(parent: ReducedGraphParent, name: Atom) -> ParentLink {
alt parent {
- ModuleReducedGraphParent(module_) {
+ ModuleReducedGraphParent(module_) => {
return ModuleParentLink(module_, name);
}
}
let (name_bindings, new_parent) = self.add_child(atom, parent);
alt item.node {
- item_mod(module_) {
+ item_mod(module_) => {
let parent_link = self.get_parent_link(new_parent, atom);
let def_id = { crate: 0, node: item.id };
(*name_bindings).define_module(parent_link, some(def_id));
visit_mod(module_, item.span, item.id, new_parent, visitor);
}
- item_foreign_mod(foreign_module) {
+ item_foreign_mod(foreign_module) => {
let parent_link = self.get_parent_link(new_parent, atom);
let def_id = { crate: 0, node: item.id };
(*name_bindings).define_module(parent_link, some(def_id));
}
// These items live in the value namespace.
- item_const(*) {
+ item_const(*) => {
(*name_bindings).define_value(def_const(local_def(item.id)));
}
- item_fn(decl, _, _) {
+ item_fn(decl, _, _) => {
let def = def_fn(local_def(item.id), decl.purity);
(*name_bindings).define_value(def);
visit_item(item, new_parent, visitor);
}
// These items live in the type namespace.
- item_ty(*) {
+ item_ty(*) => {
(*name_bindings).define_type(def_ty(local_def(item.id)));
}
// These items live in both the type and value namespaces.
- item_enum(variants, _) {
+ item_enum(variants, _) => {
(*name_bindings).define_type(def_ty(local_def(item.id)));
for variants.each |variant| {
visitor);
}
}
- item_class(_, _, class_members, optional_ctor, _) {
+ item_class(_, _, class_members, optional_ctor, _) => {
(*name_bindings).define_type(def_ty(local_def(item.id)));
alt optional_ctor {
let mut method_infos = ~[];
for class_members.each |class_member| {
alt class_member.node {
- class_method(method) {
+ class_method(method) => {
// XXX: Combine with impl method code below.
method_infos += ~[
@{
}
];
}
- instance_var(*) {
+ instance_var(*) => {
// Don't need to do anything with this.
}
}
visit_item(item, new_parent, visitor);
}
- item_impl(_, _, _, methods) {
+ item_impl(_, _, _, methods) => {
// Create the set of implementation information that the
// implementation scopes (ImplScopes) need and write it into
// the implementation definition list for this set of name
visit_item(item, new_parent, visitor);
}
- item_trait(_, _, methods) {
+ item_trait(_, _, methods) => {
// Add the names of all the methods to the trait info.
let method_names = @atom_hashmap();
for methods.each |method| {
let atom;
alt method {
- required(required_method) {
+ required(required_method) => {
atom = (*self.atom_table).intern
(required_method.ident);
}
- provided(provided_method) {
+ provided(provided_method) => {
atom = (*self.atom_table).intern
(provided_method.ident);
}
visit_item(item, new_parent, visitor);
}
- item_mac(*) {
+ item_mac(*) => {
fail ~"item macros unimplemented"
}
}
parent: ReducedGraphParent,
&&_visitor: vt<ReducedGraphParent>) {
alt view_item.node {
- view_item_import(view_paths) {
+ view_item_import(view_paths) => {
for view_paths.each |view_path| {
// Extract and intern the module part of the path. For
// globs and lists, the path is found directly in the AST;
let module_path = @dvec();
alt view_path.node {
- view_path_simple(_, full_path, _) {
+ view_path_simple(_, full_path, _) => {
let path_len = full_path.idents.len();
assert path_len != 0u;
}
view_path_glob(module_ident_path, _) |
- view_path_list(module_ident_path, _, _) {
+ view_path_list(module_ident_path, _, _) => {
for module_ident_path.idents.each |ident| {
let atom = (*self.atom_table).intern(ident);
(*module_path).push(atom);
// Build up the import directives.
let module_ = self.get_module_from_parent(parent);
alt view_path.node {
- view_path_simple(binding, full_path, _) {
+ view_path_simple(binding, full_path, _) => {
let target_atom =
(*self.atom_table).intern(binding);
let source_ident = full_path.idents.last();
subclass,
view_path.span);
}
- view_path_list(_, source_idents, _) {
+ view_path_list(_, source_idents, _) => {
for source_idents.each |source_ident| {
let name = source_ident.node.name;
let atom = (*self.atom_table).intern(name);
view_path.span);
}
}
- view_path_glob(_, _) {
+ view_path_glob(_, _) => {
self.build_import_directive(module_,
module_path,
@GlobImport,
}
}
- view_item_export(view_paths) {
+ view_item_export(view_paths) => {
let module_ = self.get_module_from_parent(parent);
for view_paths.each |view_path| {
alt view_path.node {
- view_path_simple(ident, full_path, ident_id) {
+ view_path_simple(ident, full_path, ident_id) => {
let last_ident = full_path.idents.last();
if last_ident != ident {
self.session.span_err(view_item.span,
module_.exported_names.insert(atom, ident_id);
}
- view_path_glob(*) {
+ view_path_glob(*) => {
self.session.span_err(view_item.span,
~"export globs are \
unsupported");
}
- view_path_list(path, path_list_idents, _) {
+ view_path_list(path, path_list_idents, _) => {
if path.idents.len() == 1u &&
path_list_idents.len() == 0u {
}
}
- view_item_use(name, _, node_id) {
+ view_item_use(name, _, node_id) => {
alt find_use_stmt_cnum(self.session.cstore, node_id) {
- some(crate_id) {
+ some(crate_id) => {
let atom = (*self.atom_table).intern(name);
let (child_name_bindings, new_parent) =
self.add_child(atom, parent);
self.build_reduced_graph_for_external_crate
((*child_name_bindings).get_module());
}
- none {
+ none => {
/* Ignore. */
}
}
let (name_bindings, new_parent) = self.add_child(name, parent);
alt foreign_item.node {
- foreign_item_fn(fn_decl, type_parameters) {
+ foreign_item_fn(fn_decl, type_parameters) => {
let def = def_fn(local_def(foreign_item.id), fn_decl.purity);
(*name_bindings).define_value(def);
// Define or reuse the module node.
alt child_name_bindings.module_def {
- NoModuleDef {
+ NoModuleDef => {
debug!{"(building reduced graph for external crate) \
autovivifying %s", ident};
let parent_link = self.get_parent_link(new_parent,
(*child_name_bindings).define_module(parent_link,
none);
}
- ModuleDef(_) { /* Fall through. */ }
+ ModuleDef(_) => { /* Fall through. */ }
}
current_module = (*child_name_bindings).get_module();
ModuleReducedGraphParent(current_module));
alt path_entry.def_like {
- dl_def(def) {
+ dl_def(def) => {
alt def {
- def_mod(def_id) | def_foreign_mod(def_id) {
+ def_mod(def_id) | def_foreign_mod(def_id) => {
alt copy child_name_bindings.module_def {
- NoModuleDef {
+ NoModuleDef => {
debug!{"(building reduced graph for \
external crate) building module \
%s", final_ident};
atom);
alt modules.find(def_id) {
- none {
+ none => {
(*child_name_bindings).
define_module(parent_link,
some(def_id));
(*child_name_bindings).
get_module());
}
- some(existing_module) {
+ some(existing_module) => {
// Create an import resolution to
// avoid creating cycles in the
// module graph.
alt existing_module.parent_link {
NoParentLink |
- BlockParentLink(*) {
+ BlockParentLink(*) => {
fail ~"can't happen";
}
ModuleParentLink
(parent_module,
- atom) {
+ atom) => {
let name_bindings =
parent_module.
}
}
}
- ModuleDef(module_) {
+ ModuleDef(module_) => {
debug!{"(building reduced graph for \
external crate) already created \
module"};
}
}
def_fn(def_id, _) | def_const(def_id) |
- def_variant(_, def_id) {
+ def_variant(_, def_id) => {
debug!{"(building reduced graph for external \
crate) building value %s", final_ident};
(*child_name_bindings).define_value(def);
}
- def_ty(def_id) {
+ def_ty(def_id) => {
debug!{"(building reduced graph for external \
crate) building type %s", final_ident};
alt get_method_names_if_trait(self.session.cstore,
def_id) {
- none {
+ none => {
// Nothing to do.
}
- some(method_names) {
+ some(method_names) => {
let interned_method_names =
@atom_hashmap();
for method_names.each |method_name| {
(*child_name_bindings).define_type(def);
}
- def_class(def_id, has_constructor) {
+ def_class(def_id, has_constructor) => {
debug!{"(building reduced graph for external \
crate) building type %s (value? %d)",
final_ident,
def_self(*) | def_arg(*) | def_local(*) |
def_prim_ty(*) | def_ty_param(*) | def_binding(*) |
def_use(*) | def_upvar(*) | def_region(*) |
- def_typaram_binder(*) {
+ def_typaram_binder(*) => {
fail fmt!{"didn't expect `%?`", def};
}
}
}
- dl_impl(_) {
+ dl_impl(_) => {
// Because of the infelicitous way the metadata is
// written, we can't process this impl now. We'll get it
// later.
debug!{"(building reduced graph for external crate) \
ignoring impl %s", final_ident};
}
- dl_field {
+ dl_field => {
debug!{"(building reduced graph for external crate) \
ignoring field %s", final_ident};
}
for module_.children.each |_name, child_node| {
alt (*child_node).get_module_if_available() {
- none {
+ none => {
// Nothing to do.
}
- some(child_module) {
+ some(child_module) => {
self.
build_reduced_graph_for_impls_in_external_module_subtree
(child_module);
copy module_.def_id};
alt module_.def_id {
- none {
+ none => {
debug!{"(building reduced graph for impls in external \
module) no def ID for `%s`, skipping",
self.module_to_str(module_)};
return;
}
- some(_) {
+ some(_) => {
// Continue.
}
}
// the appropriate flag.
alt *subclass {
- SingleImport(target, _) {
+ SingleImport(target, _) => {
alt module_.import_resolutions.find(target) {
- some(resolution) {
+ some(resolution) => {
resolution.outstanding_references += 1u;
}
- none {
+ none => {
let resolution = @ImportResolution(span);
resolution.outstanding_references = 1u;
module_.import_resolutions.insert(target, resolution);
}
}
}
- GlobImport {
+ GlobImport => {
// Set the glob flag. This tells us that we don't know the
// module's exports ahead of time.
for module_.children.each |_name, child_node| {
alt (*child_node).get_module_if_available() {
- none {
+ none => {
// Nothing to do.
}
- some(child_module) {
+ some(child_module) => {
self.resolve_imports_for_module_subtree(child_module);
}
}
let import_index = module_.resolved_import_count;
let import_directive = module_.imports.get_elt(import_index);
alt self.resolve_import_for_module(module_, import_directive) {
- Failed {
+ Failed => {
// We presumably emitted an error. Continue.
self.session.span_err(import_directive.span,
~"failed to resolve import");
}
- Indeterminate {
+ Indeterminate => {
// Bail out. We'll come around next time.
break;
}
- Success(()) {
+ Success(()) => {
// Good. Continue.
}
}
NoXray,
import_directive.span) {
- Failed {
+ Failed => {
resolution_result = Failed;
}
- Indeterminate {
+ Indeterminate => {
resolution_result = Indeterminate;
}
- Success(containing_module) {
+ Success(containing_module) => {
// We found the module that the target is contained
// within. Attempt to resolve the import within it.
alt *import_directive.subclass {
- SingleImport(target, source) {
+ SingleImport(target, source) => {
resolution_result =
self.resolve_single_import(module_,
containing_module,
target,
source);
}
- GlobImport {
+ GlobImport => {
let span = import_directive.span;
resolution_result =
self.resolve_glob_import(module_,
// Decrement the count of unresolved imports.
alt resolution_result {
- Success(()) {
+ Success(()) => {
assert self.unresolved_imports >= 1u;
self.unresolved_imports -= 1u;
}
- _ {
+ _ => {
// Nothing to do here; just return the error.
}
}
if resolution_result != Indeterminate {
alt *import_directive.subclass {
- GlobImport {
+ GlobImport => {
assert module_.glob_count >= 1u;
module_.glob_count -= 1u;
}
- SingleImport(*) {
+ SingleImport(*) => {
// Ignore.
}
}
// Search for direct children of the containing module.
alt containing_module.children.find(source) {
- none {
+ none => {
// Continue.
}
- some(child_name_bindings) {
+ some(child_name_bindings) => {
if (*child_name_bindings).defined_in_namespace(ModuleNS) {
module_result = BoundResult(containing_module,
child_name_bindings);
alt (module_result, value_result, type_result, impl_result) {
(BoundResult(*), BoundResult(*), BoundResult(*),
- BoundImplResult(*)) {
+ BoundImplResult(*)) => {
// Continue.
}
- _ {
+ _ => {
// If there is an unresolved glob at this point in the
// containing module, bail out. We don't know enough to be
// able to resolve this import.
// module.
alt containing_module.import_resolutions.find(source) {
- none {
+ none => {
// The containing module definitely doesn't have an
// exported import with the name in question. We can
// therefore accurately report that the names are
}
some(import_resolution)
if import_resolution.outstanding_references
- == 0u {
+ == 0u => {
fn get_binding(import_resolution: @ImportResolution,
namespace: Namespace)
alt (*import_resolution).
target_for_namespace(namespace) {
- none {
+ none => {
return UnboundResult;
}
- some(target) {
+ some(target) => {
import_resolution.used = true;
return BoundResult(target.target_module,
target.bindings);
get_import_binding(import_resolution);
}
}
- some(_) {
+ some(_) => {
// The import is unresolved. Bail out.
debug!{"(resolving single import) unresolved import; \
bailing out"};
let import_resolution = module_.import_resolutions.get(target);
alt module_result {
- BoundResult(target_module, name_bindings) {
+ BoundResult(target_module, name_bindings) => {
debug!{"(resolving single import) found module binding"};
import_resolution.module_target =
some(Target(target_module, name_bindings));
}
- UnboundResult {
+ UnboundResult => {
debug!{"(resolving single import) didn't find module \
binding"};
}
- UnknownResult {
+ UnknownResult => {
fail ~"module result should be known at this point";
}
}
alt value_result {
- BoundResult(target_module, name_bindings) {
+ BoundResult(target_module, name_bindings) => {
import_resolution.value_target =
some(Target(target_module, name_bindings));
}
- UnboundResult { /* Continue. */ }
- UnknownResult {
+ UnboundResult => { /* Continue. */ }
+ UnknownResult => {
fail ~"value result should be known at this point";
}
}
alt type_result {
- BoundResult(target_module, name_bindings) {
+ BoundResult(target_module, name_bindings) => {
import_resolution.type_target =
some(Target(target_module, name_bindings));
}
- UnboundResult { /* Continue. */ }
- UnknownResult {
+ UnboundResult => { /* Continue. */ }
+ UnknownResult => {
fail ~"type result should be known at this point";
}
}
alt impl_result {
- BoundImplResult(targets) {
+ BoundImplResult(targets) => {
for (*targets).each |target| {
(*import_resolution.impl_target).push(target);
}
}
- UnboundImplResult { /* Continue. */ }
- UnknownImplResult {
+ UnboundImplResult => { /* Continue. */ }
+ UnknownImplResult => {
fail ~"impl result should be known at this point";
}
}
If this name wasn't found in any of the four namespaces, it's
definitely unresolved
*/
- (none, none, none, v) if v.len() == 0 { return Failed; }
- _ {}
+ (none, none, none, v) if v.len() == 0 => { return Failed; }
+ _ => {}
}
assert import_resolution.outstanding_references >= 1u;
// Here we merge two import resolutions.
alt module_.import_resolutions.find(atom) {
- none {
+ none => {
// Simple: just copy the old import resolution.
let new_import_resolution =
@ImportResolution(target_import_resolution.span);
module_.import_resolutions.insert
(atom, new_import_resolution);
}
- some(dest_import_resolution) {
+ some(dest_import_resolution) => {
// Merge the two import resolutions at a finer-grained
// level.
alt copy target_import_resolution.module_target {
- none {
+ none => {
// Continue.
}
- some(module_target) {
+ some(module_target) => {
dest_import_resolution.module_target =
some(copy module_target);
}
}
alt copy target_import_resolution.value_target {
- none {
+ none => {
// Continue.
}
- some(value_target) {
+ some(value_target) => {
dest_import_resolution.value_target =
some(copy value_target);
}
}
alt copy target_import_resolution.type_target {
- none {
+ none => {
// Continue.
}
- some(type_target) {
+ some(type_target) => {
dest_import_resolution.type_target =
some(copy type_target);
}
let mut dest_import_resolution;
alt module_.import_resolutions.find(atom) {
- none {
+ none => {
// Create a new import resolution from this child.
dest_import_resolution = @ImportResolution(span);
module_.import_resolutions.insert
(atom, dest_import_resolution);
}
- some(existing_import_resolution) {
+ some(existing_import_resolution) => {
dest_import_resolution = existing_import_resolution;
}
}
alt self.resolve_name_in_module(search_module, name, ModuleNS,
xray) {
- Failed {
+ Failed => {
self.session.span_err(span, ~"unresolved name");
return Failed;
}
- Indeterminate {
+ Indeterminate => {
debug!{"(resolving module path for import) module \
resolution is indeterminate: %s",
*(*self.atom_table).atom_to_str(name)};
return Indeterminate;
}
- Success(target) {
+ Success(target) => {
alt target.bindings.module_def {
- NoModuleDef {
+ NoModuleDef => {
// Not a module.
self.session.span_err(span,
fmt!{"not a module: %s",
atom_to_str(name)});
return Failed;
}
- ModuleDef(module_) {
+ ModuleDef(module_) => {
search_module = module_;
}
}
let first_element = (*module_path).get_elt(0u);
let mut search_module;
alt self.resolve_module_in_lexical_scope(module_, first_element) {
- Failed {
+ Failed => {
self.session.span_err(span, ~"unresolved name");
return Failed;
}
- Indeterminate {
+ Indeterminate => {
debug!{"(resolving module path for import) indeterminate; \
bailing"};
return Indeterminate;
}
- Success(resulting_module) {
+ Success(resulting_module) => {
search_module = resulting_module;
}
}
alt module_.children.find(name) {
some(name_bindings)
- if (*name_bindings).defined_in_namespace(namespace) {
+ if (*name_bindings).defined_in_namespace(namespace) => {
return Success(Target(module_, name_bindings));
}
- some(_) | none { /* Not found; continue. */ }
+ some(_) | none => { /* Not found; continue. */ }
}
// Now check for its import directives. We don't have to have resolved
// current scope.
alt module_.import_resolutions.find(name) {
- none {
+ none => {
// Not found; continue.
}
- some(import_resolution) {
+ some(import_resolution) => {
alt (*import_resolution).target_for_namespace(namespace) {
- none {
+ none => {
// Not found; continue.
debug!{"(resolving item in lexical scope) found \
import resolution, but not in namespace %?",
namespace};
}
- some(target) {
+ some(target) => {
import_resolution.used = true;
return Success(copy target);
}
loop {
// Go to the next parent.
alt search_module.parent_link {
- NoParentLink {
+ NoParentLink => {
// No more parents. This module was unresolved.
debug!{"(resolving item in lexical scope) unresolved \
module"};
return Failed;
}
ModuleParentLink(parent_module_node, _) |
- BlockParentLink(parent_module_node, _) {
+ BlockParentLink(parent_module_node, _) => {
search_module = parent_module_node;
}
}
// Resolve the name in the parent module.
alt self.resolve_name_in_module(search_module, name, namespace,
Xray) {
- Failed {
+ Failed => {
// Continue up the search chain.
}
- Indeterminate {
+ Indeterminate => {
// We couldn't see through the higher scope because of an
// unresolved import higher up. Bail.
higher scope; bailing"};
return Indeterminate;
}
- Success(target) {
+ Success(target) => {
// We found the module.
return Success(copy target);
}
-> ResolveResult<@Module> {
alt self.resolve_item_in_lexical_scope(module_, name, ModuleNS) {
- Success(target) {
+ Success(target) => {
alt target.bindings.module_def {
- NoModuleDef {
+ NoModuleDef => {
error!{"!!! (resolving module in lexical scope) module
wasn't actually a module!"};
return Failed;
}
- ModuleDef(module_) {
+ ModuleDef(module_) => {
return Success(module_);
}
}
}
- Indeterminate {
+ Indeterminate => {
debug!{"(resolving module in lexical scope) indeterminate; \
bailing"};
return Indeterminate;
}
- Failed {
+ Failed => {
debug!{"(resolving module in lexical scope) failed to \
resolve"};
return Failed;
// First, check the direct children of the module.
alt module_.children.find(name) {
some(name_bindings)
- if (*name_bindings).defined_in_namespace(namespace) {
+ if (*name_bindings).defined_in_namespace(namespace) => {
debug!{"(resolving name in module) found node as child"};
return Success(Target(module_, name_bindings));
}
- some(_) | none {
+ some(_) | none => {
// Continue.
}
}
// Otherwise, we check the list of resolved imports.
alt module_.import_resolutions.find(name) {
- some(import_resolution) {
+ some(import_resolution) => {
if import_resolution.outstanding_references != 0u {
debug!{"(resolving name in module) import unresolved; \
bailing out"};
}
alt (*import_resolution).target_for_namespace(namespace) {
- none {
+ none => {
debug!{"(resolving name in module) name found, but \
not in namespace %?",
namespace};
}
- some(target) {
+ some(target) => {
debug!{"(resolving name in module) resolved to \
import"};
import_resolution.used = true;
}
}
}
- none {
+ none => {
// Continue.
}
}
let mut target_name;
let mut source_name;
alt *import_directive.subclass {
- SingleImport(target, source) {
+ SingleImport(target, source) => {
target_name = target;
source_name = source;
}
- GlobImport {
+ GlobImport => {
fail ~"found `import *`, which is invalid";
}
}
source_name,
ModuleNS) {
- Failed {
+ Failed => {
debug!{"(resolving one-level renaming import) didn't find \
module result"};
module_result = none;
}
- Indeterminate {
+ Indeterminate => {
debug!{"(resolving one-level renaming import) module result \
is indeterminate; bailing"};
return Indeterminate;
}
- Success(name_bindings) {
+ Success(name_bindings) => {
debug!{"(resolving one-level renaming import) module result \
found"};
module_result = some(copy name_bindings);
source_name,
ValueNS) {
- Failed {
+ Failed => {
debug!{"(resolving one-level renaming import) didn't find \
value result"};
value_result = none;
}
- Indeterminate {
+ Indeterminate => {
debug!{"(resolving one-level renaming import) value result \
is indeterminate; bailing"};
return Indeterminate;
}
- Success(name_bindings) {
+ Success(name_bindings) => {
debug!{"(resolving one-level renaming import) value result \
found"};
value_result = some(copy name_bindings);
source_name,
TypeNS) {
- Failed {
+ Failed => {
debug!{"(resolving one-level renaming import) didn't find \
type result"};
type_result = none;
}
- Indeterminate {
+ Indeterminate => {
debug!{"(resolving one-level renaming import) type result is \
indeterminate; bailing"};
return Indeterminate;
}
- Success(name_bindings) {
+ Success(name_bindings) => {
debug!{"(resolving one-level renaming import) type result \
found"};
type_result = some(copy name_bindings);
source_name,
ImplNS) {
- Failed {
+ Failed => {
debug!{"(resolving one-level renaming import) didn't find \
impl result"};
impl_result = none;
}
- Indeterminate {
+ Indeterminate => {
debug!{"(resolving one-level renaming import) impl result is \
indeterminate; bailing"};
return Indeterminate;
}
- Success(name_bindings) {
+ Success(name_bindings) => {
debug!{"(resolving one-level renaming import) impl result \
found"};
impl_result = some(@copy name_bindings);
// Otherwise, proceed and write in the bindings.
alt module_.import_resolutions.find(target_name) {
- none {
+ none => {
fail ~"(resolving one-level renaming import) reduced graph \
construction or glob importing should have created the \
import resolution name by now";
}
- some(import_resolution) {
+ some(import_resolution) => {
debug!{"(resolving one-level renaming import) writing module \
result %? for `%s` into `%s`",
is_none(module_result),
import_resolution.type_target = type_result;
alt impl_result {
- none {
+ none => {
// Nothing to do.
}
- some(impl_result) {
+ some(impl_result) => {
(*import_resolution.impl_target).push(impl_result);
}
}
// Descend into children and anonymous children.
for module_.children.each |_name, child_node| {
alt (*child_node).get_module_if_available() {
- none {
+ none => {
// Continue.
}
- some(child_module) {
+ some(child_module) => {
self.report_unresolved_imports(child_module);
}
}
// exports for local crates.
alt module_.def_id {
- some(def_id) if def_id.crate == local_crate {
+ some(def_id) if def_id.crate == local_crate => {
// OK. Continue.
}
- none {
+ none => {
// Record exports for the root module.
}
- some(_) {
+ some(_) => {
// Bail out.
debug!{"(recording exports for module subtree) not recording \
exports for `%s`",
for module_.children.each |_atom, child_name_bindings| {
alt (*child_name_bindings).get_module_if_available() {
- none {
+ none => {
// Nothing to do.
}
- some(child_module) {
+ some(child_module) => {
self.record_exports_for_module_subtree(child_module);
}
}
name,
namespace,
Xray) {
- NoNameDefinition {
+ NoNameDefinition => {
// Nothing to do.
}
- ChildNameDefinition(target_def) {
+ ChildNameDefinition(target_def) => {
vec::push(exports, {
reexp: false,
id: def_id_of_def(target_def)
});
}
- ImportNameDefinition(target_def) {
+ ImportNameDefinition(target_def) => {
vec::push(exports, {
reexp: true,
id: def_id_of_def(target_def)
// resolve implementations for external crates.
alt module_.def_id {
- some(def_id) if def_id.crate == local_crate {
+ some(def_id) if def_id.crate == local_crate => {
// OK. Continue.
}
- none {
+ none => {
// Resolve implementation scopes for the root module.
}
- some(_) {
+ some(_) => {
// Bail out.
debug!{"(building impl scopes for module subtree) not \
resolving implementations for `%s`",
for module_.children.each |_atom, child_name_bindings| {
alt (*child_name_bindings).get_module_if_available() {
- none {
+ none => {
// Nothing to do.
}
- some(child_module) {
+ some(child_module) => {
self.build_impl_scopes_for_module_subtree(child_module);
}
}
// Determine the parent's implementation scope.
let mut parent_impl_scopes;
alt module_.parent_link {
- NoParentLink {
+ NoParentLink => {
parent_impl_scopes = @nil;
}
ModuleParentLink(parent_module_node, _) |
- BlockParentLink(parent_module_node, _) {
+ BlockParentLink(parent_module_node, _) => {
parent_impl_scopes = parent_module_node.impl_scopes;
}
}
// Move down in the graph.
alt name {
- none {
+ none => {
// Nothing to do.
}
- some(name) {
+ some(name) => {
alt orig_module.children.find(name) {
- none {
+ none => {
debug!{"!!! (with scope) didn't find `%s` in `%s`",
*(*self.atom_table).atom_to_str(name),
self.module_to_str(orig_module)};
}
- some(name_bindings) {
+ some(name_bindings) => {
alt (*name_bindings).get_module_if_available() {
- none {
+ none => {
debug!{"!!! (with scope) didn't find module \
for `%s` in `%s`",
*(*self.atom_table).atom_to_str(name),
self.module_to_str(orig_module)};
}
- some(module_) {
+ some(module_) => {
self.current_module = module_;
}
}
alt def_like {
dl_def(d @ def_local(*)) | dl_def(d @ def_upvar(*)) |
- dl_def(d @ def_arg(*)) | dl_def(d @ def_binding(*)) {
+ dl_def(d @ def_arg(*)) | dl_def(d @ def_binding(*)) => {
def = d;
is_ty_param = false;
}
- dl_def(d @ def_ty_param(*)) {
+ dl_def(d @ def_ty_param(*)) => {
def = d;
is_ty_param = true;
}
dl_def(d @ def_self(*))
- if allow_capturing_self == DontAllowCapturingSelf {
+ if allow_capturing_self == DontAllowCapturingSelf => {
def = d;
is_ty_param = false;
}
- _ {
+ _ => {
return some(def_like);
}
}
while rib_index < (*ribs).len() {
let rib = (*ribs).get_elt(rib_index);
alt rib.kind {
- NormalRibKind {
+ NormalRibKind => {
// Nothing to do. Continue.
}
- FunctionRibKind(function_id) {
+ FunctionRibKind(function_id) => {
if !is_ty_param {
def = def_upvar(def_id_of_def(def).node,
@def,
function_id);
}
}
- MethodRibKind(item_id, method_id) {
+ MethodRibKind(item_id, method_id) => {
// If the def is a ty param, and came from the parent
// item, it's ok
alt def {
def_ty_param(did, _) if self.def_map.find(copy(did.node))
- == some(def_typaram_binder(item_id)) {
+ == some(def_typaram_binder(item_id)) => {
// ok
}
- _ {
+ _ => {
if !is_ty_param {
// This was an attempt to access an upvar inside a
// named function item. This is not allowed, so we
}
}
}
- OpaqueFunctionRibKind {
+ OpaqueFunctionRibKind => {
if !is_ty_param {
// This was an attempt to access an upvar inside a
// named function item. This is not allowed, so we
i -= 1u;
let rib = (*ribs).get_elt(i);
alt rib.bindings.find(name) {
- some(def_like) {
+ some(def_like) => {
return self.upvarify(ribs, i, def_like, span,
allow_capturing_self);
}
- none {
+ none => {
// Continue.
}
}
alt item.node {
item_enum(_, type_parameters) |
- item_ty(_, type_parameters) {
+ item_ty(_, type_parameters) => {
do self.with_type_parameter_rib
(HasTypeParameters(&type_parameters, item.id, 0u,
NormalRibKind))
}
item_impl(type_parameters, implemented_traits, self_type,
- methods) {
+ methods) => {
self.resolve_implementation(item.id, item.span,
type_parameters,
self_type, methods, visitor);
}
- item_trait(type_parameters, traits, methods) {
+ item_trait(type_parameters, traits, methods) => {
// Create a new rib for the self type.
let self_type_rib = @Rib(NormalRibKind);
(*self.type_ribs).push(self_type_rib);
// XXX: Do we need a node ID here?
alt method {
- required(ty_m) {
+ required(ty_m) => {
do self.with_type_parameter_rib
(HasTypeParameters(&ty_m.tps,
item.id,
self.resolve_type(ty_m.decl.output, visitor);
}
}
- provided(m) {
+ provided(m) => {
self.resolve_method(MethodRibKind(item.id,
Provided(m.id)),
m,
}
item_class(ty_params, traits, class_members,
- optional_constructor, optional_destructor) {
+ optional_constructor, optional_destructor) => {
self.resolve_class(item.id,
@copy ty_params,
visitor);
}
- item_mod(module_) {
+ item_mod(module_) => {
let atom = (*self.atom_table).intern(item.ident);
do self.with_scope(some(atom)) {
self.resolve_module(module_, item.span, item.ident,
}
}
- item_foreign_mod(foreign_module) {
+ item_foreign_mod(foreign_module) => {
let atom = (*self.atom_table).intern(item.ident);
do self.with_scope(some(atom)) {
for foreign_module.items.each |foreign_item| {
alt foreign_item.node {
- foreign_item_fn(_, type_parameters) {
+ foreign_item_fn(_, type_parameters) => {
do self.with_type_parameter_rib
(HasTypeParameters(&type_parameters,
foreign_item.id,
}
}
- item_fn(fn_decl, ty_params, block) {
+ item_fn(fn_decl, ty_params, block) => {
// If this is the main function, we must record it in the
// session.
//
visitor);
}
- item_const(*) {
+ item_const(*) => {
visit_item(item, (), visitor);
}
- item_mac(*) {
+ item_mac(*) => {
fail ~"item macros unimplemented"
}
}
fn with_type_parameter_rib(type_parameters: TypeParameters, f: fn()) {
alt type_parameters {
HasTypeParameters(type_parameters, node_id, initial_index,
- rib_kind) {
+ rib_kind) => {
let function_type_rib = @Rib(rib_kind);
(*self.type_ribs).push(function_type_rib);
}
}
- NoTypeParameters {
+ NoTypeParameters => {
// Nothing to do.
}
}
f();
alt type_parameters {
- HasTypeParameters(type_parameters, _, _, _) {
+ HasTypeParameters(type_parameters, _, _, _) => {
(*self.type_ribs).pop();
}
- NoTypeParameters {
+ NoTypeParameters =>{
// Nothing to do.
}
}
// Check each element of the capture clause.
alt capture_clause {
- NoCaptureClause {
+ NoCaptureClause => {
// Nothing to do.
}
- HasCaptureClause(capture_clause) {
+ HasCaptureClause(capture_clause) => {
// Resolve each captured item.
for (*capture_clause).each |capture_item| {
alt self.resolve_identifier(capture_item.name,
ValueNS,
true,
capture_item.span) {
- none {
+ none => {
self.session.span_err(capture_item.span,
~"unresolved name in \
capture clause");
}
- some(def) {
+ some(def) => {
self.record_def(capture_item.id, def);
}
}
do self.with_type_parameter_rib(type_parameters) {
// Resolve the type parameters.
alt type_parameters {
- NoTypeParameters {
+ NoTypeParameters => {
// Continue.
}
- HasTypeParameters(type_parameters, _, _, _) {
+ HasTypeParameters(type_parameters, _, _, _) => {
self.resolve_type_parameters(*type_parameters, visitor);
}
}
// Add self to the rib, if necessary.
alt self_binding {
- NoSelfBinding {
+ NoSelfBinding => {
// Nothing to do.
}
- HasSelfBinding(self_node_id) {
+ HasSelfBinding(self_node_id) => {
let def_like = dl_def(def_self(self_node_id));
(*function_value_rib).bindings.insert(self.self_atom,
def_like);
// Add each argument to the rib.
alt optional_declaration {
- none {
+ none => {
// Nothing to do.
}
- some(declaration) {
+ some(declaration) => {
for declaration.inputs.each |argument| {
let name = (*self.atom_table).intern(argument.ident);
let def_like = dl_def(def_arg(argument.id,
for type_parameters.each |type_parameter| {
for (*type_parameter.bounds).each |bound| {
alt bound {
- bound_copy | bound_send | bound_const | bound_owned {
+ bound_copy | bound_send | bound_const | bound_owned => {
// Nothing to do.
}
- bound_trait(trait_type) {
+ bound_trait(trait_type) => {
self.resolve_type(trait_type, visitor);
}
}
// Resolve implemented traits.
for traits.each |trt| {
alt self.resolve_path(trt.path, TypeNS, true, visitor) {
- none {
+ none => {
self.session.span_err(trt.path.span,
~"attempt to implement a \
nonexistent trait");
}
- some(def) {
+ some(def) => {
// Write a mapping from the trait ID to the
// definition of the trait into the definition
// map.
// Resolve methods.
for class_members.each |class_member| {
alt class_member.node {
- class_method(method) {
+ class_method(method) => {
self.resolve_method(MethodRibKind(id,
Provided(method.id)),
method,
outer_type_parameter_count,
visitor);
}
- instance_var(_, field_type, _, _, _) {
+ instance_var(_, field_type, _, _, _) => {
self.resolve_type(field_type, visitor);
}
}
// Resolve the destructor, if applicable.
alt optional_destructor {
- none {
+ none => {
// Nothing to do.
}
- some(destructor) {
+ some(destructor) => {
self.resolve_function(NormalRibKind,
none,
NoTypeParameters,
for trait_references.each |trait_reference| {
alt self.resolve_path(trait_reference.path, TypeNS, true,
visitor) {
- none {
+ none => {
self.session.span_err(span,
~"attempt to implement an \
unknown trait");
}
- some(def) {
+ some(def) => {
self.record_def(trait_reference.ref_id, def);
// Record the current trait reference.
// Resolve the initializer, if necessary.
alt local.node.init {
- none {
+ none => {
// Nothing to do.
}
- some(initializer) {
+ some(initializer) => {
self.resolve_expr(initializer.expr, visitor);
}
}
// Move down in the graph, if there's an anonymous module rooted here.
let orig_module = self.current_module;
alt self.current_module.anonymous_children.find(block.node.id) {
- none { /* Nothing to do. */ }
- some(anonymous_module) {
+ none => { /* Nothing to do. */ }
+ some(anonymous_module) => {
debug!{"(resolving block) found anonymous module, moving \
down"};
self.current_module = anonymous_module;
// Like path expressions, the interpretation of path types depends
// on whether the path has multiple elements in it or not.
- ty_path(path, path_id) {
+ ty_path(path, path_id) => {
// This is a path in the type namespace. Walk through scopes
// scopes looking for it.
let mut result_def;
alt self.resolve_path(path, TypeNS, true, visitor) {
- some(def) {
+ some(def) => {
debug!{"(resolving type) resolved `%s` to type",
*path.idents.last()};
result_def = some(def);
}
- none {
+ none => {
result_def = none;
}
}
alt result_def {
- some(_) {
+ some(_) => {
// Continue.
}
- none {
+ none => {
// Check to see whether the name is a primitive type.
if path.idents.len() == 1u {
let name =
.primitive_types
.find(name) {
- some(primitive_type) {
+ some(primitive_type) => {
result_def =
some(def_prim_ty(primitive_type));
}
- none {
+ none => {
// Continue.
}
}
}
alt copy result_def {
- some(def) {
+ some(def) => {
// Write the result into the def map.
debug!{"(resolving type) writing resolution for `%s` \
(id %d)",
path_id};
self.record_def(path_id, def);
}
- none {
+ none => {
self.session.span_err
(ty.span, fmt!{"use of undeclared type name `%s`",
connect(path.idents.map(|x| *x),
}
}
- _ {
+ _ => {
// Just resolve embedded types.
visit_ty(ty, (), visitor);
}
let is_mutable = mutability == Mutable;
let def = alt mode {
- RefutableMode {
+ RefutableMode => {
// For pattern arms, we must use
// `def_binding` definitions.
def_binding(pattern.id, binding_mode)
}
- IrrefutableMode {
+ IrrefutableMode => {
// But for locals, we use `def_local`.
def_local(pattern.id, is_mutable)
}
alt bindings_list {
some(bindings_list)
- if !bindings_list.contains_key(atom) {
+ if !bindings_list.contains_key(atom) => {
let last_rib = (*self.value_ribs).last();
last_rib.bindings.insert(atom,
dl_def(def));
bindings_list.insert(atom, pat_id);
}
- some(b) {
+ some(b) => {
if b.find(atom) == some(pat_id) {
// Then this is a duplicate variable
// in the same disjunct, which is an
}
// Not bound in the same pattern: do nothing
}
- none {
+ none => {
let last_rib = (*self.value_ribs).last();
last_rib.bindings.insert(atom,
dl_def(def));
pat_ident(_, path, _) | pat_enum(path, _) => {
// These two must be enum variants.
alt self.resolve_path(path, ValueNS, false, visitor) {
- some(def @ def_variant(*)) {
+ some(def @ def_variant(*)) => {
self.record_def(pattern.id, def);
}
- some(_) {
+ some(_) => {
self.session.span_err(path.span,
fmt!{"not an enum \
variant: %s",
*path.idents.last()});
}
- none {
+ none => {
self.session.span_err(path.span,
~"unresolved enum variant");
}
name,
ValueNS) {
- Success(target) {
+ Success(target) => {
alt target.bindings.value_def {
- none {
+ none => {
fail ~"resolved name in the value namespace to a set \
of name bindings with no def?!";
}
- some(def @ def_variant(*)) {
+ some(def @ def_variant(*)) => {
return FoundEnumVariant(def);
}
- some(def_const(*)) {
+ some(def_const(*)) => {
return FoundConst;
}
- some(_) {
+ some(_) => {
return EnumVariantOrConstNotFound;
}
}
}
- Indeterminate {
+ Indeterminate => {
fail ~"unexpected indeterminate result";
}
- Failed {
+ Failed => {
return EnumVariantOrConstNotFound;
}
}
alt self.resolve_identifier_in_local_ribs(identifier,
namespace,
span) {
- some(def) {
+ some(def) => {
return some(def);
}
- none {
+ none => {
// Continue.
}
}
// First, search children.
alt containing_module.children.find(name) {
- some(child_name_bindings) {
+ some(child_name_bindings) => {
alt (*child_name_bindings).def_for_namespace(namespace) {
- some(def) {
+ some(def) => {
// Found it. Stop the search here.
return ChildNameDefinition(def);
}
- none {
+ none => {
// Continue.
}
}
}
- none {
+ none => {
// Continue.
}
}
// Next, search import resolutions.
alt containing_module.import_resolutions.find(name) {
- some(import_resolution) {
+ some(import_resolution) => {
alt (*import_resolution).target_for_namespace(namespace) {
- some(target) {
+ some(target) => {
alt (*target.bindings).def_for_namespace(namespace) {
- some(def) {
+ some(def) => {
// Found it.
import_resolution.used = true;
return ImportNameDefinition(def);
}
- none {
+ none => {
// This can happen with external impls, due to
// the imperfect way we read the metadata.
}
}
}
- none {
+ none => {
return NoNameDefinition;
}
}
}
- none {
+ none => {
return NoNameDefinition;
}
}
xray,
path.span) {
- Failed {
+ Failed => {
self.session.span_err(path.span,
fmt!{"use of undeclared module `%s`",
*(*self.atom_table).atoms_to_str
return none;
}
- Indeterminate {
+ Indeterminate => {
fail ~"indeterminate unexpected";
}
- Success(resulting_module) {
+ Success(resulting_module) => {
containing_module = resulting_module;
}
}
name,
namespace,
xray) {
- NoNameDefinition {
+ NoNameDefinition => {
// We failed to resolve the name. Report an error.
self.session.span_err(path.span,
fmt!{"unresolved name: %s::%s",
(name)});
return none;
}
- ChildNameDefinition(def) | ImportNameDefinition(def) {
+ ChildNameDefinition(def) | ImportNameDefinition(def) => {
return some(def);
}
}
xray,
path.span) {
- Failed {
+ Failed => {
self.session.span_err(path.span,
fmt!{"use of undeclared module `::%s`",
*(*self.atom_table).atoms_to_str
return none;
}
- Indeterminate {
+ Indeterminate => {
fail ~"indeterminate unexpected";
}
- Success(resulting_module) {
+ Success(resulting_module) => {
containing_module = resulting_module;
}
}
name,
namespace,
xray) {
- NoNameDefinition {
+ NoNameDefinition => {
// We failed to resolve the name. Report an error.
self.session.span_err(path.span,
fmt!{"unresolved name: %s::%s",
(name)});
return none;
}
- ChildNameDefinition(def) | ImportNameDefinition(def) {
+ ChildNameDefinition(def) | ImportNameDefinition(def) => {
return some(def);
}
}
// Check the local set of ribs.
let mut search_result;
alt namespace {
- ValueNS {
+ ValueNS => {
search_result = self.search_ribs(self.value_ribs, name, span,
DontAllowCapturingSelf);
}
- TypeNS {
+ TypeNS => {
search_result = self.search_ribs(self.type_ribs, name, span,
AllowCapturingSelf);
}
- ModuleNS | ImplNS {
+ ModuleNS | ImplNS => {
fail ~"module or impl namespaces do not have local ribs";
}
}
alt copy search_result {
- some(dl_def(def)) {
+ some(dl_def(def)) => {
debug!{"(resolving path in local ribs) resolved `%s` to \
local: %?",
*(*self.atom_table).atom_to_str(name),
def};
return some(def);
}
- some(dl_field) | some(dl_impl(_)) | none {
+ some(dl_field) | some(dl_impl(_)) | none => {
return none;
}
}
name,
namespace) {
- Success(target) {
+ Success(target) => {
alt (*target.bindings).def_for_namespace(namespace) {
- none {
+ none => {
fail ~"resolved name in a namespace to a set of name \
bindings with no def for that namespace?!";
}
- some(def) {
+ some(def) => {
debug!{"(resolving item path in lexical scope) \
resolved `%s` to item",
*(*self.atom_table).atom_to_str(name)};
}
}
}
- Indeterminate {
+ Indeterminate => {
fail ~"unexpected indeterminate result";
}
- Failed {
+ Failed => {
return none;
}
}
// The interpretation of paths depends on whether the path has
// multiple elements in it or not.
- expr_path(path) {
+ expr_path(path) => {
// This is a local path in the value namespace. Walk through
// scopes looking for it.
alt self.resolve_path(path, ValueNS, true, visitor) {
- some(def) {
+ some(def) => {
// Write the result into the def map.
debug!{"(resolving expr) resolved `%s`",
connect(path.idents.map(|x| *x), ~"::")};
self.record_def(expr.id, def);
}
- none {
+ none => {
self.session.span_err(expr.span,
fmt!{"unresolved name: %s",
connect(path.idents.map(|x| *x),
}
expr_fn(_, fn_decl, block, capture_clause) |
- expr_fn_block(fn_decl, block, capture_clause) {
+ expr_fn_block(fn_decl, block, capture_clause) => {
self.resolve_function(FunctionRibKind(expr.id),
some(@fn_decl),
NoTypeParameters,
visitor);
}
- expr_struct(path, _) {
+ expr_struct(path, _) => {
// Resolve the path to the structure it goes to.
//
// XXX: We might want to support explicit type parameters in
alt self.resolve_path(path, TypeNS, false, visitor) {
some(definition @ def_ty(class_id))
- if self.structs.contains_key(class_id) {
+ if self.structs.contains_key(class_id) => {
let has_constructor = self.structs.get(class_id);
let class_def = def_class(class_id, has_constructor);
self.record_def(expr.id, class_def);
}
- _ {
+ _ => {
self.session.span_err(path.span,
fmt!{"`%s` does not name a \
structure",
visit_expr(expr, (), visitor);
}
- _ {
+ _ => {
visit_expr(expr, (), visitor);
}
}
fn record_impls_for_expr_if_necessary(expr: @expr) {
alt expr.node {
expr_field(*) | expr_path(*) | expr_cast(*) | expr_binary(*) |
- expr_unary(*) | expr_assign_op(*) | expr_index(*) {
+ expr_unary(*) | expr_assign_op(*) | expr_index(*) => {
self.impl_map.insert(expr.id,
self.current_module.impl_scopes);
}
- _ {
+ _ => {
// Nothing to do.
}
}
self.add_fixed_trait_for_expr(expr.id,
self.lang_items.neg_trait);
}
- expr_index(*) {
+ expr_index(*) => {
self.add_fixed_trait_for_expr(expr.id,
self.lang_items.index_trait);
}
loop {
// Look for the current trait.
alt copy self.current_trait_refs {
- some(trait_def_ids) {
+ some(trait_def_ids) => {
for trait_def_ids.each |trait_def_id| {
self.add_trait_info_if_containing_method
(found_traits, trait_def_id, name);
}
}
- none {
+ none => {
// Nothing to do.
}
}
// Look for trait children.
for search_module.children.each |_name, child_name_bindings| {
alt child_name_bindings.def_for_namespace(TypeNS) {
- some(def_ty(trait_def_id)) {
+ some(def_ty(trait_def_id)) => {
self.add_trait_info_if_containing_method(found_traits,
trait_def_id,
name);
}
- some(_) | none {
+ some(_) | none => {
// Continue.
}
}
|_atom, import_resolution| {
alt import_resolution.target_for_namespace(TypeNS) {
- none {
+ none => {
// Continue.
}
- some(target) {
+ some(target) => {
alt target.bindings.def_for_namespace(TypeNS) {
- some(def_ty(trait_def_id)) {
+ some(def_ty(trait_def_id)) => {
self.add_trait_info_if_containing_method
(found_traits, trait_def_id, name);
}
- some(_) | none {
+ some(_) | none => {
// Continue.
}
}
// Move to the next parent.
alt search_module.parent_link {
- NoParentLink {
+ NoParentLink => {
// Done.
break;
}
ModuleParentLink(parent_module, _) |
- BlockParentLink(parent_module, _) {
+ BlockParentLink(parent_module, _) => {
search_module = parent_module;
}
}
name: Atom) {
alt self.trait_info.find(trait_def_id) {
- some(trait_info) if trait_info.contains_key(name) {
+ some(trait_info) if trait_info.contains_key(name) => {
debug!{"(adding trait info if containing method) found trait \
%d:%d for method '%s'",
trait_def_id.crate,
*(*self.atom_table).atom_to_str(name)};
(*found_traits).push(trait_def_id);
}
- some(_) | none {
+ some(_) | none => {
// Continue.
}
}
// for unused imports in external crates.
alt module_.def_id {
- some(def_id) if def_id.crate == local_crate {
+ some(def_id) if def_id.crate == local_crate => {
// OK. Continue.
}
- none {
+ none => {
// Check for unused imports in the root module.
}
- some(_) {
+ some(_) => {
// Bail out.
debug!{"(checking for unused imports in module subtree) not \
checking for unused imports for `%s`",
for module_.children.each |_atom, child_name_bindings| {
alt (*child_name_bindings).get_module_if_available() {
- none {
+ none => {
// Nothing to do.
}
- some(child_module) {
+ some(child_module) => {
self.check_for_unused_imports_in_module_subtree
(child_module);
}
for module_.import_resolutions.each |_impl_name, import_resolution| {
if !import_resolution.used {
alt self.unused_import_lint_level {
- warn {
+ warn => {
self.session.span_warn(import_resolution.span,
~"unused import");
}
- deny | forbid {
+ deny | forbid => {
self.session.span_err(import_resolution.span,
~"unused import");
}
- allow {
+ allow => {
self.session.span_bug(import_resolution.span,
~"shouldn't be here if lint \
is allowed");
let mut current_module = module_;
loop {
alt current_module.parent_link {
- NoParentLink {
+ NoParentLink => {
break;
}
- ModuleParentLink(module_, name) {
+ ModuleParentLink(module_, name) => {
atoms.push(name);
current_module = module_;
}
- BlockParentLink(module_, node_id) {
+ BlockParentLink(module_, node_id) => {
atoms.push((*self.atom_table).intern(@~"<opaque>"));
current_module = module_;
}
for module_.import_resolutions.each |name, import_resolution| {
let mut module_repr;
alt (*import_resolution).target_for_namespace(ModuleNS) {
- none { module_repr = ~""; }
- some(target) {
+ none => { module_repr = ~""; }
+ some(target) => {
module_repr = ~" module:?";
// XXX
}
let mut value_repr;
alt (*import_resolution).target_for_namespace(ValueNS) {
- none { value_repr = ~""; }
- some(target) {
+ none => { value_repr = ~""; }
+ some(target) => {
value_repr = ~" value:?";
// XXX
}
let mut type_repr;
alt (*import_resolution).target_for_namespace(TypeNS) {
- none { type_repr = ~""; }
- some(target) {
+ none => { type_repr = ~""; }
+ some(target) => {
type_repr = ~" type:?";
// XXX
}
let mut impl_repr;
alt (*import_resolution).target_for_namespace(ImplNS) {
- none { impl_repr = ~""; }
- some(target) {
+ none => { impl_repr = ~""; }
+ some(target) => {
impl_repr = ~" impl:?";
// XXX
}
let mut impl_scopes = impl_scopes;
loop {
alt *impl_scopes {
- cons(impl_scope, rest_impl_scopes) {
+ cons(impl_scope, rest_impl_scopes) => {
debug!{"Impl scope %u:", i};
for (*impl_scope).each |implementation| {
i += 1u;
impl_scopes = rest_impl_scopes;
}
- nil {
+ nil => {
break;
}
}
}
fn opt_eq(tcx: ty::ctxt, a: opt, b: opt) -> bool {
alt (a, b) {
- (lit(a), lit(b)) { const_eval::compare_lit_exprs(tcx, a, b) == 0 }
- (range(a1, a2), range(b1, b2)) {
+ (lit(a), lit(b)) => const_eval::compare_lit_exprs(tcx, a, b) == 0,
+ (range(a1, a2), range(b1, b2)) => {
const_eval::compare_lit_exprs(tcx, a1, b1) == 0 &&
const_eval::compare_lit_exprs(tcx, a2, b2) == 0
}
- (var(a, _), var(b, _)) { a == b }
- _ { false }
+ (var(a, _), var(b, _)) => a == b,
+ _ => false
}
}
let ccx = bcx.ccx();
let mut bcx = bcx;
alt o {
- lit(l) {
+ lit(l) => {
alt l.node {
ast::expr_vstore(@{node: ast::expr_lit(
@{node: ast::lit_str(s), _}), _},
- ast::vstore_uniq) {
+ ast::vstore_uniq) => {
let strty = ty::mk_estr(bcx.tcx(), ty::vstore_uniq);
let cell = empty_dest_cell();
bcx = tvec::trans_estr(bcx, s, some(ast::vstore_uniq),
add_clean_temp(bcx, *cell, strty);
return single_result(rslt(bcx, *cell));
}
- _ {
+ _ => {
return single_result(
rslt(bcx, consts::const_expr(ccx, l)));
}
}
}
- var(disr_val, _) {
+ var(disr_val, _) => {
return single_result(rslt(bcx, C_int(ccx, disr_val)));
}
- range(l1, l2) {
+ range(l1, l2) => {
return range_result(rslt(bcx, consts::const_expr(ccx, l1)),
rslt(bcx, consts::const_expr(ccx, l2)));
}
fn has_nested_bindings(m: match_, col: uint) -> bool {
for vec::each(m) |br| {
alt br.pats[col].node {
- ast::pat_ident(_, _, some(_)) { return true; }
- _ {}
+ ast::pat_ident(_, _, some(_)) => return true,
+ _ => ()
}
}
return false;
let mut result = ~[];
for vec::each(m) |br| {
alt br.pats[col].node {
- ast::pat_ident(mode, name, some(inner)) {
+ ast::pat_ident(mode, name, some(inner)) => {
let pats = vec::append(
vec::slice(br.pats, 0u, col),
vec::append(~[inner],
}}])
with *br});
}
- _ { vec::push(result, br); }
+ _ => vec::push(result, br)
}
}
result
let mut result = ~[];
for vec::each(m) |br| {
alt e(br.pats[col]) {
- some(sub) {
+ some(sub) => {
let pats = vec::append(
vec::append(sub, vec::view(br.pats, 0u, col)),
vec::view(br.pats, col + 1u, br.pats.len()));
let self = br.pats[col];
let bound = alt self.node {
- ast::pat_ident(mode, name, none) if !pat_is_variant(dm, self) {
+ ast::pat_ident(mode, name, none)
+ if !pat_is_variant(dm, self) => {
vec::append(br.bound,
~[{ident: path_to_ident(name),
binding: binding {
ty: node_id_type(bcx, br.pats[col].id)
}}])
}
- _ { br.bound }
+ _ => br.bound
};
vec::push(result, @{pats: pats, bound: bound with *br});
}
- none { }
+ none => ()
}
}
return result;
do enter_match(bcx, dm, m, col, val) |p| {
alt p.node {
- ast::pat_wild | ast::pat_rec(_, _) | ast::pat_tup(_) { some(~[]) }
- ast::pat_ident(_, _, none) if !pat_is_variant(dm, p) {
- some(~[])
- }
- _ { none }
+ ast::pat_wild | ast::pat_rec(_, _) | ast::pat_tup(_) => some(~[]),
+ ast::pat_ident(_, _, none) if !pat_is_variant(dm, p) => some(~[]),
+ _ => none
}
}
}
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, tcx.def_map, m, col, val) |p| {
alt p.node {
- ast::pat_enum(_, subpats) {
+ ast::pat_enum(_, subpats) => {
if opt_eq(tcx, variant_opt(tcx, p.id), opt) {
some(option::get_default(subpats,
vec::from_elem(variant_size, dummy))) }
else { none }
}
- ast::pat_ident(_, _, none) if pat_is_variant(tcx.def_map, p) {
+ ast::pat_ident(_, _, none) if pat_is_variant(tcx.def_map, p) => {
if opt_eq(tcx, variant_opt(tcx, p.id), opt) { some(~[]) }
else { none }
}
- ast::pat_lit(l) {
+ ast::pat_lit(l) => {
if opt_eq(tcx, lit(l), opt) { some(~[]) } else { none }
}
- ast::pat_range(l1, l2) {
+ ast::pat_range(l1, l2) => {
if opt_eq(tcx, range(l1, l2), opt) { some(~[]) } else { none }
}
- _ { some(vec::from_elem(variant_size, dummy)) }
+ _ => some(vec::from_elem(variant_size, dummy))
}
}
}
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| {
alt p.node {
- ast::pat_rec(fpats, _) {
+ ast::pat_rec(fpats, _) => {
let mut pats = ~[];
for vec::each(fields) |fname| {
let mut pat = dummy;
}
some(pats)
}
- _ { some(vec::from_elem(fields.len(), dummy)) }
+ _ => some(vec::from_elem(fields.len(), dummy))
}
}
}
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| {
alt p.node {
- ast::pat_tup(elts) { some(elts) }
- _ { some(vec::from_elem(n_elts, dummy)) }
+ ast::pat_tup(elts) => some(elts),
+ _ => some(vec::from_elem(n_elts, dummy))
}
}
}
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| {
alt p.node {
- ast::pat_box(sub) { some(~[sub]) }
- _ { some(~[dummy]) }
+ ast::pat_box(sub) => some(~[sub]),
+ _ => some(~[dummy])
}
}
}
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| {
alt p.node {
- ast::pat_uniq(sub) { some(~[sub]) }
- _ { some(~[dummy]) }
+ ast::pat_uniq(sub) => some(~[sub]),
+ _ => some(~[dummy])
}
}
}
add_to_set(ccx.tcx, found, variant_opt(ccx.tcx, br.pats[col].id));
} else {
alt cur.node {
- ast::pat_lit(l) { add_to_set(ccx.tcx, found, lit(l)); }
- ast::pat_range(l1, l2) {
+ ast::pat_lit(l) => add_to_set(ccx.tcx, found, lit(l)),
+ ast::pat_range(l1, l2) => {
add_to_set(ccx.tcx, found, range(l1, l2));
}
- _ {}
+ _ => ()
}
}
}
let _icx = bcx.insn_ctxt(~"alt::extract_variant_args");
let ccx = bcx.fcx.ccx;
let enum_ty_substs = alt check ty::get(node_id_type(bcx, pat_id)).struct {
- ty::ty_enum(id, substs) { assert id == vdefs.enm; substs.tps }
+ ty::ty_enum(id, substs) => { assert id == vdefs.enm; substs.tps }
};
let mut blobptr = val;
let variants = ty::enum_variants(ccx.tcx, vdefs.enm);
let mut fields: ~[ast::ident] = ~[];
for vec::each(m) |br| {
alt br.pats[col].node {
- ast::pat_rec(fs, _) {
+ ast::pat_rec(fs, _) => {
for vec::each(fs) |f| {
if !vec::any(fields, |x| str::eq(f.ident, x)) {
vec::push(fields, f.ident);
}
}
}
- _ { }
+ _ => ()
}
}
return fields;
let pat_id = br.pats[col].id;
alt bcx.ccx().maps.root_map.find({id:pat_id, derefs:0u}) {
- none {}
- some(scope_id) {
+ none => (),
+ some(scope_id) => {
// Note: the scope_id will always be the id of the alt. See the
// extended comment in rustc::middle::borrowck::preserve() for
// details (look for the case covering cat_discr).
fn any_box_pat(m: match_, col: uint) -> bool {
for vec::each(m) |br| {
- alt br.pats[col].node { ast::pat_box(_) { return true; } _ { } }
+ alt br.pats[col].node {
+ ast::pat_box(_) => return true,
+ _ => ()
+ }
}
return false;
}
fn any_uniq_pat(m: match_, col: uint) -> bool {
for vec::each(m) |br| {
- alt br.pats[col].node { ast::pat_uniq(_) { return true; } _ { } }
+ alt br.pats[col].node {
+ ast::pat_uniq(_) => return true,
+ _ => ()
+ }
}
return false;
}
fn any_tup_pat(m: match_, col: uint) -> bool {
for vec::each(m) |br| {
- alt br.pats[col].node { ast::pat_tup(_) { return true; } _ { } }
+ alt br.pats[col].node {
+ ast::pat_tup(_) => return true,
+ _ => ()
+ }
}
return false;
}
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 }
- ast::pat_ident(_, _, some(p)) { score(p) }
- _ { 0u }
+ ast::pat_lit(_) | ast::pat_enum(_, _) | ast::pat_range(_, _) => 1u,
+ ast::pat_ident(_, _, some(p)) => score(p),
+ _ => 0u
}
}
let scores = vec::to_mut(vec::from_elem(m[0].pats.len(), 0u));
if m[0].pats.len() == 0u {
let data = m[0].data;
alt data.guard {
- some(e) {
+ some(e) => {
// Temporarily set bindings. They'll be rewritten to PHI nodes
// for the actual arm block.
//
bcx
};
}
- _ { }
+ _ => ()
}
if !bcx.unreachable {
vec::push(exits, {bound: m[0].bound, from: bcx.llbb,
if any_tup_pat(m, col) {
let tup_ty = node_id_type(bcx, pat_id);
let n_tup_elts = alt ty::get(tup_ty).struct {
- ty::ty_tup(elts) { elts.len() }
- _ { ccx.sess.bug(~"non-tuple type in tuple pattern"); }
+ ty::ty_tup(elts) => elts.len(),
+ _ => ccx.sess.bug(~"non-tuple type in tuple pattern")
};
let mut tup_vals = ~[], i = 0u;
while i < n_tup_elts {
let mut test_val = val;
if opts.len() > 0u {
alt opts[0] {
- var(_, vdef) {
+ var(_, vdef) => {
if (*ty::enum_variants(tcx, vdef.enm)).len() == 1u {
kind = single;
} else {
kind = switch;
}
}
- lit(l) {
+ lit(l) => {
test_val = Load(bcx, val);
let pty = node_id_type(bcx, pat_id);
kind = if ty::type_is_integral(pty) { switch }
else { compare };
}
- range(_, _) {
+ range(_, _) => {
test_val = Load(bcx, val);
kind = compare;
}
}
for vec::each(opts) |o| {
alt o {
- range(_, _) { kind = compare; break; }
- _ { }
+ range(_, _) => { kind = compare; break }
+ _ => ()
}
}
let else_cx = alt kind {
- no_branch | single { bcx }
- _ { sub_block(bcx, ~"match_else") }
+ no_branch | single => bcx,
+ _ => sub_block(bcx, ~"match_else")
};
let sw = if kind == switch {
Switch(bcx, test_val, else_cx.llbb, opts.len())
if !exhaustive || i < len {
opt_cx = sub_block(bcx, ~"match_case");
alt kind {
- single { Br(bcx, opt_cx.llbb); }
- switch {
+ single => Br(bcx, opt_cx.llbb),
+ switch => {
alt check trans_opt(bcx, opt) {
- single_result(r) {
+ single_result(r) => {
llvm::LLVMAddCase(sw, r.val, opt_cx.llbb);
bcx = r.bcx;
}
}
}
- compare {
+ compare => {
let t = node_id_type(bcx, pat_id);
let {bcx: after_cx, val: matches} = {
do with_scope_result(bcx, none, ~"compare_scope") |bcx| {
alt trans_opt(bcx, opt) {
- single_result({bcx, val}) {
+ single_result({bcx, val}) => {
trans_compare(bcx, ast::eq, test_val, t, val, t)
}
- range_result({val: vbegin, _}, {bcx, val: vend}) {
+ range_result(
+ {val: vbegin, _}, {bcx, val: vend}) => {
let {bcx, val: llge} = trans_compare(
bcx, ast::ge, test_val, t, vbegin, t);
let {bcx, val: llle} = trans_compare(
bcx = sub_block(after_cx, ~"compare_next");
CondBr(after_cx, matches, opt_cx.llbb, bcx.llbb);
}
- _ { }
+ _ => ()
}
} else if kind == compare { Br(bcx, else_cx.llbb); }
let mut size = 0u;
let mut unpacked = ~[];
alt opt {
- var(_, vdef) {
+ var(_, vdef) => {
let args = extract_variant_args(opt_cx, pat_id, vdef, val);
size = args.vals.len();
unpacked = args.vals;
opt_cx = args.bcx;
}
- lit(_) | range(_, _) { }
+ lit(_) | range(_, _) => ()
}
compile_submatch(opt_cx, enter_opt(bcx, m, opt, col, size, val),
vec::append(unpacked, vals_left), chk, exits);
for vec::each(map) |ex| {
if ex.to as uint == our_block {
alt assoc(name, ex.bound) {
- some(binding) {
+ some(binding) => {
vec::push(llbbs, ex.from);
vec::push(vals, binding.val);
}
- none { }
+ none => ()
}
}
}
fn mk_fail(bcx: block, sp: span, msg: ~str,
done: @mut option<BasicBlockRef>) -> BasicBlockRef {
- alt *done { some(bb) { return bb; } _ { } }
+ alt *done { some(bb) => return bb, _ => () }
let fail_cx = sub_block(bcx, ~"case_fallthrough");
trans_fail(fail_cx, some(sp), msg);
*done = some(fail_cx.llbb);
}
let t = node_id_type(bcx, expr.id);
let mk_fail = alt mode {
- ast::alt_check {
+ ast::alt_check => {
let fail_cx = @mut none;
// Cached fail-on-fallthrough block
some(|| mk_fail(scope_cx, expr.span, ~"non-exhaustive match failure",
fail_cx))
}
- ast::alt_exhaustive {
+ ast::alt_exhaustive => {
let fail_cx = @mut none;
// special case for uninhabited type
if ty::type_is_empty(tcx, t) {
// Necessary since bind_irrefutable_pat is called outside trans_alt
alt pat.node {
- ast::pat_ident(_, _,inner) {
+ ast::pat_ident(_, _,inner) => {
if pat_is_variant(bcx.tcx().def_map, pat) { return bcx; }
if make_copy {
let ty = node_id_type(bcx, pat.id);
add_clean(bcx, alloc, ty);
} else { bcx.fcx.lllocals.insert(pat.id, local_mem(val)); }
alt inner {
- some(pat) { bcx = bind_irrefutable_pat(bcx, pat, val, true); }
- _ {}
+ some(pat) => { bcx = bind_irrefutable_pat(bcx, pat, val, true); }
+ _ => ()
}
}
- ast::pat_enum(_, sub) {
+ ast::pat_enum(_, sub) => {
let vdefs = ast_util::variant_def_ids(ccx.tcx.def_map.get(pat.id));
let args = extract_variant_args(bcx, pat.id, vdefs, val);
let mut i = 0;
i += 1;
}}
}
- ast::pat_rec(fields, _) {
+ ast::pat_rec(fields, _) => {
let rec_fields = ty::get_fields(node_id_type(bcx, pat.id));
for vec::each(fields) |f| {
let ix = option::get(ty::field_idx(f.ident, rec_fields));
bcx = bind_irrefutable_pat(bcx, f.pat, fldptr, make_copy);
}
}
- ast::pat_tup(elems) {
+ ast::pat_tup(elems) => {
let mut i = 0u;
for vec::each(elems) |elem| {
let fldptr = GEPi(bcx, val, ~[0u, i]);
i += 1u;
}
}
- ast::pat_box(inner) {
+ ast::pat_box(inner) => {
let llbox = Load(bcx, val);
let unboxed =
GEPi(bcx, llbox, ~[0u, abi::box_field_body]);
bcx = bind_irrefutable_pat(bcx, inner, unboxed, true);
}
- ast::pat_uniq(inner) {
+ ast::pat_uniq(inner) => {
let llbox = Load(bcx, val);
let unboxed =
GEPi(bcx, llbox, ~[0u, abi::box_field_body]);
bcx = bind_irrefutable_pat(bcx, inner, unboxed, true);
}
- ast::pat_wild | ast::pat_lit(_) | ast::pat_range(_, _) { }
+ ast::pat_wild | ast::pat_lit(_) | ast::pat_range(_, _) => ()
}
return bcx;
}
fn dest_str(ccx: @crate_ctxt, d: dest) -> ~str {
alt d {
- by_val(v) { fmt!{"by_val(%s)", val_str(ccx.tn, *v)} }
- save_in(v) { fmt!{"save_in(%s)", val_str(ccx.tn, v)} }
- ignore { ~"ignore" }
+ by_val(v) => fmt!{"by_val(%s)", val_str(ccx.tn, *v)},
+ save_in(v) => fmt!{"save_in(%s)", val_str(ccx.tn, v)},
+ ignore => ~"ignore"
}
}
fn dup_for_join(dest: dest) -> dest {
alt dest {
- by_val(_) { by_val(empty_dest_cell()) }
- _ { dest }
+ by_val(_) => by_val(empty_dest_cell()),
+ _ => dest
}
}
Br(cx, out.llbb);
reachable = true;
alt in_ds[i] {
- by_val(cell) {
+ by_val(cell) => {
if option::is_none(phi) {
phi = some(EmptyPhi(out, val_ty(*cell)));
}
AddIncomingToPhi(option::get(phi), *cell, cx.llbb);
}
- _ {}
+ _ => ()
}
}
i += 1u;
Unreachable(out);
} else {
alt out_dest {
- by_val(cell) { *cell = option::get(phi); }
- _ {}
+ by_val(cell) => *cell = option::get(phi),
+ _ => ()
}
}
return out;
// Used to put an immediate value in a dest.
fn store_in_dest(bcx: block, val: ValueRef, dest: dest) -> block {
alt dest {
- ignore {}
- by_val(cell) { *cell = val; }
- save_in(addr) { Store(bcx, val, addr); }
+ ignore => (),
+ by_val(cell) => *cell = val,
+ save_in(addr) => Store(bcx, val, addr)
}
return bcx;
}
fn get_dest_addr(dest: dest) -> ValueRef {
alt dest {
- save_in(a) { a }
- _ { fail ~"get_dest_addr: not a save_in"; }
+ save_in(a) => a,
+ _ => fail ~"get_dest_addr: not a save_in"
}
}
let ccx = bcx.ccx();
let (mk_fn, rtcall) = alt heap {
- heap_shared { (ty::mk_imm_box, ~"malloc") }
- heap_exchange { (ty::mk_imm_uniq, ~"exchange_malloc") }
+ heap_shared => (ty::mk_imm_box, ~"malloc"),
+ heap_exchange => (ty::mk_imm_uniq, ~"exchange_malloc")
};
// Grab the TypeRef type of box_ptr_ty.
fn get_tydesc(ccx: @crate_ctxt, t: ty::t) -> @tydesc_info {
alt ccx.tydescs.find(t) {
- some(inf) { inf }
- _ {
+ some(inf) => inf,
+ _ => {
ccx.stats.n_static_tydescs += 1u;
let inf = declare_tydesc(ccx, t);
ccx.tydescs.insert(t, inf);
fn set_inline_hint_if_appr(attrs: ~[ast::attribute],
llfn: ValueRef) {
alt attr::find_inline_attr(attrs) {
- attr::ia_hint { set_inline_hint(llfn); }
- attr::ia_always { set_always_inline(llfn); }
- attr::ia_never { set_no_inline(llfn); }
- attr::ia_none { /* fallthrough */ }
+ attr::ia_hint => set_inline_hint(llfn),
+ attr::ia_always => set_always_inline(llfn),
+ attr::ia_never => set_no_inline(llfn),
+ attr::ia_none => { /* fallthrough */ }
}
}
let ti = val;
let take_glue =
alt copy ti.take_glue {
- none { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
- some(v) { ccx.stats.n_real_glues += 1u; v }
+ none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
+ some(v) => { ccx.stats.n_real_glues += 1u; v }
};
let drop_glue =
alt copy ti.drop_glue {
- none { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
- some(v) { ccx.stats.n_real_glues += 1u; v }
+ none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
+ some(v) => { ccx.stats.n_real_glues += 1u; v }
};
let free_glue =
alt copy ti.free_glue {
- none { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
- some(v) { ccx.stats.n_real_glues += 1u; v }
+ none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
+ some(v) => { ccx.stats.n_real_glues += 1u; v }
};
let visit_glue =
alt copy ti.visit_glue {
- none { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
- some(v) { ccx.stats.n_real_glues += 1u; v }
+ none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
+ some(v) => { ccx.stats.n_real_glues += 1u; v }
};
let shape = shape_of(ccx, key);
// NB: v is a *pointer* to type t here, not a direct value.
let bcx = alt ty::get(t).struct {
ty::ty_box(_) | ty::ty_opaque_box |
- ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_box) {
+ ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_box) => {
incr_refcnt_of_boxed(bcx, Load(bcx, v)); bcx
}
- ty::ty_uniq(_) {
+ ty::ty_uniq(_) => {
let {bcx, val} = uniq::duplicate(bcx, Load(bcx, v), t);
Store(bcx, val, v);
bcx
}
- ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) {
+ ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) => {
let {bcx, val} = tvec::duplicate_uniq(bcx, Load(bcx, v), t);
Store(bcx, val, v);
bcx
}
- ty::ty_evec(_, ty::vstore_slice(_)) | ty::ty_estr(ty::vstore_slice(_)) {
+ ty::ty_evec(_, ty::vstore_slice(_))
+ | ty::ty_estr(ty::vstore_slice(_)) => {
bcx
}
- ty::ty_fn(_) {
+ ty::ty_fn(_) => {
closure::make_fn_glue(bcx, v, t, take_ty)
}
- ty::ty_trait(_, _) {
+ ty::ty_trait(_, _) => {
let llbox = Load(bcx, GEPi(bcx, v, ~[0u, 1u]));
incr_refcnt_of_boxed(bcx, llbox);
bcx
}
- ty::ty_opaque_closure_ptr(ck) {
+ ty::ty_opaque_closure_ptr(ck) => {
closure::make_opaque_cbox_take_glue(bcx, ck, v)
}
- _ if ty::type_is_structural(t) {
+ _ if ty::type_is_structural(t) => {
iter_structural_ty(bcx, v, t, take_ty)
}
- _ { bcx }
+ _ => bcx
};
build_return(bcx);
let _icx = bcx.insn_ctxt(~"make_free_glue");
let ccx = bcx.ccx();
let bcx = alt ty::get(t).struct {
- ty::ty_box(body_mt) {
+ ty::ty_box(body_mt) => {
let v = PointerCast(bcx, v, type_of(ccx, t));
let body = GEPi(bcx, v, ~[0u, abi::box_field_body]);
let bcx = drop_ty(bcx, body, body_mt.ty);
trans_free(bcx, v)
}
- ty::ty_opaque_box {
+ ty::ty_opaque_box => {
let v = PointerCast(bcx, v, type_of(ccx, t));
let td = Load(bcx, GEPi(bcx, v, ~[0u, abi::box_field_tydesc]));
let valptr = GEPi(bcx, v, ~[0u, abi::box_field_body]);
none);
trans_free(bcx, v)
}
- ty::ty_uniq(content_mt) {
+ ty::ty_uniq(content_mt) => {
let v = PointerCast(bcx, v, type_of(ccx, t));
uniq::make_free_glue(bcx, v, t)
}
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) |
- ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_box) {
+ ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_box) => {
make_free_glue(bcx, v,
tvec::expand_boxed_vec_ty(bcx.tcx(), t));
return;
}
- ty::ty_fn(_) {
+ ty::ty_fn(_) => {
closure::make_fn_glue(bcx, v, t, free_ty)
}
- ty::ty_opaque_closure_ptr(ck) {
+ ty::ty_opaque_closure_ptr(ck) => {
closure::make_opaque_cbox_free_glue(bcx, ck, v)
}
- ty::ty_class(did,substs) {
+ ty::ty_class(did,substs) => {
// Call the dtor if there is one
do option::map_default(ty::ty_dtor(bcx.tcx(), did), bcx) |dt_id| {
trans_class_drop(bcx, v, dt_id, did, substs)
}
}
- _ { bcx }
+ _ => bcx
};
build_return(bcx);
}
let ccx = bcx.ccx();
let bcx = alt ty::get(t).struct {
ty::ty_box(_) | ty::ty_opaque_box |
- ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) {
+ ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) => {
decr_refcnt_maybe_free(bcx, Load(bcx, v0), t)
}
ty::ty_uniq(_) |
- ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) {
+ ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) => {
free_ty(bcx, Load(bcx, v0), t)
}
- ty::ty_unboxed_vec(_) {
+ ty::ty_unboxed_vec(_) => {
tvec::make_drop_glue_unboxed(bcx, v0, t)
}
- ty::ty_class(did, substs) {
+ ty::ty_class(did, substs) => {
let tcx = bcx.tcx();
alt ty::ty_dtor(tcx, did) {
- some(dtor) {
+ some(dtor) => {
trans_class_drop(bcx, v0, dtor, did, substs)
}
- none {
+ none => {
// No dtor? Just the default case
iter_structural_ty(bcx, v0, t, drop_ty)
}
}
}
- ty::ty_fn(_) {
+ ty::ty_fn(_) => {
closure::make_fn_glue(bcx, v0, t, drop_ty)
}
- ty::ty_trait(_, _) {
+ ty::ty_trait(_, _) => {
let llbox = Load(bcx, GEPi(bcx, v0, ~[0u, 1u]));
decr_refcnt_maybe_free(bcx, llbox, ty::mk_opaque_box(ccx.tcx))
}
- ty::ty_opaque_closure_ptr(ck) {
+ ty::ty_opaque_closure_ptr(ck) => {
closure::make_opaque_cbox_drop_glue(bcx, ck, v0)
}
- _ {
+ _ => {
if ty::type_needs_drop(ccx.tcx, t) &&
ty::type_is_structural(t) {
iter_structural_ty(bcx, v0, t, drop_ty)
let f = |a| compare_scalar_values(cx, lhs, rhs, a, op);
alt ty::get(t).struct {
- ty::ty_nil { return rslt(cx, f(nil_type)); }
- ty::ty_bool | ty::ty_ptr(_) { return rslt(cx, f(unsigned_int)); }
- ty::ty_int(_) { return rslt(cx, f(signed_int)); }
- ty::ty_uint(_) { return rslt(cx, f(unsigned_int)); }
- ty::ty_float(_) { return rslt(cx, f(floating_point)); }
- ty::ty_type {
+ ty::ty_nil => return rslt(cx, f(nil_type)),
+ ty::ty_bool | ty::ty_ptr(_) => return rslt(cx, f(unsigned_int)),
+ ty::ty_int(_) => return rslt(cx, f(signed_int)),
+ ty::ty_uint(_) => return rslt(cx, f(unsigned_int)),
+ ty::ty_float(_) => return rslt(cx, f(floating_point)),
+ ty::ty_type => {
return rslt(trans_fail(cx, none,
~"attempt to compare values of type type"),
C_nil());
}
- _ {
+ _ => {
// Should never get here, because t is scalar.
cx.sess().bug(~"non-scalar type passed to \
compare_scalar_types");
}
let die = fn@() -> ! { die_(cx) };
alt nt {
- nil_type {
+ nil_type => {
// We don't need to do actual comparisons for nil.
// () == () holds but () < () does not.
alt op {
- ast::eq | ast::le | ast::ge { return C_bool(true); }
- ast::ne | ast::lt | ast::gt { return C_bool(false); }
+ ast::eq | ast::le | ast::ge => return C_bool(true),
+ ast::ne | ast::lt | ast::gt => return C_bool(false),
// refinements would be nice
- _ { die(); }
+ _ => die()
}
}
- floating_point {
+ floating_point => {
let cmp = alt op {
- ast::eq { lib::llvm::RealOEQ }
- ast::ne { lib::llvm::RealUNE }
- ast::lt { lib::llvm::RealOLT }
- ast::le { lib::llvm::RealOLE }
- ast::gt { lib::llvm::RealOGT }
- ast::ge { lib::llvm::RealOGE }
- _ { die(); }
+ ast::eq => lib::llvm::RealOEQ,
+ ast::ne => lib::llvm::RealUNE,
+ ast::lt => lib::llvm::RealOLT,
+ ast::le => lib::llvm::RealOLE,
+ ast::gt => lib::llvm::RealOGT,
+ ast::ge => lib::llvm::RealOGE,
+ _ => die()
};
return FCmp(cx, cmp, lhs, rhs);
}
- signed_int {
+ signed_int => {
let cmp = alt op {
- ast::eq { lib::llvm::IntEQ }
- ast::ne { lib::llvm::IntNE }
- ast::lt { lib::llvm::IntSLT }
- ast::le { lib::llvm::IntSLE }
- ast::gt { lib::llvm::IntSGT }
- ast::ge { lib::llvm::IntSGE }
- _ { die(); }
+ ast::eq => lib::llvm::IntEQ,
+ ast::ne => lib::llvm::IntNE,
+ ast::lt => lib::llvm::IntSLT,
+ ast::le => lib::llvm::IntSLE,
+ ast::gt => lib::llvm::IntSGT,
+ ast::ge => lib::llvm::IntSGE,
+ _ => die()
};
return ICmp(cx, cmp, lhs, rhs);
}
- unsigned_int {
+ unsigned_int => {
let cmp = alt op {
- ast::eq { lib::llvm::IntEQ }
- ast::ne { lib::llvm::IntNE }
- ast::lt { lib::llvm::IntULT }
- ast::le { lib::llvm::IntULE }
- ast::gt { lib::llvm::IntUGT }
- ast::ge { lib::llvm::IntUGE }
- _ { die(); }
+ ast::eq => lib::llvm::IntEQ,
+ ast::ne => lib::llvm::IntNE,
+ ast::lt => lib::llvm::IntULT,
+ ast::le => lib::llvm::IntULE,
+ ast::gt => lib::llvm::IntUGT,
+ ast::ge => lib::llvm::IntUGE,
+ _ => die()
};
return ICmp(cx, cmp, lhs, rhs);
}
let ccx = cx.ccx();
let mut cx = cx;
alt ty::get(fn_ty).struct {
- ty::ty_fn({inputs: args, _}) {
+ ty::ty_fn({inputs: args, _}) => {
let mut j = 0u;
let v_id = variant.id;
for vec::each(args) |a| {
j += 1u;
}
}
- _ { cx.tcx().sess.bug(~"iter_variant: not a function type"); }
+ _ => cx.tcx().sess.bug(~"iter_variant: not a function type")
}
return cx;
}
*/
let mut cx = cx;
alt ty::get(t).struct {
- ty::ty_rec(fields) {
+ ty::ty_rec(fields) => {
for vec::eachi(fields) |i, fld| {
let llfld_a = GEPi(cx, av, ~[0u, i]);
cx = f(cx, llfld_a, fld.mt.ty);
}
}
ty::ty_estr(ty::vstore_fixed(n)) |
- ty::ty_evec(_, ty::vstore_fixed(n)) {
+ ty::ty_evec(_, ty::vstore_fixed(n)) => {
let (base, len) = tvec::get_base_and_len(cx, av, t);
cx = tvec::iter_vec_raw(cx, base, t, len, f);
}
- ty::ty_tup(args) {
+ ty::ty_tup(args) => {
for vec::eachi(args) |i, arg| {
let llfld_a = GEPi(cx, av, ~[0u, i]);
cx = f(cx, llfld_a, arg);
}
}
- ty::ty_enum(tid, substs) {
+ ty::ty_enum(tid, substs) => {
let variants = ty::enum_variants(cx.tcx(), tid);
let n_variants = (*variants).len();
}
return next_cx;
}
- ty::ty_class(did, substs) {
+ ty::ty_class(did, substs) => {
// Take the drop bit into account
let classptr = if is_some(ty::ty_dtor(cx.tcx(), did)) {
GEPi(cx, av, ~[0u, 1u])
cx = f(cx, llfld_a, fld.mt.ty);
}
}
- _ { cx.sess().unimpl(~"type in iter_structural_ty"); }
+ _ => cx.sess().unimpl(~"type in iter_structural_ty")
}
return cx;
}
let _icx = ccx.insn_ctxt(~"lazily_emit_tydesc_glue");
if field == abi::tydesc_field_take_glue {
alt ti.take_glue {
- some(_) { }
- none {
+ some(_) => (),
+ none => {
debug!{"+++ lazily_emit_tydesc_glue TAKE %s",
ppaux::ty_to_str(ccx.tcx, ti.ty)};
let glue_fn = declare_generic_glue
}
} else if field == abi::tydesc_field_drop_glue {
alt ti.drop_glue {
- some(_) { }
- none {
+ some(_) => (),
+ none => {
debug!{"+++ lazily_emit_tydesc_glue DROP %s",
ppaux::ty_to_str(ccx.tcx, ti.ty)};
let glue_fn =
}
} else if field == abi::tydesc_field_free_glue {
alt ti.free_glue {
- some(_) { }
- none {
+ some(_) => (),
+ none => {
debug!{"+++ lazily_emit_tydesc_glue FREE %s",
ppaux::ty_to_str(ccx.tcx, ti.ty)};
let glue_fn =
}
} else if field == abi::tydesc_field_visit_glue {
alt ti.visit_glue {
- some(_) { }
- none {
+ some(_) => (),
+ none => {
debug!{"+++ lazily_emit_tydesc_glue VISIT %s",
ppaux::ty_to_str(ccx.tcx, ti.ty)};
let glue_fn =
let mut static_glue_fn = none;
alt static_ti {
- none {/* no-op */ }
- some(sti) {
+ none => {/* no-op */ }
+ some(sti) => {
lazily_emit_tydesc_glue(cx.ccx(), field, sti);
if field == abi::tydesc_field_take_glue {
static_glue_fn = sti.take_glue;
let llfn = {
alt static_glue_fn {
- none {
+ none => {
// Select out the glue function to call from the tydesc
let llfnptr = GEPi(cx, tydesc, ~[0u, field]);
Load(cx, llfnptr)
}
- some(sgf) { sgf }
+ some(sgf) => sgf
}
};
alt ty::get(t).struct {
ty::ty_uniq(_) |
ty::ty_evec(_, ty::vstore_uniq) |
- ty::ty_estr(ty::vstore_uniq) {
+ ty::ty_estr(ty::vstore_uniq) => {
free_ty(bcx, v, t)
}
ty::ty_box(_) | ty::ty_opaque_box |
ty::ty_evec(_, ty::vstore_box) |
- ty::ty_estr(ty::vstore_box) {
+ ty::ty_estr(ty::vstore_box) => {
decr_refcnt_maybe_free(bcx, v, t)
}
- _ { bcx.tcx().sess.bug(~"drop_ty_immediate: non-box ty"); }
+ _ => bcx.tcx().sess.bug(~"drop_ty_immediate: non-box ty")
}
}
alt ty::get(t).struct {
ty::ty_box(_) | ty::ty_opaque_box |
ty::ty_evec(_, ty::vstore_box) |
- ty::ty_estr(ty::vstore_box) {
+ ty::ty_estr(ty::vstore_box) => {
incr_refcnt_of_boxed(bcx, v);
rslt(bcx, v)
}
- ty::ty_uniq(_) {
+ ty::ty_uniq(_) => {
uniq::duplicate(bcx, v, t)
}
ty::ty_evec(_, ty::vstore_uniq) |
- ty::ty_estr(ty::vstore_uniq) {
+ ty::ty_estr(ty::vstore_uniq) => {
tvec::duplicate_uniq(bcx, v, t)
}
- _ { rslt(bcx, v) }
+ _ => rslt(bcx, v)
}
}
let _icx = cx.insn_ctxt(~"call_memmove");
let ccx = cx.ccx();
let key = alt ccx.sess.targ_cfg.arch {
- session::arch_x86 | session::arch_arm { ~"llvm.memmove.p0i8.p0i8.i32" }
- session::arch_x86_64 { ~"llvm.memmove.p0i8.p0i8.i64" }
+ session::arch_x86 | session::arch_arm => ~"llvm.memmove.p0i8.p0i8.i32",
+ session::arch_x86_64 => ~"llvm.memmove.p0i8.p0i8.i64"
};
let memmove = ccx.intrinsics.get(key);
let src_ptr = PointerCast(cx, src, T_ptr(T_i8()));
fn type_is_structural_or_param(t: ty::t) -> bool {
if ty::type_is_structural(t) { return true; }
alt ty::get(t).struct {
- ty::ty_param(*) { return true; }
- _ { return false; }
+ ty::ty_param(*) => return true,
+ _ => return false
}
}
let _icx = bcx.insn_ctxt(~"trans_unary");
// Check for user-defined method call
alt bcx.ccx().maps.method_map.find(un_expr.id) {
- some(mentry) {
+ some(mentry) => {
let fty = node_id_type(bcx, un_expr.callee_id);
return trans_call_inner(
bcx, un_expr.info(), fty,
mentry),
arg_exprs(~[]), dest);
}
- _ {}
+ _ => ()
}
if dest == ignore { return trans_expr(bcx, e, ignore); }
let e_ty = expr_ty(bcx, e);
alt op {
- ast::not {
+ ast::not => {
let {bcx, val} = trans_temp_expr(bcx, e);
store_in_dest(bcx, Not(bcx, val), dest)
}
- ast::neg {
+ ast::neg => {
let {bcx, val} = trans_temp_expr(bcx, e);
let llneg = if ty::type_is_fp(e_ty) {
FNeg(bcx, val)
} else { Neg(bcx, val) };
store_in_dest(bcx, llneg, dest)
}
- ast::box(_) {
+ ast::box(_) => {
trans_boxed_expr(bcx, e, e_ty, heap_shared, dest)
}
- ast::uniq(_) {
+ ast::uniq(_) => {
trans_boxed_expr(bcx, e, e_ty, heap_exchange, dest)
}
- ast::deref {
+ ast::deref => {
bcx.sess().bug(~"deref expressions should have been \
translated using trans_lval(), not \
trans_unary()")
// Determine the operation we need.
let llop = {
alt op {
- ast::eq | ast::ne { C_u8(abi::cmp_glue_op_eq) }
- ast::lt | ast::ge { C_u8(abi::cmp_glue_op_lt) }
- ast::le | ast::gt { C_u8(abi::cmp_glue_op_le) }
- _ { cx.tcx().sess.bug(~"trans_compare got non-comparison-op"); }
+ ast::eq | ast::ne => C_u8(abi::cmp_glue_op_eq),
+ ast::lt | ast::ge => C_u8(abi::cmp_glue_op_lt),
+ ast::le | ast::gt => C_u8(abi::cmp_glue_op_le),
+ _ => cx.tcx().sess.bug(~"trans_compare got non-comparison-op")
}
};
// Invert the result if necessary.
alt op {
- ast::eq | ast::lt | ast::le { rslt(cx, cmpval) }
- ast::ne | ast::ge | ast::gt { rslt(cx, Not(cx, cmpval)) }
- _ { cx.tcx().sess.bug(~"trans_compare got non-comparison-op"); }
+ ast::eq | ast::lt | ast::le => rslt(cx, cmpval),
+ ast::ne | ast::ge | ast::gt => rslt(cx, Not(cx, cmpval)),
+ _ => cx.tcx().sess.bug(~"trans_compare got non-comparison-op")
}
}
~"modulo zero"
};
let is_zero = alt ty::get(rhs_t).struct {
- ty::ty_int(t) {
+ ty::ty_int(t) => {
let zero = C_integral(T_int_ty(cx.ccx(), t), 0u64, False);
ICmp(cx, lib::llvm::IntEQ, rhs, zero)
}
- ty::ty_uint(t) {
+ ty::ty_uint(t) => {
let zero = C_integral(T_uint_ty(cx.ccx(), t), 0u64, False);
ICmp(cx, lib::llvm::IntEQ, rhs, zero)
}
- _ {
+ _ => {
cx.tcx().sess.bug(~"fail-if-zero on unexpected type: " +
ty_to_str(cx.ccx().tcx, rhs_t));
}
let mut cx = cx;
let val = alt op {
- ast::add {
+ ast::add => {
if is_float { FAdd(cx, lhs, rhs) }
else { Add(cx, lhs, rhs) }
}
- ast::subtract {
+ ast::subtract => {
if is_float { FSub(cx, lhs, rhs) }
else { Sub(cx, lhs, rhs) }
}
- ast::mul {
+ ast::mul => {
if is_float { FMul(cx, lhs, rhs) }
else { Mul(cx, lhs, rhs) }
}
- ast::div {
+ ast::div => {
if is_float {
FDiv(cx, lhs, rhs)
} else {
}
}
}
- ast::rem {
+ ast::rem => {
if is_float {
FRem(cx, lhs, rhs)
} else {
}
}
}
- ast::bitor { Or(cx, lhs, rhs) }
- ast::bitand { And(cx, lhs, rhs) }
- ast::bitxor { Xor(cx, lhs, rhs) }
- ast::shl { Shl(cx, lhs, rhs) }
- ast::shr {
+ ast::bitor => Or(cx, lhs, rhs),
+ ast::bitand => And(cx, lhs, rhs),
+ ast::bitxor => Xor(cx, lhs, rhs),
+ ast::shl => Shl(cx, lhs, rhs),
+ ast::shr => {
if ty::type_is_signed(intype) {
AShr(cx, lhs, rhs)
} else { LShr(cx, lhs, rhs) }
}
- _ {
+ _ => {
let cmpr = trans_compare(cx, op, lhs, lhs_t, rhs, rhs_t);
cx = cmpr.bcx;
cmpr.val
// A user-defined operator method
alt bcx.ccx().maps.method_map.find(ex.id) {
- some(origin) {
+ some(origin) => {
let bcx = lhs_res.bcx;
debug!{"user-defined method callee_id: %s",
ast_map::node_id_to_str(bcx.tcx().items, ex.callee_id)};
{bcx: bcx, val: target, kind: lv_owned},
dty);
}
- _ {}
+ _ => ()
}
let {bcx, val: rhs_val} = trans_temp_expr(lhs_res.bcx, src);
// root the autoderef'd value, if necessary:
derefs += 1u;
alt ccx.maps.root_map.find({id:e_id, derefs:derefs}) {
- none { }
- some(scope_id) {
+ none => (),
+ some(scope_id) => {
root_value(cx, v1, t1, scope_id);
}
}
alt ty::get(t1).struct {
- ty::ty_box(mt) {
+ ty::ty_box(mt) => {
let body = GEPi(cx, v1, ~[0u, abi::box_field_body]);
t1 = mt.ty;
let llty = type_of(ccx, t1);
v1 = PointerCast(cx, body, T_ptr(llty));
}
- ty::ty_uniq(_) {
+ ty::ty_uniq(_) => {
let derefed = uniq::autoderef(cx, v1, t1);
t1 = derefed.t;
v1 = derefed.v;
}
- ty::ty_rptr(_, mt) {
+ ty::ty_rptr(_, mt) => {
t1 = mt.ty;
v1 = v;
}
- ty::ty_enum(did, substs) {
+ ty::ty_enum(did, substs) => {
let variants = ty::enum_variants(ccx.tcx, did);
if (*variants).len() != 1u || variants[0].args.len() != 1u {
break;
t1 = ty::subst(ccx.tcx, substs, variants[0].args[0]);
v1 = PointerCast(cx, v1, T_ptr(type_of(ccx, t1)));
}
- _ { break; }
+ _ => break
}
v1 = load_if_immediate(cx, v1, t1);
}
let join = sub_block(bcx, ~"join"), before_rhs = sub_block(bcx, ~"rhs");
alt op {
- lazy_and { CondBr(past_lhs, lhs, before_rhs.llbb, join.llbb); }
- lazy_or { CondBr(past_lhs, lhs, join.llbb, before_rhs.llbb); }
+ lazy_and => CondBr(past_lhs, lhs, before_rhs.llbb, join.llbb),
+ lazy_or => CondBr(past_lhs, lhs, join.llbb, before_rhs.llbb)
}
let {bcx: past_rhs, val: rhs} = {
do with_scope_result(before_rhs, b.info(), ~"rhs") |bcx| {
let _icx = bcx.insn_ctxt(~"trans_binary");
// User-defined operators
alt bcx.ccx().maps.method_map.find(ex.id) {
- some(origin) {
+ some(origin) => {
let fty = node_id_type(bcx, ex.callee_id);
return trans_call_inner(
bcx, ex.info(), fty,
},
arg_exprs(~[rhs]), dest);
}
- _ {}
+ _ => ()
}
// First couple cases are lazy:
alt op {
- ast::and {
+ ast::and => {
return trans_lazy_binop(bcx, lazy_and, lhs, rhs, dest);
}
- ast::or {
+ ast::or => {
return trans_lazy_binop(bcx, lazy_or, lhs, rhs, dest);
}
- _ {
+ _ => {
// Remaining cases are eager:
let lhs_res = trans_temp_expr(bcx, lhs);
let rhs_res = trans_temp_expr(lhs_res.bcx, rhs);
// context for the block, but we've already got the
// 'else' context
let else_bcx = alt els {
- some(elexpr) {
+ some(elexpr) => {
alt elexpr.node {
- ast::expr_if(_, _, _) {
+ ast::expr_if(_, _, _) => {
let elseif_blk = ast_util::block_from_expr(elexpr);
trans_block(else_cx, elseif_blk, else_dest)
}
- ast::expr_block(blk) {
+ ast::expr_block(blk) => {
trans_block(else_cx, blk, else_dest)
}
// would be nice to have a constraint on ifs
- _ { cx.tcx().sess.bug(~"strange alternative in if"); }
+ _ => cx.tcx().sess.bug(~"strange alternative in if")
}
}
- _ { else_cx }
+ _ => else_cx
};
let else_bcx = trans_block_cleanups(else_bcx, else_cx);
return join_returns(cx,
-> ValueRef {
let name = csearch::get_symbol(ccx.sess.cstore, did);
alt ty::get(t).struct {
- ty::ty_fn(_) {
+ ty::ty_fn(_) => {
let llty = type_of_fn_from_ty(ccx, t);
return get_extern_fn(ccx.externs, ccx.llmod, name,
lib::llvm::CCallConv, llty);
}
- _ {
+ _ => {
let llty = type_of(ccx, t);
return get_extern_const(ccx.externs, ccx.llmod, name, llty);
}
fn normalize_for_monomorphization(tcx: ty::ctxt, ty: ty::t) -> option<ty::t> {
// FIXME[mono] could do this recursively. is that worthwhile? (#2529)
alt ty::get(ty).struct {
- ty::ty_box(mt) {
+ ty::ty_box(mt) => {
some(ty::mk_opaque_box(tcx))
}
- ty::ty_fn(fty) {
+ ty::ty_fn(fty) => {
some(ty::mk_fn(tcx, {purity: ast::impure_fn,
proto: fty.proto,
inputs: ~[],
output: ty::mk_nil(tcx),
ret_style: ast::return_val}))
}
- ty::ty_trait(_, _) {
+ ty::ty_trait(_, _) => {
some(ty::mk_fn(tcx, {purity: ast::impure_fn,
proto: ast::proto_box,
inputs: ~[],
output: ty::mk_nil(tcx),
ret_style: ast::return_val}))
}
- ty::ty_ptr(_) { some(ty::mk_uint(tcx)) }
- _ { none }
+ ty::ty_ptr(_) => some(ty::mk_uint(tcx)),
+ _ => none
}
}
vtables: option<typeck::vtable_res>,
param_uses: option<~[type_use::type_uses]>) -> mono_id {
let precise_param_ids = alt vtables {
- some(vts) {
+ some(vts) => {
let bounds = ty::lookup_item_type(ccx.tcx, item).bounds;
let mut i = 0u;
vec::map2(*bounds, substs, |bounds, subst| {
let mut v = ~[];
for vec::each(*bounds) |bound| {
alt bound {
- ty::bound_trait(_) {
+ ty::bound_trait(_) => {
vec::push(v, impl::vtable_id(ccx, vts[i]));
i += 1u;
}
- _ {}
+ _ => ()
}
}
mono_precise(subst, if v.len() > 0u { some(v) } else { none })
})
}
- none {
+ none => {
vec::map(substs, |subst| mono_precise(subst, none))
}
};
let param_ids = alt param_uses {
- some(uses) {
+ some(uses) => {
vec::map2(precise_param_ids, uses, |id, uses| {
alt check id {
- mono_precise(_, some(_)) { id }
- mono_precise(subst, none) {
+ mono_precise(_, some(_)) => id,
+ mono_precise(subst, none) => {
if uses == 0u { mono_any }
else if uses == type_use::use_repr &&
!ty::type_needs_drop(ccx.tcx, subst) {
}
})
}
- none { precise_param_ids }
+ none => precise_param_ids
};
@{def: item, params: param_ids}
}
let mut must_cast = false;
let substs = vec::map(real_substs, |t| {
alt normalize_for_monomorphization(ccx.tcx, t) {
- some(t) { must_cast = true; t }
- none { t }
+ some(t) => { must_cast = true; t }
+ none => t
}
});
let param_uses = type_use::type_uses_for(ccx, fn_id, substs.len());
let hash_id = make_mono_id(ccx, fn_id, substs, vtables, some(param_uses));
if vec::any(hash_id.params,
- |p| alt p { mono_precise(_, _) { false } _ { true } }) {
+ |p| alt p { mono_precise(_, _) => false, _ => true }) {
must_cast = true;
}
substs.map(|s| ty_to_str(ccx.tcx, s)), hash_id];
alt ccx.monomorphized.find(hash_id) {
- some(val) {
+ some(val) => {
debug!{"leaving monomorphic fn %s",
ty::item_path_str(ccx.tcx, fn_id)};
return {val: val, must_cast: must_cast};
}
- none {}
+ none => ()
}
let tpt = ty::lookup_item_type(ccx.tcx, fn_id);
crate?)", fn_id});
// Get the path so that we can create a symbol
let (pt, name, span) = alt map_node {
- ast_map::node_item(i, pt) { (pt, i.ident, i.span) }
- ast_map::node_variant(v, enm, pt) { (pt, v.node.name, enm.span) }
- ast_map::node_method(m, _, pt) { (pt, m.ident, m.span) }
+ ast_map::node_item(i, pt) => (pt, i.ident, i.span),
+ ast_map::node_variant(v, enm, pt) => (pt, v.node.name, enm.span),
+ ast_map::node_method(m, _, pt) => (pt, m.ident, m.span),
ast_map::node_foreign_item(i, ast::foreign_abi_rust_intrinsic, pt)
- { (pt, i.ident, i.span) }
- ast_map::node_foreign_item(_, abi, _) {
+ => (pt, i.ident, i.span),
+ ast_map::node_foreign_item(_, abi, _) => {
// Foreign externs don't have to be monomorphized.
return {val: get_item_val(ccx, fn_id.node),
must_cast: true};
}
- ast_map::node_ctor(nm, _, ct, _, pt) { (pt, nm, ct.span) }
- ast_map::node_dtor(_, dtor, _, pt) {(pt, @~"drop", dtor.span)}
- ast_map::node_trait_method(*) {
+ ast_map::node_ctor(nm, _, ct, _, pt) => (pt, nm, ct.span),
+ ast_map::node_dtor(_, dtor, _, pt) => (pt, @~"drop", dtor.span),
+ ast_map::node_trait_method(*) => {
ccx.tcx.sess.bug(~"Can't monomorphize a trait method")
}
- ast_map::node_expr(*) {
+ ast_map::node_expr(*) => {
ccx.tcx.sess.bug(~"Can't monomorphize an expr")
}
- ast_map::node_export(*) {
+ ast_map::node_export(*) => {
ccx.tcx.sess.bug(~"Can't monomorphize an export")
}
- ast_map::node_arg(*) { ccx.tcx.sess.bug(~"Can't monomorphize an arg") }
- ast_map::node_block(*) {
+ ast_map::node_arg(*) => ccx.tcx.sess.bug(~"Can't monomorphize an arg"),
+ ast_map::node_block(*) => {
ccx.tcx.sess.bug(~"Can't monomorphize a block")
}
- ast_map::node_local(*) {
+ ast_map::node_local(*) => {
ccx.tcx.sess.bug(~"Can't monomorphize a local")
}
};
let psubsts = some({tys: substs, vtables: vtables, bounds: tpt.bounds});
let lldecl = alt map_node {
- ast_map::node_item(i@@{node: ast::item_fn(decl, _, body), _}, _) {
+ ast_map::node_item(i@@{node: ast::item_fn(decl, _, body), _}, _) => {
let d = mk_lldecl();
set_inline_hint_if_appr(i.attrs, d);
trans_fn(ccx, pt, decl, body, d, no_self, psubsts, fn_id.node);
d
}
- ast_map::node_item(*) {
+ ast_map::node_item(*) => {
ccx.tcx.sess.bug(~"Can't monomorphize this kind of item")
}
- ast_map::node_foreign_item(i, _, _) {
+ ast_map::node_foreign_item(i, _, _) => {
let d = mk_lldecl();
foreign::trans_intrinsic(ccx, d, i, pt, option::get(psubsts),
ref_id);
d
}
- ast_map::node_variant(v, enum_item, _) {
+ ast_map::node_variant(v, enum_item, _) => {
let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id));
let this_tv = option::get(vec::find(*tvs, |tv| {
tv.id.node == fn_id.node}));
(*tvs).len() == 1u, psubsts, d);
d
}
- ast_map::node_method(mth, impl_def_id, _) {
+ ast_map::node_method(mth, impl_def_id, _) => {
let d = mk_lldecl();
set_inline_hint_if_appr(mth.attrs, d);
let selfty = ty::node_id_to_type(ccx.tcx, mth.self_id);
impl_self(selfty), psubsts, fn_id.node);
d
}
- ast_map::node_ctor(nm, tps, ctor, parent_id, _) {
+ ast_map::node_ctor(nm, tps, ctor, parent_id, _) => {
// ctors don't have attrs, at least not right now
let d = mk_lldecl();
let tp_tys = ty::ty_params_to_tys(ccx.tcx, tps);
fn_id.node, parent_id, ctor.span);
d
}
- ast_map::node_dtor(_, dtor, _, pt) {
+ ast_map::node_dtor(_, dtor, _, pt) => {
let parent_id = alt ty::ty_to_def_id(ty::node_id_to_type(ccx.tcx,
dtor.node.self_id)) {
- some(did) { did }
- none { ccx.sess.span_bug(dtor.span, ~"Bad self ty in \
- dtor"); }
+ some(did) => did,
+ none => ccx.sess.span_bug(dtor.span, ~"Bad self ty in \
+ dtor")
};
trans_class_dtor(ccx, *pt, dtor.node.body,
dtor.node.id, psubsts, some(hash_id), parent_id)
}
// Ugh -- but this ensures any new variants won't be forgotten
- ast_map::node_expr(*) {
+ ast_map::node_expr(*) => {
ccx.tcx.sess.bug(~"Can't monomorphize an expr")
}
- ast_map::node_trait_method(*) {
+ ast_map::node_trait_method(*) => {
ccx.tcx.sess.bug(~"Can't monomorphize a trait method")
}
- ast_map::node_export(*) {
+ ast_map::node_export(*) => {
ccx.tcx.sess.bug(~"Can't monomorphize an export")
}
- ast_map::node_arg(*) { ccx.tcx.sess.bug(~"Can't monomorphize an arg") }
- ast_map::node_block(*) {
+ ast_map::node_arg(*) => ccx.tcx.sess.bug(~"Can't monomorphize an arg"),
+ ast_map::node_block(*) => {
ccx.tcx.sess.bug(~"Can't monomorphize a block")
}
- ast_map::node_local(*) {
+ ast_map::node_local(*) => {
ccx.tcx.sess.bug(~"Can't monomorphize a local")
}
};
-> ast::def_id {
let _icx = ccx.insn_ctxt(~"maybe_instantiate_inline");
alt ccx.external.find(fn_id) {
- some(some(node_id)) {
+ some(some(node_id)) => {
// Already inline
debug!{"maybe_instantiate_inline(%s): already inline as node id %d",
ty::item_path_str(ccx.tcx, fn_id), node_id};
local_def(node_id)
}
- some(none) { fn_id } // Not inlinable
- none { // Not seen yet
+ some(none) => fn_id, // Not inlinable
+ none => { // Not seen yet
alt csearch::maybe_get_item_ast(
ccx.tcx, fn_id,
|a,b,c,d| {
astencode::decode_inlined_item(a, b, ccx.maps, c, d)
}) {
- csearch::not_found {
+ csearch::not_found => {
ccx.external.insert(fn_id, none);
fn_id
}
- csearch::found(ast::ii_item(item)) {
+ csearch::found(ast::ii_item(item)) => {
ccx.external.insert(fn_id, some(item.id));
trans_item(ccx, *item);
local_def(item.id)
}
- csearch::found(ast::ii_ctor(ctor, nm, tps, parent_id)) {
+ csearch::found(ast::ii_ctor(ctor, nm, tps, parent_id)) => {
ccx.external.insert(fn_id, some(ctor.node.id));
local_def(ctor.node.id)
}
- csearch::found(ast::ii_foreign(item)) {
+ csearch::found(ast::ii_foreign(item)) => {
ccx.external.insert(fn_id, some(item.id));
local_def(item.id)
}
- csearch::found_parent(parent_id, ast::ii_item(item)) {
+ csearch::found_parent(parent_id, ast::ii_item(item)) => {
ccx.external.insert(parent_id, some(item.id));
let mut my_id = 0;
alt check item.node {
- ast::item_enum(_, _) {
+ ast::item_enum(_, _) => {
let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id));
let vs_there = ty::enum_variants(ccx.tcx, parent_id);
do vec::iter2(*vs_here, *vs_there) |here, there| {
trans_item(ccx, *item);
local_def(my_id)
}
- csearch::found_parent(_, _) {
+ csearch::found_parent(_, _) => {
ccx.sess.bug(~"maybe_get_item_ast returned a found_parent \
with a non-item parent");
}
- csearch::found(ast::ii_method(impl_did, mth)) {
+ csearch::found(ast::ii_method(impl_did, mth)) => {
ccx.external.insert(fn_id, some(mth.id));
let {bounds: impl_bnds, rp: _, ty: impl_ty} =
ty::lookup_item_type(ccx.tcx, impl_did);
}
local_def(mth.id)
}
- csearch::found(ast::ii_dtor(dtor, nm, tps, parent_id)) {
+ csearch::found(ast::ii_dtor(dtor, nm, tps, parent_id)) => {
ccx.external.insert(fn_id, some(dtor.node.id));
local_def(dtor.node.id)
}
}
alt ty::get(tpt.ty).struct {
- ty::ty_fn(fn_ty) {
+ ty::ty_fn(fn_ty) => {
alt fn_ty.purity {
- ast::extern_fn {
+ ast::extern_fn => {
// Extern functions are just opaque pointers
let val = PointerCast(bcx, val, T_ptr(T_i8()));
return lval_no_env(bcx, val, lv_owned_imm);
}
- _ { /* fall through */ }
+ _ => { /* fall through */ }
}
}
- _ { /* fall through */ }
+ _ => { /* fall through */ }
}
return {bcx: bcx, val: val, kind: lv_owned, env: null_env};
fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef {
let _icx = ccx.insn_ctxt(~"lookup_discriminant");
alt ccx.discrims.find(vid) {
- none {
+ none => {
// It's an external discriminant that we haven't seen yet.
assert (vid.crate != ast::local_crate);
let sym = csearch::get_symbol(ccx.sess.cstore, vid);
ccx.discrims.insert(vid, gvar);
return gvar;
}
- some(llval) { return llval; }
+ some(llval) => return llval,
}
}
fn take_local(table: hashmap<ast::node_id, local_val>,
id: ast::node_id) -> local_var_result {
alt table.find(id) {
- some(local_mem(v)) { {val: v, kind: lv_owned} }
- some(local_imm(v)) { {val: v, kind: lv_owned_imm} }
- r { fail(~"take_local: internal error"); }
+ some(local_mem(v)) => {val: v, kind: lv_owned},
+ some(local_imm(v)) => {val: v, kind: lv_owned_imm},
+ r => fail(~"take_local: internal error")
}
}
alt def {
- ast::def_upvar(nid, _, _) {
+ ast::def_upvar(nid, _, _) => {
assert (cx.fcx.llupvars.contains_key(nid));
return { val: cx.fcx.llupvars.get(nid), kind: lv_owned };
}
- ast::def_arg(nid, _) {
+ ast::def_arg(nid, _) => {
assert (cx.fcx.llargs.contains_key(nid));
return take_local(cx.fcx.llargs, nid);
}
- ast::def_local(nid, _) | ast::def_binding(nid, _) {
+ ast::def_local(nid, _) | ast::def_binding(nid, _) => {
assert (cx.fcx.lllocals.contains_key(nid));
return take_local(cx.fcx.lllocals, nid);
}
- ast::def_self(sid) {
+ ast::def_self(sid) => {
let slf = alt copy cx.fcx.llself {
- some(s) { cast_self(cx, s) }
- none { cx.sess().bug(~"trans_local_var: reference to self \
- out of context"); }
+ some(s) => cast_self(cx, s),
+ none => cx.sess().bug(~"trans_local_var: reference to self \
+ out of context")
};
return {val: slf, kind: lv_owned};
}
- _ {
+ _ => {
cx.sess().unimpl(fmt!{"unsupported def type in trans_local_var: %?",
def});
}
-> lval_maybe_callee {
let _icx = cx.insn_ctxt(~"trans_path");
alt cx.tcx().def_map.find(id) {
- none { cx.sess().bug(~"trans_path: unbound node ID"); }
- some(df) {
+ none => cx.sess().bug(~"trans_path: unbound node ID"),
+ some(df) => {
return trans_var(cx, df, id);
}
}
let _icx = cx.insn_ctxt(~"trans_var");
let ccx = cx.ccx();
alt def {
- ast::def_fn(did, _) {
+ ast::def_fn(did, _) => {
return lval_static_fn(cx, did, id);
}
- ast::def_variant(tid, vid) {
+ ast::def_variant(tid, vid) => {
if ty::enum_variant_with_id(ccx.tcx, tid, vid).args.len() > 0u {
// N-ary variant.
return lval_static_fn(cx, vid, id);
return lval_no_env(cx, llenumptr, lv_temporary);
}
}
- ast::def_const(did) {
+ ast::def_const(did) => {
if did.crate == ast::local_crate {
return lval_no_env(cx, get_item_val(ccx, did.node), lv_owned);
} else {
lv_owned_imm);
}
}
- _ {
+ _ => {
let loc = trans_local_var(cx, def);
return lval_no_env(cx, loc.val, loc.kind);
}
field: ast::ident, sp: span) -> lval_result {
let mut llderef = false;
let fields = alt ty::get(ty).struct {
- ty::ty_rec(fs) { fs }
- ty::ty_class(did, substs) {
+ ty::ty_rec(fs) => fs,
+ ty::ty_class(did, substs) => {
if option::is_some(ty::ty_dtor(bcx.tcx(), did)) {
llderef = true;
}
ty::class_items_as_mutable_fields(bcx.tcx(), did, substs)
}
// Constraint?
- _ { bcx.tcx().sess.span_bug(sp, ~"trans_rec_field:\
- base expr has non-record type"); }
+ _ => bcx.tcx().sess.span_bug(sp, ~"trans_rec_field:\
+ base expr has non-record type")
};
// seems wrong? Doesn't take into account the field
// sizes
fn trans_callee(bcx: block, e: @ast::expr) -> lval_maybe_callee {
let _icx = bcx.insn_ctxt(~"trans_callee");
alt e.node {
- ast::expr_path(path) { return trans_path(bcx, e.id); }
- ast::expr_field(base, _, _) {
+ ast::expr_path(path) => return trans_path(bcx, e.id),
+ ast::expr_field(base, _, _) => {
// Lval means this is a record field, so not a method
if !expr_is_lval(bcx, e) {
alt bcx.ccx().maps.method_map.find(e.id) {
- some(origin) { // An impl method
+ some(origin) => { // An impl method
return impl::trans_method_callee(bcx, e.id, base, origin);
}
- _ {
+ _ => {
bcx.ccx().sess.span_bug(e.span, ~"trans_callee: weird expr");
}
}
}
}
- _ {}
+ _ => ()
}
let lv = trans_temp_lval(bcx, e);
return lval_no_env(lv.bcx, lv.val, lv.kind);
fn trans_lval(cx: block, e: @ast::expr) -> lval_result {
return alt cx.ccx().maps.root_map.find({id:e.id, derefs:0u}) {
// No need to root this lvalue.
- none { unrooted(cx, e) }
+ none => unrooted(cx, e),
// Lvalue must remain rooted until exit of `scope_id`. See
// add_root_cleanup() for comments on why this works the way it does.
- some(scope_id) {
+ some(scope_id) => {
let lv = unrooted(cx, e);
if !cx.sess().no_asm_comments() {
fn unrooted(cx: block, e: @ast::expr) -> lval_result {
let _icx = cx.insn_ctxt(~"trans_lval");
alt e.node {
- ast::expr_path(_) {
+ ast::expr_path(_) => {
let v = trans_path(cx, e.id);
return lval_maybe_callee_to_lval(v, e.span);
}
- ast::expr_field(base, ident, _) {
+ ast::expr_field(base, ident, _) => {
return trans_rec_field(cx, base, ident);
}
- ast::expr_index(base, idx) {
+ ast::expr_index(base, idx) => {
return trans_index(cx, e, base, idx);
}
- ast::expr_unary(ast::deref, base) {
+ ast::expr_unary(ast::deref, base) => {
let ccx = cx.ccx();
let sub = trans_temp_expr(cx, base);
let t = expr_ty(cx, base);
let val = alt check ty::get(t).struct {
- ty::ty_box(_) {
+ ty::ty_box(_) => {
let non_gc_val = non_gc_box_cast(sub.bcx, sub.val);
GEPi(sub.bcx, non_gc_val, ~[0u, abi::box_field_body])
}
- ty::ty_uniq(_) {
+ ty::ty_uniq(_) => {
let non_gc_val = non_gc_box_cast(sub.bcx, sub.val);
GEPi(sub.bcx, non_gc_val, ~[0u, abi::box_field_body])
}
- ty::ty_enum(_, _) {
+ ty::ty_enum(_, _) => {
let ety = expr_ty(cx, e);
let ellty = T_ptr(type_of(ccx, ety));
PointerCast(sub.bcx, sub.val, ellty)
}
- ty::ty_ptr(_) | ty::ty_rptr(_,_) { sub.val }
+ ty::ty_ptr(_) | ty::ty_rptr(_,_) => sub.val
};
return lval_owned(sub.bcx, val);
}
- _ { cx.sess().span_bug(e.span, ~"non-lval in trans_lval"); }
+ _ => cx.sess().span_bug(e.span, ~"non-lval in trans_lval")
}
}
}
fn lval_maybe_callee_to_lval(c: lval_maybe_callee, sp: span) -> lval_result {
alt c.env {
- self_env(*) {
+ self_env(*) => {
c.bcx.sess().span_bug(sp, ~"implicitly binding method call");
}
- is_closure { {bcx: c.bcx, val: c.val, kind: c.kind} }
- null_env {
+ is_closure => { {bcx: c.bcx, val: c.val, kind: c.kind} }
+ null_env => {
let llfnty = llvm::LLVMGetElementType(val_ty(c.val));
let llfn = create_real_fn_pair(c.bcx, llfnty, c.val,
null_env_ptr(c.bcx));
cast_enum, cast_other, }
fn cast_type_kind(t: ty::t) -> cast_kind {
alt ty::get(t).struct {
- ty::ty_float(*) {cast_float}
- ty::ty_ptr(*) {cast_pointer}
- ty::ty_rptr(*) {cast_pointer}
- ty::ty_int(*) {cast_integral}
- ty::ty_uint(*) {cast_integral}
- ty::ty_bool {cast_integral}
- ty::ty_enum(*) {cast_enum}
- _ {cast_other}
+ ty::ty_float(*) => cast_float,
+ ty::ty_ptr(*) => cast_pointer,
+ ty::ty_rptr(*) => cast_pointer,
+ ty::ty_int(*) => cast_integral,
+ ty::ty_uint(*) => cast_integral,
+ ty::ty_bool => cast_integral,
+ ty::ty_enum(*) => cast_enum,
+ _ => cast_other
}
}
let ccx = cx.ccx();
let t_out = node_id_type(cx, id);
alt ty::get(t_out).struct {
- ty::ty_trait(_, _) { return impl::trans_cast(cx, e, id, dest); }
- _ {}
+ ty::ty_trait(_, _) => return impl::trans_cast(cx, e, id, dest),
+ _ => ()
}
let e_res = trans_temp_expr(cx, e);
let ll_t_in = val_ty(e_res.val);
let newval =
alt {in: k_in, out: k_out} {
- {in: cast_integral, out: cast_integral} {
+ {in: cast_integral, out: cast_integral} => {
int_cast(e_res.bcx, ll_t_out, ll_t_in, e_res.val, s_in)
}
- {in: cast_float, out: cast_float} {
+ {in: cast_float, out: cast_float} => {
float_cast(e_res.bcx, ll_t_out, ll_t_in, e_res.val)
}
- {in: cast_integral, out: cast_float} {
+ {in: cast_integral, out: cast_float} => {
if s_in {
SIToFP(e_res.bcx, e_res.val, ll_t_out)
} else { UIToFP(e_res.bcx, e_res.val, ll_t_out) }
}
- {in: cast_float, out: cast_integral} {
+ {in: cast_float, out: cast_integral} => {
if ty::type_is_signed(t_out) {
FPToSI(e_res.bcx, e_res.val, ll_t_out)
} else { FPToUI(e_res.bcx, e_res.val, ll_t_out) }
}
- {in: cast_integral, out: cast_pointer} {
+ {in: cast_integral, out: cast_pointer} => {
IntToPtr(e_res.bcx, e_res.val, ll_t_out)
}
- {in: cast_pointer, out: cast_integral} {
+ {in: cast_pointer, out: cast_integral} => {
PtrToInt(e_res.bcx, e_res.val, ll_t_out)
}
- {in: cast_pointer, out: cast_pointer} {
+ {in: cast_pointer, out: cast_pointer} => {
PointerCast(e_res.bcx, e_res.val, ll_t_out)
}
{in: cast_enum, out: cast_integral} |
- {in: cast_enum, out: cast_float} {
+ {in: cast_enum, out: cast_float} => {
let cx = e_res.bcx;
let llenumty = T_opaque_enum_ptr(ccx);
let av_enum = PointerCast(cx, e_res.val, llenumty);
let lldiscrim_a_ptr = GEPi(cx, av_enum, ~[0u, 0u]);
let lldiscrim_a = Load(cx, lldiscrim_a_ptr);
alt k_out {
- cast_integral {int_cast(e_res.bcx, ll_t_out,
- val_ty(lldiscrim_a), lldiscrim_a, true)}
- cast_float {SIToFP(e_res.bcx, lldiscrim_a, ll_t_out)}
- _ { ccx.sess.bug(~"translating unsupported cast.") }
+ cast_integral => int_cast(e_res.bcx, ll_t_out,
+ val_ty(lldiscrim_a),
+ lldiscrim_a, true),
+ cast_float => SIToFP(e_res.bcx, lldiscrim_a, ll_t_out),
+ _ => ccx.sess.bug(~"translating unsupported cast.")
}
}
- _ { ccx.sess.bug(~"translating unsupported cast.") }
+ _ => ccx.sess.bug(~"translating unsupported cast.")
};
return store_in_dest(e_res.bcx, newval, dest);
}
fn trans_loop_body(bcx: block, e: @ast::expr, ret_flag: option<ValueRef>,
dest: dest) -> block {
alt check e.node {
- ast::expr_loop_body(b@@{node: ast::expr_fn_block(decl, body, cap), _}) {
+ ast::expr_loop_body(b@@{
+ node: ast::expr_fn_block(decl, body, cap),
+ _
+ }) => {
alt check ty::get(expr_ty(bcx, e)).struct {
- ty::ty_fn({proto, _}) {
+ ty::ty_fn({proto, _}) => {
closure::trans_expr_fn(bcx, proto, decl, body, b.id,
cap, some(ret_flag),
dest)
// translate the arg expr as an lvalue
let lv = alt ret_flag {
// If there is a ret_flag, this *must* be a loop body
- some(ptr) {
- alt check e.node {
- ast::expr_loop_body(blk) {
+ some(ptr) => alt check e.node {
+ ast::expr_loop_body(blk) => {
let scratch = alloc_ty(cx, expr_ty(cx, blk));
let bcx = trans_loop_body(cx, e, ret_flag, save_in(scratch));
{bcx: bcx, val: scratch, kind: lv_temporary}
- }
}
}
- none {
+ none => {
trans_temp_lval(cx, e)
}
};
val = llvm::LLVMGetUndef(lldestty);
} else {
alt arg_mode {
- ast::by_ref | ast::by_mutbl_ref {
+ ast::by_ref | ast::by_mutbl_ref => {
// Ensure that the value is spilled into memory:
if lv.kind != lv_owned && ty::type_is_immediate(e_ty) {
val = do_spill_noroot(bcx, val);
}
}
- ast::by_val {
+ ast::by_val => {
// Ensure that the value is not spilled into memory:
if lv.kind == lv_owned || !ty::type_is_immediate(e_ty) {
val = Load(bcx, val);
}
}
- ast::by_copy | ast::by_move {
+ ast::by_copy | ast::by_move => {
// Ensure that an owned copy of the value is in memory:
let alloc = alloc_ty(bcx, arg.ty);
let move_out = arg_mode == ast::by_move ||
}
alt ty::get(e_ty).struct {
- ty::ty_uniq(mt) | ty::ty_box(mt) {
+ ty::ty_uniq(mt) | ty::ty_box(mt) => {
let box_ptr = load_value_from_lval_result(lv, e_ty);
let body_ptr = GEPi(bcx, box_ptr, ~[0u, abi::box_field_body]);
let rptr_ty = ty::mk_rptr(bcx.tcx(), ty::re_static, mt);
return {lv: lval_temp(bcx, body_ptr), ty: rptr_ty};
}
- ty::ty_estr(_) | ty::ty_evec(_, _) {
+ ty::ty_estr(_) | ty::ty_evec(_, _) => {
let ccx = bcx.ccx();
let val = alt lv.kind {
- lv_temporary { lv.val }
- lv_owned { load_if_immediate(bcx, lv.val, e_ty) }
- lv_owned_imm { lv.val }
+ lv_temporary => lv.val,
+ lv_owned => load_if_immediate(bcx, lv.val, e_ty),
+ lv_owned_imm => lv.val
};
let unit_ty = ty::sequence_element_type(ccx.tcx, e_ty);
return {lv: lval_temp(bcx, p), ty: slice_ty};
}
- _ {
+ _ => {
bcx.tcx().sess.span_bug(
e.span, fmt!{"cannot borrow a value of type %s",
ppaux::ty_to_str(bcx.tcx(), e_ty)});
let retty = ty::ty_fn_ret(fn_ty);
// Arg 0: Output pointer.
let llretslot = alt dest {
- ignore {
+ ignore => {
if ty::type_is_nil(retty) {
llvm::LLVMGetUndef(T_ptr(T_nil()))
} else { alloc_ty(bcx, retty) }
}
- save_in(dst) { dst }
- by_val(_) { alloc_ty(bcx, retty) }
+ save_in(dst) => dst,
+ by_val(_) => alloc_ty(bcx, retty)
};
vec::push(llargs, llretslot);
// This will be needed if this is a generic call, because the callee has
// to cast her view of the arguments to the caller's view.
alt args {
- arg_exprs(es) {
+ arg_exprs(es) => {
let llarg_tys = type_of_explicit_args(ccx, arg_tys);
let last = es.len() - 1u;
do vec::iteri(es) |i, e| {
vec::push(llargs, r.val);
}
}
- arg_vals(vs) {
+ arg_vals(vs) => {
vec::push_all(llargs, vs);
}
}
visit_expr: |e: @ast::expr, cx: {mut found: bool}, v| {
if !cx.found {
alt e.node {
- ast::expr_ret(_) { cx.found = true; }
- _ { visit::visit_expr(e, cx, v); }
+ ast::expr_ret(_) => cx.found = true,
+ _ => visit::visit_expr(e, cx, v),
}
}
} with *visit::default_visitor()
do with_scope(in_cx, call_info, ~"call") |cx| {
let ret_in_loop = alt args {
- arg_exprs(args) { args.len() > 0u && alt vec::last(args).node {
- ast::expr_loop_body(@{node: ast::expr_fn_block(_, body, _), _}) {
- body_contains_ret(body)
+ arg_exprs(args) => {
+ args.len() > 0u && alt vec::last(args).node {
+ ast::expr_loop_body(@{
+ node: ast::expr_fn_block(_, body, _),
+ _
+ }) => body_contains_ret(body),
+ _ => false
}
- _ { false }
- } }
- _ { false }
+ }
+ _ => false
};
let f_res = get_callee(cx);
let mut faddr = f_res.val;
let llenv = alt f_res.env {
- null_env {
+ null_env => {
llvm::LLVMGetUndef(T_opaque_box_ptr(ccx))
}
- self_env(e, _, _) {
+ self_env(e, _, _) => {
PointerCast(bcx, e, T_opaque_box_ptr(ccx))
}
- is_closure {
+ is_closure => {
// It's a closure. Have to fetch the elements
if f_res.kind == lv_owned {
faddr = load_if_immediate(bcx, faddr, fn_expr_ty);
for the call itself is unreachable. */
bcx = invoke(bcx, faddr, llargs);
alt dest {
- ignore {
+ ignore => {
if llvm::LLVMIsUndef(llretslot) != lib::llvm::True {
bcx = drop_ty(bcx, llretslot, ret_ty);
}
}
- save_in(_) { } // Already saved by callee
- by_val(cell) {
+ save_in(_) => { } // Already saved by callee
+ by_val(cell) => {
*cell = Load(bcx, llretslot);
}
}
let mut cur = bcx;
loop {
alt cur.kind {
- block_scope(inf) {
+ block_scope(inf) => {
for vec::each(inf.cleanups) |cleanup| {
alt cleanup {
- clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) {
+ clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) => {
if cleanup_type == normal_exit_and_unwind {
return true;
}
}
}
}
- _ { }
+ _ => ()
}
cur = alt cur.parent {
- some(next) { next }
- none { return false; }
+ some(next) => next,
+ none => return false
}
}
}
let mut res = false;
do in_lpad_scope_cx(bcx) |inf| {
alt inf.landing_pad {
- some(_) { res = true; }
- none { res = false; }
+ some(_) => res = true,
+ none => res = false
}
}
return res;
let mut bcx = bcx;
loop {
alt bcx.kind {
- block_scope(inf) {
+ block_scope(inf) => {
if inf.cleanups.len() > 0u || is_none(bcx.parent) {
f(inf); return;
}
}
- _ {}
+ _ => ()
}
bcx = block_parent(bcx);
}
do in_lpad_scope_cx(bcx) |inf| {
// If there is a valid landing pad still around, use it
alt copy inf.landing_pad {
- some(target) { cached = some(target); }
- none {
+ some(target) => cached = some(target),
+ none => {
pad_bcx = lpad_block(bcx, ~"unwind");
inf.landing_pad = some(pad_bcx.llbb);
}
}
}
// Can't return from block above
- alt cached { some(b) { return b; } none {} }
+ alt cached { some(b) => return b, none => () }
// The landing pad return type (the type being propagated). Not sure what
// this represents but it's determined by the personality function and
// this is what the EH proposal example uses.
// We store the retval in a function-central alloca, so that calls to
// Resume can find it.
alt copy bcx.fcx.personality {
- some(addr) { Store(pad_bcx, llretval, addr); }
- none {
+ some(addr) => Store(pad_bcx, llretval, addr),
+ none => {
let addr = alloca(pad_bcx, val_ty(llretval));
bcx.fcx.personality = some(addr);
Store(pad_bcx, llretval, addr);
let _icx = bcx.insn_ctxt(~"trans_tup");
let mut bcx = bcx;
let addr = alt dest {
- ignore {
+ ignore => {
for vec::each(elts) |ex| { bcx = trans_expr(bcx, ex, ignore); }
return bcx;
}
- save_in(pos) { pos }
- _ { bcx.tcx().sess.bug(~"trans_tup: weird dest"); }
+ save_in(pos) => pos,
+ _ => bcx.tcx().sess.bug(~"trans_tup: weird dest")
};
let mut temp_cleanups = ~[];
for vec::eachi(elts) |i, e| {
let t = node_id_type(bcx, id);
let mut bcx = bcx;
let addr = alt check dest {
- ignore {
+ ignore => {
for vec::each(fields) |fld| {
bcx = trans_expr(bcx, fld.node.expr, ignore);
}
return bcx;
}
- save_in(pos) { pos }
+ save_in(pos) => pos
};
- let ty_fields = alt check ty::get(t).struct { ty::ty_rec(f) { f } };
+ let ty_fields = alt check ty::get(t).struct { ty::ty_rec(f) => f };
let mut temp_cleanups = ~[];
for fields.each |fld| {
vec::push(temp_cleanups, dst);
}
alt base {
- some(bexp) {
+ some(bexp) => {
let {bcx: cx, val: base_val} = trans_temp_expr(bcx, bexp);
bcx = cx;
// Copy over inherited fields
}
}
}
- none {}
+ none => ()
};
// Now revoke the cleanups as we pass responsibility for the data
fn load_value_from_lval_result(lv: lval_result, ty: ty::t) -> ValueRef {
alt lv.kind {
- lv_temporary { lv.val }
- lv_owned { load_if_immediate(lv.bcx, lv.val, ty) }
- lv_owned_imm { lv.val }
+ lv_temporary => lv.val,
+ lv_owned => load_if_immediate(lv.bcx, lv.val, ty),
+ lv_owned_imm => lv.val
}
}
let mut bcx_sid = bcx;
loop {
bcx_sid = alt bcx_sid.node_info {
- some({id, _}) if id == scope_id { return bcx_sid; }
- _ {
+ some({id, _}) if id == scope_id => {
+ return bcx_sid
+ }
+ _ => {
alt bcx_sid.parent {
- none {
- bcx.tcx().sess.bug(
- fmt!{"no enclosing scope with id %d", scope_id});
- }
- some(bcx_par) { bcx_par }
+ none => bcx.tcx().sess.bug(
+ fmt!{"no enclosing scope with id %d", scope_id}),
+ some(bcx_par) => bcx_par
}
}
}
}
return alt bcx.ccx().maps.root_map.find({id:e.id, derefs:0u}) {
- none { unrooted(bcx, e, dest) }
- some(scope_id) {
+ none => unrooted(bcx, e, dest),
+ some(scope_id) => {
debug!{"expression %d found in root map with scope %d",
e.id, scope_id};
fn unrooted(bcx: block, e: @ast::expr, dest: dest) -> block {
let tcx = bcx.tcx();
alt e.node {
- ast::expr_if(cond, thn, els) {
+ ast::expr_if(cond, thn, els) => {
return trans_if(bcx, cond, thn, els, dest);
}
- ast::expr_alt(expr, arms, mode) {
+ ast::expr_alt(expr, arms, mode) => {
return alt::trans_alt(bcx, e, expr, arms, mode, dest);
}
- ast::expr_block(blk) {
+ ast::expr_block(blk) => {
return do with_scope(bcx, blk.info(), ~"block-expr body") |bcx| {
trans_block(bcx, blk, dest)
};
}
- ast::expr_rec(args, base) {
+ ast::expr_rec(args, base) => {
return trans_rec(bcx, args, base, e.id, dest);
}
- ast::expr_struct(_, fields) {
+ ast::expr_struct(_, fields) => {
return trans_struct(bcx, e.span, fields, e.id, dest);
}
- ast::expr_tup(args) { return trans_tup(bcx, args, dest); }
- ast::expr_vstore(e, v) {
+ ast::expr_tup(args) => { return trans_tup(bcx, args, dest); }
+ ast::expr_vstore(e, v) => {
return tvec::trans_vstore(bcx, e, v, dest);
}
- ast::expr_lit(lit) { return trans_lit(bcx, e, *lit, dest); }
- ast::expr_vec(args, _) {
+ ast::expr_lit(lit) => return trans_lit(bcx, e, *lit, dest),
+ ast::expr_vec(args, _) => {
return tvec::trans_evec(bcx, tvec::individual_evec(args),
ast::vstore_fixed(none), e.id, dest);
}
- ast::expr_repeat(element, count_expr, _) {
+ ast::expr_repeat(element, count_expr, _) => {
let count = ty::eval_repeat_count(bcx.tcx(), count_expr, e.span);
return tvec::trans_evec(bcx, tvec::repeating_evec(element, count),
ast::vstore_fixed(none), e.id, dest);
}
- ast::expr_binary(op, lhs, rhs) {
+ ast::expr_binary(op, lhs, rhs) => {
return trans_binary(bcx, op, lhs, rhs, dest, e);
}
- ast::expr_unary(op, x) {
+ ast::expr_unary(op, x) => {
assert op != ast::deref; // lvals are handled above
return trans_unary(bcx, op, x, e, dest);
}
- ast::expr_addr_of(_, x) { return trans_addr_of(bcx, x, dest); }
- ast::expr_fn(proto, decl, body, cap_clause) {
+ ast::expr_addr_of(_, x) => { return trans_addr_of(bcx, x, dest); }
+ ast::expr_fn(proto, decl, body, cap_clause) => {
return closure::trans_expr_fn(bcx, proto, decl, body, e.id,
cap_clause, none, dest);
}
- ast::expr_fn_block(decl, body, cap_clause) {
+ ast::expr_fn_block(decl, body, cap_clause) => {
alt check ty::get(expr_ty(bcx, e)).struct {
- ty::ty_fn({proto, _}) {
+ ty::ty_fn({proto, _}) => {
debug!{"translating fn_block %s with type %s",
expr_to_str(e),
ppaux::ty_to_str(tcx, expr_ty(bcx, e))};
}
}
}
- ast::expr_loop_body(blk) {
+ ast::expr_loop_body(blk) => {
return trans_loop_body(bcx, e, none, dest);
}
- ast::expr_do_body(blk) {
+ ast::expr_do_body(blk) => {
return trans_expr(bcx, blk, dest);
}
- ast::expr_copy(a) | ast::expr_unary_move(a) {
+ ast::expr_copy(a) | ast::expr_unary_move(a) => {
if !expr_is_lval(bcx, a) {
return trans_expr(bcx, a, dest);
}
else { return lval_to_dps(bcx, a, dest); }
}
- ast::expr_cast(val, _) { return trans_cast(bcx, val, e.id, dest); }
- ast::expr_call(f, args, _) {
+ ast::expr_cast(val, _) => return trans_cast(bcx, val, e.id, dest),
+ ast::expr_call(f, args, _) => {
return trans_call(bcx, e, f, arg_exprs(args), e.id, dest);
}
- ast::expr_field(base, _, _) {
+ ast::expr_field(base, _, _) => {
if dest == ignore { return trans_expr(bcx, base, ignore); }
let callee = trans_callee(bcx, e), ty = expr_ty(bcx, e);
let lv = lval_maybe_callee_to_lval(callee, e.span);
memmove_ty(lv.bcx, get_dest_addr(dest), lv.val, ty);
return lv.bcx;
}
- ast::expr_index(base, idx) {
+ ast::expr_index(base, idx) => {
// If it is here, it's not an lval, so this is a user-defined
// index op
let origin = bcx.ccx().maps.method_map.get(e.id);
}
// These return nothing
- ast::expr_break {
+ ast::expr_break => {
assert dest == ignore;
return trans_break(bcx);
}
- ast::expr_again {
+ ast::expr_again => {
assert dest == ignore;
return trans_cont(bcx);
}
- ast::expr_ret(ex) {
+ ast::expr_ret(ex) => {
assert dest == ignore;
return trans_ret(bcx, ex);
}
- ast::expr_fail(expr) {
+ ast::expr_fail(expr) => {
assert dest == ignore;
return trans_fail_expr(bcx, some(e.span), expr);
}
- ast::expr_log(_, lvl, a) {
+ ast::expr_log(_, lvl, a) => {
assert dest == ignore;
return trans_log(e, lvl, bcx, a);
}
- ast::expr_assert(a) {
+ ast::expr_assert(a) => {
assert dest == ignore;
return trans_check_expr(bcx, e, a, ~"Assertion");
}
- ast::expr_while(cond, body) {
+ ast::expr_while(cond, body) => {
assert dest == ignore;
return trans_while(bcx, cond, body);
}
- ast::expr_loop(body) {
+ ast::expr_loop(body) => {
assert dest == ignore;
return trans_loop(bcx, body);
}
- ast::expr_assign(dst, src) {
+ ast::expr_assign(dst, src) => {
assert dest == ignore;
let src_r = trans_temp_lval(bcx, src);
let {bcx, val: addr, kind} = trans_lval(src_r.bcx, dst);
return store_temp_expr(bcx, DROP_EXISTING, addr, src_r,
expr_ty(bcx, src), is_last_use);
}
- ast::expr_move(dst, src) {
+ ast::expr_move(dst, src) => {
// FIXME: calculate copy init-ness in typestate. (#839)
assert dest == ignore;
let src_r = trans_temp_lval(bcx, src);
return move_val(bcx, DROP_EXISTING, addr, src_r,
expr_ty(bcx, src));
}
- ast::expr_swap(dst, src) {
+ ast::expr_swap(dst, src) => {
assert dest == ignore;
let lhs_res = trans_lval(bcx, dst);
assert lhs_res.kind == lv_owned;
return move_val(bcx, INIT, rhs_res.val,
lval_owned(bcx, tmp_alloc), t);
}
- ast::expr_assign_op(op, dst, src) {
+ ast::expr_assign_op(op, dst, src) => {
assert dest == ignore;
return trans_assign_op(bcx, e, op, dst, src);
}
- _ {
+ _ => {
bcx.tcx().sess.span_bug(e.span, ~"trans_expr reached \
fall-through case");
}
let mut {bcx, val, kind} = lv;
let ccx = bcx.ccx();
alt dest {
- by_val(cell) {
+ by_val(cell) => {
if kind == lv_temporary {
revoke_clean(bcx, val);
*cell = val;
bcx = cx;
}
}
- save_in(loc) {
+ save_in(loc) => {
bcx = store_temp_expr(bcx, INIT, loc, lv, ty, last_use);
}
- ignore {}
+ ignore => ()
}
return bcx;
}
let modpath = vec::append(
~[path_mod(ccx.link_meta.name)],
vec::filter(bcx.fcx.path, |e|
- alt e { path_mod(_) { true } _ { false } }
+ alt e { path_mod(_) => true, _ => false }
));
let modname = path_str(modpath);
let _icx = bcx.insn_ctxt(~"trans_fail_expr");
let mut bcx = bcx;
alt fail_expr {
- some(expr) {
+ some(expr) => {
let ccx = bcx.ccx(), tcx = ccx.tcx;
let expr_res = trans_temp_expr(bcx, expr);
let e_ty = expr_ty(bcx, expr);
ppaux::ty_to_str(tcx, e_ty));
}
}
- _ { return trans_fail(bcx, sp_opt, ~"explicit failure"); }
+ _ => return trans_fail(bcx, sp_opt, ~"explicit failure")
}
}
add_comment(bcx, trace_str);
let V_trace_str = C_cstr(bcx.ccx(), trace_str);
let {V_filename, V_line} = alt sp_opt {
- some(sp) {
+ some(sp) => {
let sess = bcx.sess();
let loc = codemap::lookup_char_pos(sess.parse_sess.cm, sp.lo);
{V_filename: C_cstr(bcx.ccx(), loc.file.name),
V_line: loc.line as int}
}
- none {
+ none => {
{V_filename: C_cstr(bcx.ccx(), ~"<runtime>"),
V_line: 0}
}
let _icx = bcx.insn_ctxt(~"trans_fail_value");
let ccx = bcx.ccx();
let {V_filename, V_line} = alt sp_opt {
- some(sp) {
+ some(sp) => {
let sess = bcx.sess();
let loc = codemap::lookup_char_pos(sess.parse_sess.cm, sp.lo);
{V_filename: C_cstr(bcx.ccx(), loc.file.name),
V_line: loc.line as int}
}
- none {
+ none => {
{V_filename: C_cstr(bcx.ccx(), ~"<runtime>"),
V_line: 0}
}
let mut target;
loop {
alt unwind.kind {
- block_scope({loop_break: some(brk), _}) {
+ block_scope({loop_break: some(brk), _}) => {
target = if to_end {
brk
} else {
};
break;
}
- _ {}
+ _ => ()
}
unwind = alt unwind.parent {
- some(cx) { cx }
+ some(cx) => cx,
// This is a return from a loop body block
- none {
+ none => {
Store(bcx, C_bool(!to_end), bcx.fcx.llretptr);
cleanup_and_leave(bcx, none, some(bcx.fcx.llreturn));
Unreachable(bcx);
let _icx = bcx.insn_ctxt(~"trans_ret");
let mut bcx = bcx;
let retptr = alt copy bcx.fcx.loop_ret {
- some({flagptr, retptr}) {
+ some({flagptr, retptr}) => {
// This is a loop body return. Must set continue flag (our retptr)
// to false, return flag to true, and then store the value in the
// parent's retptr.
Store(bcx, C_bool(true), flagptr);
Store(bcx, C_bool(false), bcx.fcx.llretptr);
alt e {
- some(x) { PointerCast(bcx, retptr,
- T_ptr(type_of(bcx.ccx(), expr_ty(bcx, x)))) }
- none { retptr }
+ some(x) => PointerCast(bcx, retptr,
+ T_ptr(type_of(bcx.ccx(), expr_ty(bcx, x)))),
+ none => retptr
}
}
- none { bcx.fcx.llretptr }
+ none => bcx.fcx.llretptr
};
alt e {
- some(x) {
+ some(x) => {
bcx = trans_expr_save_in(bcx, x, retptr);
}
- _ {}
+ _ => ()
}
cleanup_and_leave(bcx, none, some(bcx.fcx.llreturn));
Unreachable(bcx);
let _icx = bcx.insn_ctxt(~"init_local");
let ty = node_id_type(bcx, local.node.id);
let llptr = alt bcx.fcx.lllocals.find(local.node.id) {
- some(local_mem(v)) { v }
- _ { bcx.tcx().sess.span_bug(local.span,
+ some(local_mem(v)) => v,
+ _ => { bcx.tcx().sess.span_bug(local.span,
~"init_local: Someone forgot to document why it's\
safe to assume local.node.init must be local_mem!");
}
let mut bcx = bcx;
alt local.node.init {
- some(init) {
+ some(init) => {
if init.op == ast::init_assign || !expr_is_lval(bcx, init.expr) {
bcx = trans_expr_save_in(bcx, init.expr, llptr);
} else { // This is a move from an lval, must perform an actual move
bcx = move_val(sub.bcx, INIT, llptr, sub, ty);
}
}
- _ { bcx = zero_mem(bcx, llptr, ty); }
+ _ => bcx = zero_mem(bcx, llptr, ty),
}
// Make a note to drop this slot on the way out.
add_clean(bcx, llptr, ty);
debuginfo::update_source_pos(cx, s.span);
alt s.node {
- ast::stmt_expr(e, _) | ast::stmt_semi(e, _) {
+ ast::stmt_expr(e, _) | ast::stmt_semi(e, _) => {
bcx = trans_expr(cx, e, ignore);
}
- ast::stmt_decl(d, _) {
+ ast::stmt_decl(d, _) => {
alt d.node {
- ast::decl_local(locals) {
+ ast::decl_local(locals) => {
for vec::each(locals) |local| {
bcx = init_local(bcx, local);
if cx.sess().opts.extra_debuginfo {
}
}
}
- ast::decl_item(i) { trans_item(cx.fcx.ccx, *i); }
+ ast::decl_item(i) => trans_item(cx.fcx.ccx, *i)
}
}
}
if bcx.unreachable { return bcx; }
let mut bcx = bcx;
alt check cleanup_cx.kind {
- block_scope({cleanups, _}) {
+ block_scope({cleanups, _}) => {
let cleanups = copy cleanups;
do vec::riter(cleanups) |cu| {
alt cu {
- clean(cfn, cleanup_type) | clean_temp(_, cfn, cleanup_type) {
+ clean(cfn, cleanup_type) | clean_temp(_, cfn, cleanup_type) => {
// Some types don't need to be cleaned up during
// landing pads because they can be freed en mass later
if cleanup_type == normal_exit_and_unwind || !is_lpad {
}
alt cur.kind {
- block_scope(inf) if inf.cleanups.len() > 0u {
+ block_scope(inf) if inf.cleanups.len() > 0u => {
for vec::find(inf.cleanup_paths,
|cp| cp.target == leave).each |cp| {
Br(bcx, cp.dest);
vec::push(inf.cleanup_paths, {target: leave, dest: sub_cx.llbb});
bcx = trans_block_cleanups_(sub_cx, cur, is_lpad);
}
- _ {}
+ _ => ()
}
alt upto {
- some(bb) { if cur.llbb == bb { break; } }
- _ {}
+ some(bb) => { if cur.llbb == bb { break; } }
+ _ => ()
}
cur = alt cur.parent {
- some(next) { next }
- none { assert is_none(upto); break; }
+ some(next) => next,
+ none => { assert is_none(upto); break; }
};
}
alt leave {
- some(target) { Br(bcx, target); }
- none { Resume(bcx, Load(bcx, option::get(bcx.fcx.personality))); }
+ some(target) => Br(bcx, target),
+ none => { Resume(bcx, Load(bcx, option::get(bcx.fcx.personality))); }
}
}
fn block_locals(b: ast::blk, it: fn(@ast::local)) {
for vec::each(b.node.stmts) |s| {
alt s.node {
- ast::stmt_decl(d, _) {
+ ast::stmt_decl(d, _) => {
alt d.node {
- ast::decl_local(locals) {
+ ast::decl_local(locals) => {
for vec::each(locals) |local| { it(local); }
}
- _ {/* fall through */ }
+ _ => {/* fall through */ }
}
}
- _ {/* fall through */ }
+ _ => {/* fall through */ }
}
}
}
let _icx = cx.insn_ctxt(~"alloc_local");
let t = node_id_type(cx, local.node.id);
let simple_name = alt local.node.pat.node {
- ast::pat_ident(_, pth, none) { some(path_to_ident(pth)) }
- _ { none }
+ ast::pat_ident(_, pth, none) => some(path_to_ident(pth)),
+ _ => none
};
let val = alloc_ty(cx, t);
if cx.sess().opts.debuginfo {
bcx = trans_stmt(bcx, *s);
}
alt b.node.expr {
- some(e) {
+ some(e) => {
let bt = ty::type_is_bot(expr_ty(bcx, e));
debuginfo::update_source_pos(bcx, e.span);
bcx = trans_expr(bcx, e, if bt { ignore } else { dest });
}
- _ { assert dest == ignore || bcx.unreachable; }
+ _ => assert dest == ignore || bcx.unreachable
}
return bcx;
}
// Skip the implicit arguments 0, and 1.
let mut arg_n = first_real_arg;
alt ty_self {
- impl_self(tt) {
+ impl_self(tt) => {
cx.llself = some({v: cx.llenv, t: tt});
}
- no_self {}
+ no_self => ()
}
// Populate the llargs field of the function context with the ValueRefs
};
for vec::each(arg_tys) |arg| {
let id = args[arg_n].id;
- let argval = alt fcx.llargs.get(id) { local_mem(v) { v }
- _ { epic_fail() } };
+ let argval = alt fcx.llargs.get(id) {
+ local_mem(v) => v,
+ _ => epic_fail()
+ };
alt ty::resolved_mode(tcx, arg.mode) {
- ast::by_mutbl_ref { }
- ast::by_move | ast::by_copy { add_clean(bcx, argval, arg.ty); }
- ast::by_val {
+ ast::by_mutbl_ref => (),
+ ast::by_move | ast::by_copy => add_clean(bcx, argval, arg.ty),
+ ast::by_val => {
if !ty::type_is_immediate(arg.ty) {
let alloc = alloc_ty(bcx, arg.ty);
Store(bcx, argval, alloc);
fcx.llargs.insert(id, local_imm(argval));
}
}
- ast::by_ref {}
+ ast::by_ref => ()
}
if fcx.ccx.sess.opts.extra_debuginfo {
debuginfo::create_arg(bcx, args[arg_n], args[arg_n].ty.span);
param_substs, none);
create_llargs_for_fn_args(fcx, no_self, fn_args);
let ty_param_substs = alt param_substs {
- some(substs) { substs.tys }
- none { ~[] }
+ some(substs) => substs.tys,
+ none => ~[]
};
let bcx = top_scope_block(fcx, none), lltop = bcx.llbb;
let arg_tys = ty::ty_fn_args(node_id_type(bcx, variant.node.id));
// this function as an opaque blob due to the way that type_of()
// works. So we have to cast to the destination's view of the type.
let llarg = alt check fcx.llargs.find(va.id) {
- some(local_mem(x)) { x }
+ some(local_mem(x)) => x
};
let arg_ty = arg_tys[i].ty;
memmove_ty(bcx, lldestptr, llarg, arg_ty);
fn trans_item(ccx: @crate_ctxt, item: ast::item) {
let _icx = ccx.insn_ctxt(~"trans_item");
let path = alt check ccx.tcx.items.get(item.id) {
- ast_map::node_item(_, p) { p }
+ ast_map::node_item(_, p) => p
};
alt item.node {
- ast::item_fn(decl, tps, body) {
+ ast::item_fn(decl, tps, body) => {
if decl.purity == ast::extern_fn {
let llfndecl = get_item_val(ccx, item.id);
foreign::trans_foreign_fn(ccx,
} else {
for vec::each(body.node.stmts) |stmt| {
alt stmt.node {
- ast::stmt_decl(@{node: ast::decl_item(i), _}, _) {
+ ast::stmt_decl(@{node: ast::decl_item(i), _}, _) => {
trans_item(ccx, *i);
}
- _ {}
+ _ => ()
}
}
}
}
- ast::item_impl(tps, _, _, ms) {
+ ast::item_impl(tps, _, _, ms) => {
impl::trans_impl(ccx, *path, item.ident, ms, tps);
}
- ast::item_mod(m) {
+ ast::item_mod(m) => {
trans_mod(ccx, m);
}
- ast::item_enum(variants, tps) {
+ ast::item_enum(variants, tps) => {
if tps.len() == 0u {
let degen = variants.len() == 1u;
let vi = ty::enum_variants(ccx.tcx, local_def(item.id));
}
}
}
- ast::item_const(_, expr) { consts::trans_const(ccx, expr, item.id); }
- ast::item_foreign_mod(foreign_mod) {
+ ast::item_const(_, expr) => consts::trans_const(ccx, expr, item.id),
+ ast::item_foreign_mod(foreign_mod) => {
let abi = alt attr::foreign_abi(item.attrs) {
- either::right(abi_) { abi_ }
- either::left(msg) { ccx.sess.span_fatal(item.span, msg) }
+ either::right(abi_) => abi_,
+ either::left(msg) => ccx.sess.span_fatal(item.span, msg)
};
foreign::trans_foreign_mod(ccx, foreign_mod, abi);
}
- ast::item_class(tps, _traits, items, m_ctor, m_dtor) {
+ ast::item_class(tps, _traits, items, m_ctor, m_dtor) => {
if tps.len() == 0u {
let psubsts = {tys: ty::ty_params_to_tys(ccx.tcx, tps),
vtables: none,
let (_, ms) = ast_util::split_class_items(items);
impl::trans_impl(ccx, *path, item.ident, ms, tps);
}
- _ {/* fall through */ }
+ _ => {/* fall through */ }
}
}
let main_takes_argv =
// invariant!
alt ty::get(main_node_type).struct {
- ty::ty_fn({inputs, _}) { inputs.len() != 0u }
- _ { ccx.sess.span_fatal(sp, ~"main has a non-function type"); }
+ ty::ty_fn({inputs, _}) => inputs.len() != 0u,
+ _ => ccx.sess.span_fatal(sp, ~"main has a non-function type")
};
let llfn = create_main(ccx, main_llfn, main_takes_argv);
fn item_path(ccx: @crate_ctxt, i: @ast::item) -> path {
vec::append(
*alt check ccx.tcx.items.get(i.id) {
- ast_map::node_item(_, p) { p }
+ ast_map::node_item(_, p) => p
},
~[path_name(i.ident)])
}
substs: option<param_substs>) -> ~str {
let t = ty::node_id_to_type(ccx.tcx, id);
alt ccx.item_symbols.find(id) {
- some(s) { s }
- none if is_none(substs) {
+ some(s) => s,
+ none if is_none(substs) => {
let s = mangle_exported_name(
ccx,
vec::append(path, ~[path_name(@ccx.names(~"dtor"))]),
ccx.item_symbols.insert(id, s);
s
}
- none {
+ none => {
// Monomorphizing, so just make a symbol, don't add
// this to item_symbols
alt substs {
- some(ss) {
+ some(ss) => {
let mono_ty = ty::subst_tps(ccx.tcx, ss.tys, t);
mangle_exported_name(
ccx,
~[path_name(@ccx.names(~"dtor"))]),
mono_ty)
}
- none {
+ none => {
ccx.sess.bug(fmt!{"get_dtor_symbol: not monomorphizing and \
couldn't find a symbol for dtor %?", path});
}
fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
let tcx = ccx.tcx;
alt ccx.item_vals.find(id) {
- some(v) { v }
- none {
+ some(v) => v,
+ none => {
let mut exprt = false;
let val = alt check ccx.tcx.items.get(id) {
- ast_map::node_item(i, pth) {
+ ast_map::node_item(i, pth) => {
let my_path = vec::append(*pth, ~[path_name(i.ident)]);
alt check i.node {
- ast::item_const(_, _) {
+ ast::item_const(_, _) => {
let typ = ty::node_id_to_type(ccx.tcx, i.id);
let s = mangle_exported_name(ccx, my_path, typ);
let g = str::as_c_str(s, |buf| {
ccx.item_symbols.insert(i.id, s);
g
}
- ast::item_fn(decl, _, _) {
+ ast::item_fn(decl, _, _) => {
let llfn = if decl.purity != ast::extern_fn {
register_fn(ccx, i.span, my_path, i.id)
} else {
}
}
}
- ast_map::node_method(m, impl_id, pth) {
+ ast_map::node_method(m, impl_id, pth) => {
exprt = true;
let mty = ty::node_id_to_type(ccx.tcx, id);
let pth = vec::append(*pth, ~[path_name(@ccx.names(~"meth")),
set_inline_hint_if_appr(m.attrs, llfn);
llfn
}
- ast_map::node_foreign_item(ni, _, pth) {
+ ast_map::node_foreign_item(ni, _, pth) => {
exprt = true;
register_fn(ccx, ni.span,
vec::append(*pth, ~[path_name(ni.ident)]),
ni.id)
}
- ast_map::node_ctor(nm, tps, ctor, _, pt) {
+ ast_map::node_ctor(nm, tps, ctor, _, pt) => {
let my_path = vec::append(*pt, ~[path_name(nm)]);
register_fn(ccx, ctor.span, my_path, ctor.node.id)
}
- ast_map::node_dtor(tps, dt, parent_id, pt) {
+ ast_map::node_dtor(tps, dt, parent_id, pt) => {
/*
Don't just call register_fn, since we don't want to add
the implicit self argument automatically (we want to make sure
llfn
}
- ast_map::node_variant(v, enm, pth) {
+ ast_map::node_variant(v, enm, pth) => {
assert v.node.args.len() != 0u;
let pth = vec::append(*pth,
~[path_name(enm.ident),
path_name(v.node.name)]);
let llfn = alt check enm.node {
- ast::item_enum(_, _) {
+ ast::item_enum(_, _) => {
register_fn(ccx, v.span, pth, id)
}
};
fn trans_constant(ccx: @crate_ctxt, it: @ast::item) {
let _icx = ccx.insn_ctxt(~"trans_constant");
alt it.node {
- ast::item_enum(variants, _) {
+ ast::item_enum(variants, _) => {
let vi = ty::enum_variants(ccx.tcx, {crate: ast::local_crate,
node: it.id});
let mut i = 0;
i += 1;
}
}
- _ { }
+ _ => ()
}
}
fn trap(bcx: block) {
let v: ~[ValueRef] = ~[];
alt bcx.ccx().intrinsics.find(~"llvm.trap") {
- some(x) { Call(bcx, x, v); }
- _ { bcx.sess().bug(~"unbound llvm.trap in trap"); }
+ some(x) => { Call(bcx, x, v); },
+ _ => bcx.sess().bug(~"unbound llvm.trap in trap")
}
}
fn gather_local_rtcalls(ccx: @crate_ctxt, crate: @ast::crate) {
visit::visit_crate(*crate, (), visit::mk_simple_visitor(@{
visit_item: |item| alt item.node {
- ast::item_fn(decl, _, _) {
+ ast::item_fn(decl, _, _) => {
let attr_metas = attr::attr_metas(
attr::find_attrs_by_name(item.attrs, ~"rt"));
do vec::iter(attr_metas) |attr_meta| {
alt attr::get_meta_item_list(attr_meta) {
- some(list) {
+ some(list) => {
let name = *attr::get_meta_item_name(vec::head(list));
push_rtcall(ccx, name, {crate: ast::local_crate,
node: item.id});
}
- none {}
+ none => ()
}
}
}
- _ {}
+ _ => ()
}
with *visit::default_simple_visitor()
}));
do decoder::each_path(cmeta) |path| {
let pathname = path.path_string;
alt path.def_like {
- decoder::dl_def(d) {
+ decoder::dl_def(d) => {
alt d {
- ast::def_fn(did, _) {
+ ast::def_fn(did, _) => {
// FIXME (#2861): This should really iterate attributes
// like gather_local_rtcalls, but we'll need to
// export attributes in metadata/encoder before we can do
push_rtcall(ccx, name, did);
}
}
- _ {}
+ _ => ()
}
}
- _ {}
+ _ => ()
}
true
}
for defs.each |def| {
if !def.reexp { again; }
let path = alt check cx.tcx.items.get(exp_id) {
- ast_map::node_export(_, path) {
+ ast_map::node_export(_, path) => {
ast_map::path_to_str(*path)
}
};
s += ~"/";
s += category;
- let n = alt h.find(s) { some(n) { n } _ { 0u } };
+ let n = alt h.find(s) {
+ some(n) => n,
+ _ => 0u
+ };
h.insert(s, n+1u);
}
}
fn ev_to_str(ccx: @crate_ctxt, ev: environment_value) -> ~str {
alt ev {
- env_copy(v, t, lk) { fmt!{"copy(%s,%s)", val_str(ccx.tn, v),
- ty_to_str(ccx.tcx, t)} }
- env_move(v, t, lk) { fmt!{"move(%s,%s)", val_str(ccx.tn, v),
- ty_to_str(ccx.tcx, t)} }
- env_ref(v, t, lk) { fmt!{"ref(%s,%s)", val_str(ccx.tn, v),
- ty_to_str(ccx.tcx, t)} }
+ env_copy(v, t, lk) => fmt!{"copy(%s,%s)", val_str(ccx.tn, v),
+ ty_to_str(ccx.tcx, t)},
+ env_move(v, t, lk) => fmt!{"move(%s,%s)", val_str(ccx.tn, v),
+ ty_to_str(ccx.tcx, t)},
+ env_ref(v, t, lk) => fmt!{"ref(%s,%s)", val_str(ccx.tn, v),
+ ty_to_str(ccx.tcx, t)}
}
}
// Compute the closed over data
for vec::each(bound_values) |bv| {
vec::push(bound_tys, alt bv {
- env_copy(_, t, _) { t }
- env_move(_, t, _) { t }
- env_ref(_, t, _) { t }
+ env_copy(_, t, _) => t,
+ env_move(_, t, _) => t,
+ env_ref(_, t, _) => t
});
}
let cdata_ty = ty::mk_tup(tcx, bound_tys);
// Allocate and initialize the box:
let {bcx, val} = alt ck {
- ty::ck_box {
- malloc_raw(bcx, cdata_ty, heap_shared)
- }
- ty::ck_uniq {
- malloc_raw(bcx, cdata_ty, heap_exchange)
- }
- ty::ck_block {
+ ty::ck_box => malloc_raw(bcx, cdata_ty, heap_shared),
+ ty::ck_uniq => malloc_raw(bcx, cdata_ty, heap_exchange),
+ ty::ck_block => {
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
let llbox = base::alloc_ty(bcx, cbox_ty);
nuke_ref_count(bcx, llbox);
let bound_data = GEPi(bcx, llbox,
~[0u, abi::box_field_body, i]);
alt bv {
- env_copy(val, ty, lv_owned) {
+ env_copy(val, ty, lv_owned) => {
let val1 = load_if_immediate(bcx, val, ty);
bcx = base::copy_val(bcx, INIT, bound_data, val1, ty);
}
- env_copy(val, ty, lv_owned_imm) {
+ env_copy(val, ty, lv_owned_imm) => {
bcx = base::copy_val(bcx, INIT, bound_data, val, ty);
}
- env_copy(_, _, lv_temporary) {
+ env_copy(_, _, lv_temporary) => {
fail ~"cannot capture temporary upvar";
}
- env_move(val, ty, kind) {
+ env_move(val, ty, kind) => {
let src = {bcx:bcx, val:val, kind:kind};
bcx = move_val(bcx, INIT, bound_data, src, ty);
}
- env_ref(val, ty, lv_owned) {
+ env_ref(val, ty, lv_owned) => {
debug!{"> storing %s into %s",
val_str(bcx.ccx().tn, val),
val_str(bcx.ccx().tn, bound_data)};
Store(bcx, val, bound_data);
}
- env_ref(val, ty, lv_owned_imm) {
+ env_ref(val, ty, lv_owned_imm) => {
let addr = do_spill_noroot(bcx, val);
Store(bcx, addr, bound_data);
}
- env_ref(_, _, lv_temporary) {
+ env_ref(_, _, lv_temporary) => {
fail ~"cannot capture temporary upvar";
}
}
syntax::ast_map::node_id_to_str(bcx.ccx().tcx.items, nid)};
let mut ty = node_id_type(bcx, nid);
alt cap_var.mode {
- capture::cap_ref {
+ capture::cap_ref => {
assert ck == ty::ck_block;
ty = ty::mk_mut_ptr(tcx, ty);
vec::push(env_vals, env_ref(lv.val, ty, lv.kind));
}
- capture::cap_copy {
+ capture::cap_copy => {
let mv = alt check ccx.maps.last_use_map.find(id) {
- none { false }
- some(vars) { (*vars).contains(nid) }
+ none => false,
+ some(vars) => (*vars).contains(nid)
};
if mv { vec::push(env_vals, env_move(lv.val, ty, lv.kind)); }
else { vec::push(env_vals, env_copy(lv.val, ty, lv.kind)); }
}
- capture::cap_move {
+ capture::cap_move => {
vec::push(env_vals, env_move(lv.val, ty, lv.kind));
}
- capture::cap_drop {
+ capture::cap_drop => {
assert lv.kind == lv_owned;
bcx = drop_ty(bcx, lv.val, ty);
bcx = zero_mem(bcx, lv.val, ty);
}
do option::iter(include_ret_handle) |flagptr| {
let our_ret = alt bcx.fcx.loop_ret {
- some({retptr, _}) { retptr }
- none { bcx.fcx.llretptr }
+ some({retptr, _}) => retptr,
+ none => bcx.fcx.llretptr
};
let nil_ret = PointerCast(bcx, our_ret, T_ptr(T_nil()));
vec::push(env_vals,
let mut i = 0u;
do vec::iter(cap_vars) |cap_var| {
alt cap_var.mode {
- capture::cap_drop { /* ignore */ }
- _ {
+ capture::cap_drop => { /* ignore */ }
+ _ => {
let mut upvarptr =
GEPi(bcx, llcdata, ~[0u, i]);
alt ck {
- ty::ck_block { upvarptr = Load(bcx, upvarptr); }
- ty::ck_uniq | ty::ck_box { }
+ ty::ck_block => { upvarptr = Load(bcx, upvarptr); }
+ ty::ck_uniq | ty::ck_box => ()
}
let def_id = ast_util::def_id_of_def(cap_var.def);
fcx.llupvars.insert(def_id.node, upvarptr);
let trans_closure_env = fn@(ck: ty::closure_kind) -> result {
let cap_vars = capture::compute_capture_vars(
ccx.tcx, id, proto, cap_clause);
- let ret_handle = alt is_loop_body { some(x) { x } none { none } };
+ let ret_handle = alt is_loop_body { some(x) => x, none => none };
let {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, ck, id,
ret_handle);
trans_closure(ccx, sub_path, decl, body, llfn, no_self,
};
let {bcx: bcx, val: closure} = alt proto {
- ast::proto_block { trans_closure_env(ty::ck_block) }
- ast::proto_box { trans_closure_env(ty::ck_box) }
- ast::proto_uniq { trans_closure_env(ty::ck_uniq) }
- ast::proto_bare {
+ ast::proto_block => trans_closure_env(ty::ck_block),
+ ast::proto_box => trans_closure_env(ty::ck_box),
+ ast::proto_uniq => trans_closure_env(ty::ck_uniq),
+ ast::proto_bare => {
trans_closure(ccx, sub_path, decl, body, llfn, no_self, none,
id, |_fcx| { }, |_bcx| { });
{bcx: bcx, val: C_null(T_opaque_box_ptr(ccx))}
return alt ty::get(t).struct {
ty::ty_fn({proto: ast::proto_bare, _}) |
- ty::ty_fn({proto: ast::proto_block, _}) { bcx }
- ty::ty_fn({proto: ast::proto_uniq, _}) { fn_env(ty::ck_uniq) }
- ty::ty_fn({proto: ast::proto_box, _}) { fn_env(ty::ck_box) }
- _ { fail ~"make_fn_glue invoked on non-function type" }
+ ty::ty_fn({proto: ast::proto_block, _}) => bcx,
+ ty::ty_fn({proto: ast::proto_uniq, _}) => fn_env(ty::ck_uniq),
+ ty::ty_fn({proto: ast::proto_box, _}) => fn_env(ty::ck_box),
+ _ => fail ~"make_fn_glue invoked on non-function type"
};
}
// Easy cases:
let _icx = bcx.insn_ctxt(~"closure::make_opaque_cbox_take_glue");
alt ck {
- ty::ck_block { return bcx; }
- ty::ck_box {
+ ty::ck_block => return bcx,
+ ty::ck_box => {
incr_refcnt_of_boxed(bcx, Load(bcx, cboxptr));
return bcx;
}
- ty::ck_uniq { /* hard case: */ }
+ ty::ck_uniq => { /* hard case: */ }
}
// Hard case, a deep copy:
-> block {
let _icx = bcx.insn_ctxt(~"closure::make_opaque_cbox_drop_glue");
alt ck {
- ty::ck_block { bcx }
- ty::ck_box {
+ ty::ck_block => bcx,
+ ty::ck_box => {
decr_refcnt_maybe_free(bcx, Load(bcx, cboxptr),
ty::mk_opaque_closure_ptr(bcx.tcx(), ck))
}
- ty::ck_uniq {
+ ty::ck_uniq => {
free_ty(bcx, Load(bcx, cboxptr),
ty::mk_opaque_closure_ptr(bcx.tcx(), ck))
}
-> block {
let _icx = bcx.insn_ctxt(~"closure::make_opaque_cbox_free_glue");
alt ck {
- ty::ck_block { return bcx; }
- ty::ck_box | ty::ck_uniq { /* hard cases: */ }
+ ty::ck_block => return bcx,
+ ty::ck_box | ty::ck_uniq => { /* hard cases: */ }
}
let ccx = bcx.ccx();
// Free the ty descr (if necc) and the box itself
alt ck {
- ty::ck_block { fail ~"Impossible"; }
- ty::ck_box {
- trans_free(bcx, cbox)
- }
- ty::ck_uniq {
- trans_unique_free(bcx, cbox)
- }
+ ty::ck_block => fail ~"Impossible",
+ ty::ck_box => trans_free(bcx, cbox),
+ ty::ck_uniq => trans_unique_free(bcx, cbox)
}
}
}
}
fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
let free_fn = alt heap {
- heap_shared { |a| base::trans_free(a, ptr) }
- heap_exchange { |a| base::trans_unique_free(a, ptr) }
+ heap_shared => |a| base::trans_free(a, ptr),
+ heap_exchange => |a| base::trans_unique_free(a, ptr)
};
do in_scope_cx(cx) |info| {
vec::push(info.cleanups, clean_temp(ptr, free_fn,
fn revoke_clean(cx: block, val: ValueRef) {
do in_scope_cx(cx) |info| {
do option::iter(vec::position(info.cleanups, |cu| {
- alt cu { clean_temp(v, _, _) if v == val { true } _ { false } }
+ alt cu {
+ clean_temp(v, _, _) if v == val => true,
+ _ => false
+ }
})) |i| {
info.cleanups =
vec::append(vec::slice(info.cleanups, 0u, i),
let mut cur = cx;
loop {
alt cur.kind {
- block_scope(inf) { f(inf); return; }
- _ {}
+ block_scope(inf) => { f(inf); return; }
+ _ => ()
}
cur = block_parent(cur);
}
fn block_parent(cx: block) -> block {
alt cx.parent {
- some(b) { b }
- none { cx.sess().bug(fmt!{"block_parent called on root block %?",
- cx}); }
+ some(b) => b,
+ none => cx.sess().bug(fmt!{"block_parent called on root block %?",
+ cx})
}
}
}
fn to_str() -> ~str {
alt self.node_info {
- some(node_info) {
+ some(node_info) => {
fmt!{"[block %d]", node_info.id}
}
- none {
+ none => {
fmt!{"[block %x]", ptr::addr_of(*self) as uint}
}
}
fn T_int(targ_cfg: @session::config) -> TypeRef {
return alt targ_cfg.arch {
- session::arch_x86 { T_i32() }
- session::arch_x86_64 { T_i64() }
- session::arch_arm { T_i32() }
+ session::arch_x86 => T_i32(),
+ session::arch_x86_64 => T_i64(),
+ session::arch_arm => T_i32()
};
}
fn T_int_ty(cx: @crate_ctxt, t: ast::int_ty) -> TypeRef {
alt t {
- ast::ty_i { cx.int_type }
- ast::ty_char { T_char() }
- ast::ty_i8 { T_i8() }
- ast::ty_i16 { T_i16() }
- ast::ty_i32 { T_i32() }
- ast::ty_i64 { T_i64() }
+ ast::ty_i => cx.int_type,
+ ast::ty_char => T_char(),
+ ast::ty_i8 => T_i8(),
+ ast::ty_i16 => T_i16(),
+ ast::ty_i32 => T_i32(),
+ ast::ty_i64 => T_i64()
}
}
fn T_uint_ty(cx: @crate_ctxt, t: ast::uint_ty) -> TypeRef {
alt t {
- ast::ty_u { cx.int_type }
- ast::ty_u8 { T_i8() }
- ast::ty_u16 { T_i16() }
- ast::ty_u32 { T_i32() }
- ast::ty_u64 { T_i64() }
+ ast::ty_u => cx.int_type,
+ ast::ty_u8 => T_i8(),
+ ast::ty_u16 => T_i16(),
+ ast::ty_u32 => T_i32(),
+ ast::ty_u64 => T_i64()
}
}
fn T_float_ty(cx: @crate_ctxt, t: ast::float_ty) -> TypeRef {
alt t {
- ast::ty_f { cx.float_type }
- ast::ty_f32 { T_f32() }
- ast::ty_f64 { T_f64() }
+ ast::ty_f => cx.float_type,
+ ast::ty_f32 => T_f32(),
+ ast::ty_f64 => T_f64()
}
}
fn T_float(targ_cfg: @session::config) -> TypeRef {
return alt targ_cfg.arch {
- session::arch_x86 { T_f64() }
- session::arch_x86_64 { T_f64() }
- session::arch_arm { T_f64() }
+ session::arch_x86 => T_f64(),
+ session::arch_x86_64 => T_f64(),
+ session::arch_arm => T_f64()
};
}
fn T_glue_fn(cx: @crate_ctxt) -> TypeRef {
let s = ~"glue_fn";
- alt name_has_type(cx.tn, s) { some(t) { return t; } _ {} }
+ alt name_has_type(cx.tn, s) {
+ some(t) => return t,
+ _ => ()
+ }
let t = T_tydesc_field(cx, abi::tydesc_field_drop_glue);
associate_type(cx.tn, s, t);
return t;
// This type must never be used directly; it must always be cast away.
fn T_typaram(tn: type_names) -> TypeRef {
let s = ~"typaram";
- alt name_has_type(tn, s) { some(t) { return t; } _ {} }
+ alt name_has_type(tn, s) {
+ some(t) => return t,
+ _ => ()
+ }
let t = T_i8();
associate_type(tn, s, t);
return t;
fn T_opaque_enum(cx: @crate_ctxt) -> TypeRef {
let s = ~"opaque_enum";
- alt name_has_type(cx.tn, s) { some(t) { return t; } _ {} }
+ alt name_has_type(cx.tn, s) {
+ some(t) => return t,
+ _ => ()
+ }
let t = T_struct(~[T_enum_discrim(cx), T_i8()]);
associate_type(cx.tn, s, t);
return t;
// our boxed-and-length-annotated strings.
fn C_cstr(cx: @crate_ctxt, s: ~str) -> ValueRef {
alt cx.const_cstr_cache.find(s) {
- some(llval) { return llval; }
- none { }
+ some(llval) => return llval,
+ none => ()
}
let sc = do str::as_c_str(s) |buf| {
let mut h = syntax::ast_util::hash_def(&mi.def);
for vec::each(mi.params) |param| {
h = h * alt param {
- mono_precise(ty, vts) {
+ mono_precise(ty, vts) => {
let mut h = ty::type_id(ty);
do option::iter(vts) |vts| {
for vec::each(vts) |vt| {
}
h
}
- mono_any { 1u }
- mono_repr(sz, align) { sz * (align + 2u) }
+ mono_any => 1u,
+ mono_repr(sz, align) => sz * (align + 2u)
}
}
h
fn path_str(p: path) -> ~str {
let mut r = ~"", first = true;
for vec::each(p) |e| {
- alt e { ast_map::path_name(s) | ast_map::path_mod(s) {
+ alt e { ast_map::path_name(s) | ast_map::path_mod(s) => {
if first { first = false; }
else { r += ~"::"; }
r += *s;
let tcx = bcx.tcx();
let t = ty::node_id_to_type(tcx, id);
alt bcx.fcx.param_substs {
- some(substs) { ty::subst_tps(tcx, substs.tys, t) }
- _ { assert !ty::type_has_params(t); t }
+ some(substs) => ty::subst_tps(tcx, substs.tys, t),
+ _ => { assert !ty::type_has_params(t); t }
}
}
fn expr_ty(bcx: block, ex: @ast::expr) -> ty::t {
let tcx = bcx.tcx();
let params = ty::node_id_to_type_params(tcx, id);
alt bcx.fcx.param_substs {
- some(substs) {
+ some(substs) => {
vec::map(params, |t| ty::subst_tps(tcx, substs.tys, t))
}
- _ { params }
+ _ => params
}
}
fields: ~[ty::field])
-> uint {
alt ty::field_idx(ident, fields) {
- none { cx.sess.span_bug(sp, fmt!{"base expr doesn't appear to \
- have a field named %s", *ident}); }
- some(i) { i }
+ none => cx.sess.span_bug(
+ sp, fmt!{"base expr doesn't appear to \
+ have a field named %s", *ident}),
+ some(i) => i
}
}
-> ValueRef {
let _icx = cx.insn_ctxt(~"trans_lit");
alt lit.node {
- ast::lit_int(i, t) { C_integral(T_int_ty(cx, t), i as u64, True) }
- ast::lit_uint(u, t) { C_integral(T_uint_ty(cx, t), u, False) }
- ast::lit_int_unsuffixed(i) {
+ ast::lit_int(i, t) => C_integral(T_int_ty(cx, t), i as u64, True),
+ ast::lit_uint(u, t) => C_integral(T_uint_ty(cx, t), u, False),
+ ast::lit_int_unsuffixed(i) => {
let lit_int_ty = ty::node_id_to_type(cx.tcx, e.id);
alt ty::get(lit_int_ty).struct {
- ty::ty_int(t) {
+ ty::ty_int(t) => {
C_integral(T_int_ty(cx, t), i as u64, True)
}
- ty::ty_uint(t) {
+ ty::ty_uint(t) => {
C_integral(T_uint_ty(cx, t), i as u64, False)
}
- _ { cx.sess.span_bug(lit.span,
- ~"integer literal doesn't have a type");
- }
+ _ => cx.sess.span_bug(lit.span,
+ ~"integer literal doesn't have a type")
}
}
- ast::lit_float(fs, t) { C_floating(*fs, T_float_ty(cx, t)) }
- ast::lit_bool(b) { C_bool(b) }
- ast::lit_nil { C_nil() }
- ast::lit_str(s) { C_estr_slice(cx, *s) }
+ ast::lit_float(fs, t) => C_floating(*fs, T_float_ty(cx, t)),
+ ast::lit_bool(b) => C_bool(b),
+ ast::lit_nil => C_nil(),
+ ast::lit_str(s) => C_estr_slice(cx, *s)
}
}
fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
let _icx = cx.insn_ctxt(~"const_expr");
alt e.node {
- ast::expr_lit(lit) { consts::const_lit(cx, e, *lit) }
- ast::expr_binary(b, e1, e2) {
+ ast::expr_lit(lit) => consts::const_lit(cx, e, *lit),
+ ast::expr_binary(b, e1, e2) => {
let te1 = const_expr(cx, e1);
let te2 = const_expr(cx, e2);
let is_float = ty::type_is_fp(ty);
let signed = ty::type_is_signed(ty);
return alt b {
- ast::add {
+ ast::add => {
if is_float { llvm::LLVMConstFAdd(te1, te2) }
else { llvm::LLVMConstAdd(te1, te2) }
}
- ast::subtract {
+ ast::subtract => {
if is_float { llvm::LLVMConstFSub(te1, te2) }
else { llvm::LLVMConstSub(te1, te2) }
}
- ast::mul {
+ ast::mul => {
if is_float { llvm::LLVMConstFMul(te1, te2) }
else { llvm::LLVMConstMul(te1, te2) }
}
- ast::div {
+ ast::div => {
if is_float { llvm::LLVMConstFDiv(te1, te2) }
else if signed { llvm::LLVMConstSDiv(te1, te2) }
else { llvm::LLVMConstUDiv(te1, te2) }
}
- ast::rem {
+ ast::rem => {
if is_float { llvm::LLVMConstFRem(te1, te2) }
else if signed { llvm::LLVMConstSRem(te1, te2) }
else { llvm::LLVMConstURem(te1, te2) }
}
ast::and |
- ast::or { cx.sess.span_unimpl(e.span, ~"binop logic"); }
- ast::bitxor { llvm::LLVMConstXor(te1, te2) }
- ast::bitand { llvm::LLVMConstAnd(te1, te2) }
- ast::bitor { llvm::LLVMConstOr(te1, te2) }
- ast::shl { llvm::LLVMConstShl(te1, te2) }
- ast::shr {
+ ast::or => cx.sess.span_unimpl(e.span, ~"binop logic"),
+ ast::bitxor => llvm::LLVMConstXor(te1, te2),
+ ast::bitand => llvm::LLVMConstAnd(te1, te2),
+ ast::bitor => llvm::LLVMConstOr(te1, te2),
+ ast::shl => llvm::LLVMConstShl(te1, te2),
+ ast::shr => {
if signed { llvm::LLVMConstAShr(te1, te2) }
else { llvm::LLVMConstLShr(te1, te2) }
}
ast::le |
ast::ne |
ast::ge |
- ast::gt { cx.sess.span_unimpl(e.span, ~"binop comparator"); }
+ ast::gt => cx.sess.span_unimpl(e.span, ~"binop comparator")
}
}
- ast::expr_unary(u, e) {
+ ast::expr_unary(u, e) => {
let te = const_expr(cx, e);
let ty = ty::expr_ty(cx.tcx, e);
let is_float = ty::type_is_fp(ty);
return alt u {
ast::box(_) |
ast::uniq(_) |
- ast::deref { cx.sess.span_bug(e.span,
- ~"bad unop type in const_expr"); }
- ast::not { llvm::LLVMConstNot(te) }
- ast::neg {
+ ast::deref => cx.sess.span_bug(e.span,
+ ~"bad unop type in const_expr"),
+ ast::not => llvm::LLVMConstNot(te),
+ ast::neg => {
if is_float { llvm::LLVMConstFNeg(te) }
else { llvm::LLVMConstNeg(te) }
}
}
}
- ast::expr_cast(base, tp) {
+ ast::expr_cast(base, tp) => {
let ety = ty::expr_ty(cx.tcx, e), llty = type_of::type_of(cx, ety);
let basety = ty::expr_ty(cx.tcx, base);
let v = const_expr(cx, base);
alt check (base::cast_type_kind(basety), base::cast_type_kind(ety)) {
- (base::cast_integral, base::cast_integral) {
+ (base::cast_integral, base::cast_integral) => {
let s = if ty::type_is_signed(basety) { True } else { False };
llvm::LLVMConstIntCast(v, llty, s)
}
- (base::cast_integral, base::cast_float) {
+ (base::cast_integral, base::cast_float) => {
if ty::type_is_signed(basety) { llvm::LLVMConstSIToFP(v, llty) }
else { llvm::LLVMConstUIToFP(v, llty) }
}
- (base::cast_float, base::cast_float) {
+ (base::cast_float, base::cast_float) => {
llvm::LLVMConstFPCast(v, llty)
}
- (base::cast_float, base::cast_integral) {
+ (base::cast_float, base::cast_integral) => {
if ty::type_is_signed(ety) { llvm::LLVMConstFPToSI(v, llty) }
else { llvm::LLVMConstFPToUI(v, llty) }
}
}
}
- ast::expr_addr_of(ast::m_imm, sub) {
+ ast::expr_addr_of(ast::m_imm, sub) => {
let cv = const_expr(cx, sub);
let subty = ty::expr_ty(cx.tcx, sub),
llty = type_of::type_of(cx, subty);
llvm::LLVMSetGlobalConstant(gv, True);
gv
}
- ast::expr_tup(es) {
+ ast::expr_tup(es) => {
C_struct(es.map(|e| const_expr(cx, e)))
}
- ast::expr_rec(fs, none) {
+ ast::expr_rec(fs, none) => {
C_struct(fs.map(|f| const_expr(cx, f.node.expr)))
}
- ast::expr_vec(es, m_imm) {
+ ast::expr_vec(es, m_imm) => {
let (v, _) = const_vec_and_sz(cx, e, es);
v
}
- ast::expr_vstore(e, ast::vstore_fixed(_)) {
+ ast::expr_vstore(e, ast::vstore_fixed(_)) => {
const_expr(cx, e)
}
- ast::expr_vstore(sub, ast::vstore_slice(_)) {
+ ast::expr_vstore(sub, ast::vstore_slice(_)) => {
alt sub.node {
- ast::expr_lit(lit) {
+ ast::expr_lit(lit) => {
alt lit.node {
ast::lit_str(*) => { const_expr(cx, sub) }
_ => { cx.sess.span_bug(e.span,
~"bad const-slice expr")
}
}
- ast::expr_path(path) {
+ ast::expr_path(path) => {
alt cx.tcx.def_map.find(e.id) {
- some(ast::def_const(def_id)) {
+ some(ast::def_const(def_id)) => {
// Don't know how to handle external consts
assert ast_util::is_local(def_id);
alt cx.tcx.items.get(def_id.node) {
ast_map::node_item(@{
node: ast::item_const(_, subexpr), _
- }, _) {
+ }, _) => {
// FIXME (#2530): Instead of recursing here to regenerate
// the values for other constants, we should just look up
// the already-defined value.
const_expr(cx, subexpr)
}
- _ {
- cx.sess.span_bug(e.span, ~"expected item");
- }
+ _ => cx.sess.span_bug(e.span, ~"expected item")
}
}
- _ { cx.sess.span_bug(e.span, ~"expected to find a const def") }
+ _ => cx.sess.span_bug(e.span, ~"expected to find a const def")
}
}
- _ { cx.sess.span_bug(e.span,
- ~"bad constant expression type in consts::const_expr"); }
+ _ => cx.sess.span_bug(e.span,
+ ~"bad constant expression type in consts::const_expr")
}
}
fn md_from_metadata<T>(val: debug_metadata) -> T unsafe {
alt val {
- file_metadata(md) { cast_safely(md) }
- compile_unit_metadata(md) { cast_safely(md) }
- subprogram_metadata(md) { cast_safely(md) }
- local_var_metadata(md) { cast_safely(md) }
- tydesc_metadata(md) { cast_safely(md) }
- block_metadata(md) { cast_safely(md) }
- argument_metadata(md) { cast_safely(md) }
- retval_metadata(md) { cast_safely(md) }
+ file_metadata(md) => cast_safely(md),
+ compile_unit_metadata(md) => cast_safely(md),
+ subprogram_metadata(md) => cast_safely(md),
+ local_var_metadata(md) => cast_safely(md),
+ tydesc_metadata(md) => cast_safely(md),
+ block_metadata(md) => cast_safely(md),
+ argument_metadata(md) => cast_safely(md),
+ retval_metadata(md) => cast_safely(md)
}
}
let tg = CompileUnitTag;
alt cached_metadata::<@metadata<compile_unit_md>>(cache, tg,
|md| md.data.name == crate_name) {
- option::some(md) { return md; }
- option::none {}
+ option::some(md) => return md,
+ option::none => ()
}
let (_, work_dir) = get_file_path_and_dir(cx.sess.working_dir,
let tg = FileDescriptorTag;
alt cached_metadata::<@metadata<file_md>>(
cache, tg, |md| md.data.path == full_path) {
- option::some(md) { return md; }
- option::none {}
+ option::some(md) => return md,
+ option::none => ()
}
let (file_path, work_dir) = get_file_path_and_dir(cx.sess.working_dir,
let mut cx = cx;
while option::is_none(cx.node_info) {
alt cx.parent {
- some(b) { cx = b; }
- none { fail; }
+ some(b) => cx = b,
+ none => fail
}
}
let sp = option::get(cx.node_info).span;
}*/
let parent = alt cx.parent {
- none { create_function(cx.fcx).node }
- some(bcx) { create_block(bcx).node }
+ none => create_function(cx.fcx).node,
+ some(bcx) => create_block(bcx).node
};
let file_node = create_file(cx.ccx(), fname);
let unique_id = alt cache.find(LexicalBlockTag) {
- option::some(v) { vec::len(v) as int }
- option::none { 0 }
+ option::some(v) => vec::len(v) as int,
+ option::none => 0
};
let lldata = ~[lltag(tg),
parent,
let tg = BasicTypeDescriptorTag;
alt cached_metadata::<@metadata<tydesc_md>>(
cache, tg, |md| ty::type_id(t) == md.data.hash) {
- option::some(md) { return md; }
- option::none {}
+ option::some(md) => return md,
+ option::none => ()
}
let (name, encoding) = alt check ty {
- ast::ty_bool {(~"bool", DW_ATE_boolean)}
- ast::ty_int(m) { alt m {
- ast::ty_char {(~"char", DW_ATE_unsigned)}
- ast::ty_i {(~"int", DW_ATE_signed)}
- ast::ty_i8 {(~"i8", DW_ATE_signed_char)}
- ast::ty_i16 {(~"i16", DW_ATE_signed)}
- ast::ty_i32 {(~"i32", DW_ATE_signed)}
- ast::ty_i64 {(~"i64", DW_ATE_signed)}
- }}
- ast::ty_uint(m) { alt m {
- ast::ty_u {(~"uint", DW_ATE_unsigned)}
- ast::ty_u8 {(~"u8", DW_ATE_unsigned_char)}
- ast::ty_u16 {(~"u16", DW_ATE_unsigned)}
- ast::ty_u32 {(~"u32", DW_ATE_unsigned)}
- ast::ty_u64 {(~"u64", DW_ATE_unsigned)}
- }}
- ast::ty_float(m) { alt m {
- ast::ty_f {(~"float", DW_ATE_float)}
- ast::ty_f32 {(~"f32", DW_ATE_float)}
- ast::ty_f64 {(~"f64", DW_ATE_float)}
- }}
+ ast::ty_bool => (~"bool", DW_ATE_boolean),
+ ast::ty_int(m) => alt m {
+ ast::ty_char => (~"char", DW_ATE_unsigned),
+ ast::ty_i => (~"int", DW_ATE_signed),
+ ast::ty_i8 => (~"i8", DW_ATE_signed_char),
+ ast::ty_i16 => (~"i16", DW_ATE_signed),
+ ast::ty_i32 => (~"i32", DW_ATE_signed),
+ ast::ty_i64 => (~"i64", DW_ATE_signed)
+ }
+ ast::ty_uint(m) => alt m {
+ ast::ty_u => (~"uint", DW_ATE_unsigned),
+ ast::ty_u8 => (~"u8", DW_ATE_unsigned_char),
+ ast::ty_u16 => (~"u16", DW_ATE_unsigned),
+ ast::ty_u32 => (~"u32", DW_ATE_unsigned),
+ ast::ty_u64 => (~"u64", DW_ATE_unsigned)
+ }
+ ast::ty_float(m) => alt m {
+ ast::ty_f => (~"float", DW_ATE_float),
+ ast::ty_f32 => (~"f32", DW_ATE_float),
+ ast::ty_f64 => (~"f64", DW_ATE_float)
+ }
};
let fname = filename_from_span(cx, span);
let tg = AutoVariableTag;
alt cached_metadata::<@metadata<local_var_md>>(
cache, tg, |md| md.data.id == local.node.id) {
- option::some(md) { return md; }
- option::none {}
+ option::some(md) => return md,
+ option::none => ()
}
let name = alt local.node.pat.node {
- ast::pat_ident(_, pth, _) { ast_util::path_to_ident(pth) }
+ ast::pat_ident(_, pth, _) => ast_util::path_to_ident(pth),
// FIXME this should be handled (#2533)
- _ { fail ~"no single variable name for local"; }
+ _ => fail ~"no single variable name for local"
};
let loc = codemap::lookup_char_pos(cx.sess.codemap,
local.span.lo);
let tymd = create_ty(cx, ty, local.node.ty);
let filemd = create_file(cx, loc.file.name);
let context = alt bcx.parent {
- none { create_function(bcx.fcx).node }
- some(_) { create_block(bcx).node }
+ none => create_function(bcx.fcx).node,
+ some(_) => create_block(bcx).node
};
let mdnode = create_var(tg, context, *name, filemd.node,
loc.line as int, tymd.node);
update_cache(cache, AutoVariableTag, local_var_metadata(mdval));
let llptr = alt bcx.fcx.lllocals.find(local.node.id) {
- option::some(local_mem(v)) { v }
- option::some(_) {
+ option::some(local_mem(v)) => v,
+ option::some(_) => {
bcx.tcx().sess.span_bug(local.span, ~"local is bound to \
something weird");
}
- option::none {
+ option::none => {
alt bcx.fcx.lllocals.get(local.node.pat.id) {
- local_imm(v) { v }
- _ { bcx.tcx().sess.span_bug(local.span, ~"local is bound to \
- something weird"); }
+ local_imm(v) => v,
+ _ => bcx.tcx().sess.span_bug(local.span, ~"local is bound to \
+ something weird")
}
}
};
let tg = ArgVariableTag;
alt cached_metadata::<@metadata<argument_md>>(
cache, ArgVariableTag, |md| md.data.id == arg.id) {
- option::some(md) { return md; }
- option::none {}
+ option::some(md) => return md,
+ option::none => ()
}
let loc = codemap::lookup_char_pos(cx.sess.codemap,
update_cache(cache, tg, argument_metadata(mdval));
let llptr = alt fcx.llargs.get(arg.id) {
- local_mem(v) | local_imm(v) { v }
+ local_mem(v) | local_imm(v) => v,
};
let declargs = ~[llmdnode(~[llptr]), mdnode];
trans::build::Call(bcx, cx.intrinsics.get(~"llvm.dbg.declare"),
log(debug, codemap::span_to_str(sp, cx.sess.codemap));
let (ident, ret_ty, id) = alt cx.tcx.items.get(fcx.id) {
- ast_map::node_item(item, _) {
+ ast_map::node_item(item, _) => {
alt item.node {
- ast::item_fn(decl, _, _) {
+ ast::item_fn(decl, _, _) => {
(item.ident, decl.output, item.id)
}
- _ { fcx.ccx.sess.span_bug(item.span, ~"create_function: item \
- bound to non-function"); }
+ _ => fcx.ccx.sess.span_bug(item.span, ~"create_function: item \
+ bound to non-function")
}
}
- ast_map::node_method(method, _, _) {
+ ast_map::node_method(method, _, _) => {
(method.ident, method.decl.output, method.id)
}
- ast_map::node_ctor(nm, _, ctor, _, _) {
+ ast_map::node_ctor(nm, _, ctor, _, _) => {
// FIXME: output type may be wrong (#2194)
(nm, ctor.node.dec.output, ctor.node.id)
}
- ast_map::node_expr(expr) {
+ ast_map::node_expr(expr) => {
alt expr.node {
- ast::expr_fn(_, decl, _, _) {
+ ast::expr_fn(_, decl, _, _) => {
(@dbg_cx.names(~"fn"), decl.output, expr.id)
}
- ast::expr_fn_block(decl, _, _) {
+ ast::expr_fn_block(decl, _, _) => {
(@dbg_cx.names(~"fn"), decl.output, expr.id)
}
- _ { fcx.ccx.sess.span_bug(expr.span, ~"create_function: \
- expected an expr_fn or fn_block here"); }
+ _ => fcx.ccx.sess.span_bug(expr.span,
+ ~"create_function: \
+ expected an expr_fn or fn_block here")
}
}
- _ { fcx.ccx.sess.bug(~"create_function: unexpected \
- sort of node"); }
+ _ => fcx.ccx.sess.bug(~"create_function: unexpected \
+ sort of node")
};
log(debug, ident);
let cache = get_cache(cx);
alt cached_metadata::<@metadata<subprogram_md>>(
cache, SubprogramTag, |md| md.data.id == id) {
- option::some(md) { return md; }
- option::none {}
+ option::some(md) => return md,
+ option::none => ()
}
let loc = codemap::lookup_char_pos(cx.sess.codemap,
let file_node = create_file(cx, loc.file.name).node;
let ty_node = if cx.sess.opts.extra_debuginfo {
alt ret_ty.node {
- ast::ty_nil { llnull() }
- _ { create_ty(cx, ty::node_id_to_type(cx.tcx, id), ret_ty).node }
+ ast::ty_nil => llnull(),
+ _ => create_ty(cx, ty::node_id_to_type(cx.tcx, id), ret_ty).node
}
} else {
llnull()
fn is_sse(++c: x86_64_reg_class) -> bool {
return alt c {
sse_fs_class | sse_fv_class |
- sse_ds_class | sse_dv_class { true }
- _ { false }
+ sse_ds_class | sse_dv_class => true,
+ _ => false
};
}
fn ty_align(ty: TypeRef) -> uint {
return alt llvm::LLVMGetTypeKind(ty) as int {
- 8 /* integer */ {
+ 8 /* integer */ => {
((llvm::LLVMGetIntTypeWidth(ty) as uint) + 7u) / 8u
}
- 12 /* pointer */ { 8u }
- 2 /* float */ { 4u }
- 3 /* double */ { 8u }
- 10 /* struct */ {
+ 12 /* pointer */ => 8u,
+ 2 /* float */ => 4u,
+ 3 /* double */ => 8u,
+ 10 /* struct */ => {
do vec::foldl(0u, struct_tys(ty)) |a, t| {
uint::max(a, ty_align(t))
}
}
- 11 /* array */ {
+ 11 /* array */ => {
let elt = llvm::LLVMGetElementType(ty);
ty_align(elt)
}
- _ {
- fail ~"ty_size: unhandled type"
- }
+ _ => fail ~"ty_size: unhandled type"
};
}
fn ty_size(ty: TypeRef) -> uint {
return alt llvm::LLVMGetTypeKind(ty) as int {
- 8 /* integer */ {
+ 8 /* integer */ => {
((llvm::LLVMGetIntTypeWidth(ty) as uint) + 7u) / 8u
}
- 12 /* pointer */ { 8u }
- 2 /* float */ { 4u }
- 3 /* double */ { 8u }
- 10 /* struct */ {
+ 12 /* pointer */ => 8u,
+ 2 /* float */ => 4u,
+ 3 /* double */ => 8u,
+ 10 /* struct */ => {
do vec::foldl(0u, struct_tys(ty)) |s, t| {
s + ty_size(t)
}
}
- 11 /* array */ {
+ 11 /* array */ => {
let len = llvm::LLVMGetArrayLength(ty) as uint;
let elt = llvm::LLVMGetElementType(ty);
let eltsz = ty_size(elt);
len * eltsz
}
- _ {
- fail ~"ty_size: unhandled type"
- }
+ _ => fail ~"ty_size: unhandled type"
};
}
alt llvm::LLVMGetTypeKind(ty) as int {
8 /* integer */ |
- 12 /* pointer */ {
+ 12 /* pointer */ => {
unify(cls, ix + off / 8u, integer_class);
}
- 2 /* float */ {
+ 2 /* float */ => {
if off % 8u == 4u {
unify(cls, ix + off / 8u, sse_fv_class);
} else {
unify(cls, ix + off / 8u, sse_fs_class);
}
}
- 3 /* double */ {
+ 3 /* double */ => {
unify(cls, ix + off / 8u, sse_ds_class);
}
- 10 /* struct */ {
+ 10 /* struct */ => {
classify_struct(struct_tys(ty), cls, ix, off);
}
- 11 /* array */ {
+ 11 /* array */ => {
let elt = llvm::LLVMGetElementType(ty);
let eltsz = ty_size(elt);
let len = llvm::LLVMGetArrayLength(ty) as uint;
i += 1u;
}
}
- _ {
- fail ~"classify: unhandled type";
- }
+ _ => fail ~"classify: unhandled type"
}
}
let e = vec::len(cls);
while i < e {
alt cls[i] {
- integer_class {
+ integer_class => {
vec::push(tys, T_i64());
}
- sse_fv_class {
+ sse_fv_class => {
let vec_len = llvec_len(vec::tailn(cls, i + 1u)) * 2u;
let vec_ty = llvm::LLVMVectorType(T_f32(),
vec_len as c_uint);
i += vec_len;
again;
}
- sse_fs_class {
+ sse_fs_class => {
vec::push(tys, T_f32());
}
- sse_ds_class {
+ sse_ds_class => {
vec::push(tys, T_f64());
}
- _ {
- fail ~"llregtype: unhandled class";
- }
+ _ => fail ~"llregtype: unhandled class"
}
i += 1u;
}
8 /* integer */ |
12 /* pointer */ |
2 /* float */ |
- 3 /* double */ { true }
- _ { false }
+ 3 /* double */ => true,
+ _ => false
};
}
do vec::iteri(tys.attrs) |i, a| {
alt a {
- option::some(attr) {
+ option::some(attr) => {
let llarg = get_param(llfn, i);
llvm::LLVMAddAttribute(llarg, attr as c_uint);
}
- _ {}
+ _ => ()
}
}
return llfn;
fn link_name(i: @ast::foreign_item) -> ~str {
alt attr::first_attr_value_str_by_name(i.attrs, ~"link_name") {
- none { return *i.ident; }
- option::some(ln) { return *ln; }
+ none => return *i.ident,
+ option::some(ln) => return *ln
}
}
fn c_arg_and_ret_lltys(ccx: @crate_ctxt,
id: ast::node_id) -> (~[TypeRef], TypeRef, ty::t) {
alt ty::get(ty::node_id_to_type(ccx.tcx, id)).struct {
- ty::ty_fn({inputs: arg_tys, output: ret_ty, _}) {
+ ty::ty_fn({inputs: arg_tys, output: ret_ty, _}) => {
let llargtys = type_of_explicit_args(ccx, arg_tys);
let llretty = type_of::type_of(ccx, ret_ty);
(llargtys, llretty, ret_ty)
}
- _ { ccx.sess.bug(~"c_arg_and_ret_lltys called on non-function type"); }
+ _ => ccx.sess.bug(~"c_arg_and_ret_lltys called on non-function type")
}
}
let n = vec::len(tys.arg_tys);
alt tys.x86_64_tys {
- some(x86_64) {
+ some(x86_64) => {
let mut atys = x86_64.arg_tys;
let mut attrs = x86_64.attrs;
if x86_64.sret {
i += 1u;
}
}
- _ {
+ _ => {
while i < n {
let llargval = load_inbounds(bcx, llargbundle,
~[0u, i]);
llargbundle: ValueRef, llretval: ValueRef) {
let _icx = bcx.insn_ctxt(~"foreign::shim::build_ret");
alt tys.x86_64_tys {
- some(x86_64) {
+ some(x86_64) => {
do vec::iteri(x86_64.attrs) |i, a| {
alt a {
- some(attr) {
+ some(attr) => {
llvm::LLVMAddInstrAttribute(
llretval, (i + 1u) as c_uint,
attr as c_uint);
}
- _ {}
+ _ => ()
}
}
if x86_64.sret || !tys.ret_def {
Store(bcx, llretval, llretloc);
};
}
- _ {
+ _ => {
if tys.ret_def {
let n = vec::len(tys.arg_tys);
// R** llretptr = &args->r;
cc: lib::llvm::CallConv) -> ValueRef {
// Declare the "prototype" for the base function F:
alt tys.x86_64_tys {
- some(x86_64) {
+ some(x86_64) => {
do decl_x86_64_fn(x86_64) |fnty| {
decl_fn(ccx.llmod, lname, cc, fnty)
}
}
- _ {
+ _ => {
let llbasefnty = T_fn(tys.arg_tys, tys.ret_ty);
decl_fn(ccx.llmod, lname, cc, llbasefnty)
}
let mut cc = alt abi {
ast::foreign_abi_rust_intrinsic |
- ast::foreign_abi_cdecl { lib::llvm::CCallConv }
- ast::foreign_abi_stdcall { lib::llvm::X86StdcallCallConv }
+ ast::foreign_abi_cdecl => lib::llvm::CCallConv,
+ ast::foreign_abi_stdcall => lib::llvm::X86StdcallCallConv
};
for vec::each(foreign_mod.items) |foreign_item| {
alt foreign_item.node {
- ast::foreign_item_fn(fn_decl, typarams) {
+ ast::foreign_item_fn(fn_decl, typarams) => {
let id = foreign_item.id;
if abi != ast::foreign_abi_rust_intrinsic {
let llwrapfn = get_item_val(ccx, id);
if typarams.is_empty() {
let llwrapfn = get_item_val(ccx, id);
let path = alt ccx.tcx.items.find(id) {
- some(ast_map::node_foreign_item(_, _, pt)) { pt }
- _ {
+ some(ast_map::node_foreign_item(_, _, pt)) => pt,
+ _ => {
ccx.sess.span_bug(foreign_item.span,
~"can't find intrinsic path")
}
some(substs), some(item.span));
let mut bcx = top_scope_block(fcx, none), lltop = bcx.llbb;
alt check *item.ident {
- ~"atomic_xchng" {
+ ~"atomic_xchng" => {
let old = AtomicRMW(bcx, Xchg,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
SequentiallyConsistent);
Store(bcx, old, fcx.llretptr);
}
- ~"atomic_xchng_acq" {
+ ~"atomic_xchng_acq" => {
let old = AtomicRMW(bcx, Xchg,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
Acquire);
Store(bcx, old, fcx.llretptr);
}
- ~"atomic_xchng_rel" {
+ ~"atomic_xchng_rel" => {
let old = AtomicRMW(bcx, Xchg,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
Release);
Store(bcx, old, fcx.llretptr);
}
- ~"atomic_add" {
+ ~"atomic_add" => {
let old = AtomicRMW(bcx, lib::llvm::Add,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
SequentiallyConsistent);
Store(bcx, old, fcx.llretptr);
}
- ~"atomic_add_acq" {
+ ~"atomic_add_acq" => {
let old = AtomicRMW(bcx, lib::llvm::Add,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
Acquire);
Store(bcx, old, fcx.llretptr);
}
- ~"atomic_add_rel" {
+ ~"atomic_add_rel" => {
let old = AtomicRMW(bcx, lib::llvm::Add,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
Release);
Store(bcx, old, fcx.llretptr);
}
- ~"atomic_sub" {
+ ~"atomic_sub" => {
let old = AtomicRMW(bcx, lib::llvm::Sub,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
SequentiallyConsistent);
Store(bcx, old, fcx.llretptr);
}
- ~"atomic_sub_acq" {
+ ~"atomic_sub_acq" => {
let old = AtomicRMW(bcx, lib::llvm::Sub,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
Acquire);
Store(bcx, old, fcx.llretptr);
}
- ~"atomic_sub_rel" {
+ ~"atomic_sub_rel" => {
let old = AtomicRMW(bcx, lib::llvm::Sub,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
Release);
Store(bcx, old, fcx.llretptr);
}
- ~"size_of" {
+ ~"size_of" => {
let tp_ty = substs.tys[0];
let lltp_ty = type_of::type_of(ccx, tp_ty);
Store(bcx, C_uint(ccx, shape::llsize_of_real(ccx, lltp_ty)),
fcx.llretptr);
}
- ~"move_val" {
+ ~"move_val" => {
let tp_ty = substs.tys[0];
let src = {bcx: bcx,
val: get_param(decl, first_real_arg + 1u),
src,
tp_ty);
}
- ~"move_val_init" {
+ ~"move_val_init" => {
let tp_ty = substs.tys[0];
let src = {bcx: bcx,
val: get_param(decl, first_real_arg + 1u),
src,
tp_ty);
}
- ~"min_align_of" {
+ ~"min_align_of" => {
let tp_ty = substs.tys[0];
let lltp_ty = type_of::type_of(ccx, tp_ty);
Store(bcx, C_uint(ccx, shape::llalign_of_min(ccx, lltp_ty)),
fcx.llretptr);
}
- ~"pref_align_of" {
+ ~"pref_align_of"=> {
let tp_ty = substs.tys[0];
let lltp_ty = type_of::type_of(ccx, tp_ty);
Store(bcx, C_uint(ccx, shape::llalign_of_pref(ccx, lltp_ty)),
fcx.llretptr);
}
- ~"get_tydesc" {
+ ~"get_tydesc" => {
let tp_ty = substs.tys[0];
let static_ti = get_tydesc(ccx, tp_ty);
lazily_emit_all_tydesc_glue(ccx, static_ti);
let td = PointerCast(bcx, static_ti.tydesc, T_ptr(T_nil()));
Store(bcx, td, fcx.llretptr);
}
- ~"init" {
+ ~"init" => {
let tp_ty = substs.tys[0];
let lltp_ty = type_of::type_of(ccx, tp_ty);
if !ty::type_is_nil(tp_ty) {
Store(bcx, C_null(lltp_ty), fcx.llretptr);
}
}
- ~"forget" {}
- ~"reinterpret_cast" {
+ ~"forget" => {}
+ ~"reinterpret_cast" => {
let tp_ty = substs.tys[0];
let lltp_ty = type_of::type_of(ccx, tp_ty);
let llout_ty = type_of::type_of(ccx, substs.tys[1]);
out_sz = shape::llsize_of_real(ccx, llout_ty);
if tp_sz != out_sz {
let sp = alt check ccx.tcx.items.get(option::get(ref_id)) {
- ast_map::node_expr(e) { e.span }
+ ast_map::node_expr(e) => e.span
};
ccx.sess.span_fatal(
sp, fmt!{"reinterpret_cast called on types \
Store(bcx, Load(bcx, cast), fcx.llretptr);
}
}
- ~"addr_of" {
+ ~"addr_of" => {
Store(bcx, get_param(decl, first_real_arg), fcx.llretptr);
}
- ~"needs_drop" {
+ ~"needs_drop" => {
let tp_ty = substs.tys[0];
Store(bcx, C_bool(ty::type_needs_drop(ccx.tcx, tp_ty)),
fcx.llretptr);
}
- ~"visit_tydesc" {
+ ~"visit_tydesc" => {
let td = get_param(decl, first_real_arg);
let visitor = get_param(decl, first_real_arg + 1u);
let td = PointerCast(bcx, td, T_ptr(ccx.tydesc_type));
call_tydesc_glue_full(bcx, visitor, td,
abi::tydesc_field_visit_glue, none);
}
- ~"frame_address" {
+ ~"frame_address" => {
let frameaddress = ccx.intrinsics.get(~"llvm.frameaddress");
let frameaddress_val = Call(bcx, frameaddress, ~[C_i32(0i32)]);
let fty = ty::mk_fn(bcx.tcx(), {
llwrapfn: ValueRef, llargbundle: ValueRef) {
let _icx = bcx.insn_ctxt(~"foreign::foreign::wrap::build_args");
alt tys.x86_64_tys {
- option::some(x86_64) {
+ option::some(x86_64) => {
let mut atys = x86_64.arg_tys;
let mut attrs = x86_64.attrs;
let mut j = 0u;
}
store_inbounds(bcx, llretptr, llargbundle, ~[0u, n]);
}
- _ {
+ _ => {
let llretptr = alloca(bcx, tys.ret_ty);
let n = vec::len(tys.arg_tys);
for uint::range(0u, n) |i| {
llargbundle: ValueRef) {
let _icx = bcx.insn_ctxt(~"foreign::foreign::wrap::build_ret");
alt tys.x86_64_tys {
- option::some(x86_64) {
+ option::some(x86_64) => {
if x86_64.sret || !tys.ret_def {
RetVoid(bcx);
return;
};
Ret(bcx, llretval);
}
- _ {
+ _ => {
let n = vec::len(tys.arg_tys);
let llretval = load_inbounds(bcx, llargbundle, ~[0u, n]);
let llretval = Load(bcx, llretval);
fn abi_of_foreign_fn(ccx: @crate_ctxt, i: @ast::foreign_item)
-> ast::foreign_abi {
alt attr::first_attr_value_str_by_name(i.attrs, ~"abi") {
- none {
- alt check ccx.tcx.items.get(i.id) {
- ast_map::node_foreign_item(_, abi, _) { abi }
- }
+ none => alt check ccx.tcx.items.get(i.id) {
+ ast_map::node_foreign_item(_, abi, _) => abi
}
- some(_) {
- alt attr::foreign_abi(i.attrs) {
- either::right(abi) { abi }
- either::left(msg) { ccx.sess.span_fatal(i.span, msg); }
- }
+ some(_) => alt attr::foreign_abi(i.attrs) {
+ either::right(abi) => abi,
+ either::left(msg) => ccx.sess.span_fatal(i.span, msg)
}
}
}
-> lval_maybe_callee {
let _icx = bcx.insn_ctxt(~"impl::trans_method_callee");
alt mentry.origin {
- typeck::method_static(did) {
+ typeck::method_static(did) => {
let {bcx, val} = trans_self_arg(bcx, self, mentry.derefs);
{env: self_env(val, node_id_type(bcx, self.id), none)
with lval_static_fn(bcx, did, callee_id)}
}
typeck::method_param({trait_id:iid, method_num:off,
- param_num:p, bound_num:b}) {
+ param_num:p, bound_num:b}) => {
alt check bcx.fcx.param_substs {
- some(substs) {
+ some(substs) => {
trans_monomorphized_callee(bcx, callee_id, self, mentry.derefs,
iid, off, p, b, substs)
}
}
}
- typeck::method_trait(_, off) {
+ typeck::method_trait(_, off) => {
let {bcx, val} = trans_temp_expr(bcx, self);
let fty = node_id_type(bcx, callee_id);
trans_trait_callee(bcx, val, fty, off)
name: ast::ident) -> ast::def_id {
if impl_id.crate == ast::local_crate {
alt check ccx.tcx.items.get(impl_id.node) {
- ast_map::node_item(@{node: ast::item_impl(_, _, _, ms), _}, _) {
+ ast_map::node_item(@{node: ast::item_impl(_, _, _, ms), _}, _) => {
method_from_methods(ms, name)
}
ast_map::node_item(@{node:
- ast::item_class(_, _, items, _, _), _}, _) {
+ ast::item_class(_, _, items, _, _), _}, _) => {
let (_,ms) = split_class_items(items);
method_from_methods(ms, name)
}
i_id: ast::def_id) -> uint {
if m_id.crate == ast::local_crate {
alt check ccx.tcx.items.get(m_id.node) {
- ast_map::node_method(m, _, _) { vec::len(m.tps) }
+ ast_map::node_method(m, _, _) => vec::len(m.tps),
}
} else {
csearch::get_type_param_count(ccx.sess.cstore, m_id) -
substs: param_substs) -> lval_maybe_callee {
let _icx = bcx.insn_ctxt(~"impl::trans_monomorphized_callee");
alt find_vtable_in_fn_ctxt(substs, n_param, n_bound) {
- typeck::vtable_static(impl_did, impl_substs, sub_origins) {
+ typeck::vtable_static(impl_did, impl_substs, sub_origins) => {
let ccx = bcx.ccx();
let mname = ty::trait_methods(ccx.tcx, trait_id)[n_method].ident;
let mth_id = method_with_name(bcx.ccx(), impl_did, mname);
ccx, node_id_type(bcx, callee_id))))
with lval}
}
- typeck::vtable_trait(iid, tps) {
+ typeck::vtable_trait(iid, tps) => {
let {bcx, val} = trans_temp_expr(bcx, base);
let fty = node_id_type(bcx, callee_id);
trans_trait_callee(bcx, val, fty, n_method)
}
- typeck::vtable_param(n_param, n_bound) {
+ typeck::vtable_param(n_param, n_bound) => {
fail ~"vtable_param left in monomorphized function's vtable substs";
}
}
for vec::each(*ps.bounds) |bounds| {
if i >= n_param { break; }
for vec::each(*bounds) |bound| {
- alt bound { ty::bound_trait(_) { vtable_off += 1u; } _ {} }
+ alt bound { ty::bound_trait(_) => vtable_off += 1u, _ => () }
}
i += 1u;
}
fn resolve_vtable_in_fn_ctxt(fcx: fn_ctxt, vt: typeck::vtable_origin)
-> typeck::vtable_origin {
alt vt {
- typeck::vtable_static(iid, tys, sub) {
+ typeck::vtable_static(iid, tys, sub) => {
let tys = alt fcx.param_substs {
- some(substs) {
+ some(substs) => {
vec::map(tys, |t| ty::subst_tps(fcx.ccx.tcx, substs.tys, t))
}
- _ { tys }
+ _ => tys
};
typeck::vtable_static(iid, tys, resolve_vtables_in_fn_ctxt(fcx, sub))
}
- typeck::vtable_param(n_param, n_bound) {
+ typeck::vtable_param(n_param, n_bound) => {
alt check fcx.param_substs {
- some(substs) {
+ some(substs) => {
find_vtable_in_fn_ctxt(substs, n_param, n_bound)
}
}
}
- _ { vt }
+ _ => vt
}
}
fn vtable_id(ccx: @crate_ctxt, origin: typeck::vtable_origin) -> mono_id {
alt check origin {
- typeck::vtable_static(impl_id, substs, sub_vtables) {
+ typeck::vtable_static(impl_id, substs, sub_vtables) => {
make_mono_id(ccx, impl_id, substs,
if (*sub_vtables).len() == 0u { none }
else { some(sub_vtables) }, none)
}
- typeck::vtable_trait(trait_id, substs) {
+ typeck::vtable_trait(trait_id, substs) => {
@{def: trait_id,
params: vec::map(substs, |t| mono_precise(t, none))}
}
-> ValueRef {
let hash_id = vtable_id(ccx, origin);
alt ccx.vtables.find(hash_id) {
- some(val) { val }
- none {
- alt check origin {
- typeck::vtable_static(id, substs, sub_vtables) {
+ some(val) => val,
+ none => alt check origin {
+ typeck::vtable_static(id, substs, sub_vtables) => {
make_impl_vtable(ccx, id, substs, sub_vtables)
- }
}
}
}
let mut found_export = false;
for vec::each(vis) |vi| {
alt vi.node {
- view_item_export(vps) {
+ view_item_export(vps) => {
found_export = true;
for vec::each(vps) |vp| {
alt vp.node {
view_path_simple(_, _, id) | view_path_glob(_, id) |
- view_path_list(_, _, id) {
+ view_path_list(_, _, id) => {
traverse_export(cx, id);
}
}
}
}
- _ {}
+ _ => ()
}
}
found_export
fn traverse_def_id(cx: ctx, did: def_id) {
if did.crate != local_crate { return; }
let n = alt cx.tcx.items.find(did.node) {
- none { return; } // This can happen for self, for example
- some(n) { n }
+ none => return, // This can happen for self, for example
+ some(n) => n
};
alt n {
- ast_map::node_item(item, _) { traverse_public_item(cx, item); }
- ast_map::node_method(_, impl_id, _) { traverse_def_id(cx, impl_id); }
- ast_map::node_foreign_item(item, _, _) { cx.rmap.insert(item.id, ()); }
- ast_map::node_variant(v, _, _) { cx.rmap.insert(v.node.id, ()); }
+ ast_map::node_item(item, _) => traverse_public_item(cx, item),
+ ast_map::node_method(_, impl_id, _) => traverse_def_id(cx, impl_id),
+ ast_map::node_foreign_item(item, _, _) => {
+ cx.rmap.insert(item.id, ());
+ }
+ ast_map::node_variant(v, _, _) => { cx.rmap.insert(v.node.id, ()); }
// If it's a ctor, consider the parent reachable
- ast_map::node_ctor(_, _, _, parent_id, _) {
+ ast_map::node_ctor(_, _, _, parent_id, _) => {
traverse_def_id(cx, parent_id);
}
- _ {}
+ _ => ()
}
}
if cx.rmap.contains_key(item.id) { return; }
cx.rmap.insert(item.id, ());
alt item.node {
- item_mod(m) { traverse_public_mod(cx, m); }
- item_foreign_mod(nm) {
+ item_mod(m) => traverse_public_mod(cx, m),
+ item_foreign_mod(nm) => {
if !traverse_exports(cx, nm.view_items) {
for vec::each(nm.items) |item| { cx.rmap.insert(item.id, ()); }
}
}
- item_fn(_, tps, blk) {
+ item_fn(_, tps, blk) => {
if tps.len() > 0u ||
attr::find_inline_attr(item.attrs) != attr::ia_none {
traverse_inline_body(cx, blk);
}
}
- item_impl(tps, _, _, ms) {
+ item_impl(tps, _, _, ms) => {
for vec::each(ms) |m| {
if tps.len() > 0u || m.tps.len() > 0u ||
attr::find_inline_attr(m.attrs) != attr::ia_none {
}
}
}
- item_class(tps, _traits, items, m_ctor, m_dtor) {
+ item_class(tps, _traits, items, m_ctor, m_dtor) => {
do option::iter(m_ctor) |ctor| {
cx.rmap.insert(ctor.node.id, ());
if tps.len() > 0u || attr::find_inline_attr(ctor.node.attrs)
}
for vec::each(items) |item| {
alt item.node {
- class_method(m) {
+ class_method(m) => {
cx.rmap.insert(m.id, ());
if tps.len() > 0u ||
attr::find_inline_attr(m.attrs) != attr::ia_none {
traverse_inline_body(cx, m.body);
}
}
- _ {}
+ _ => ()
}
}
}
- item_ty(t, _) {
+ item_ty(t, _) => {
traverse_ty(t, cx, mk_ty_visitor());
}
item_const(*) |
- item_enum(*) | item_trait(*) {}
- item_mac(*) { fail ~"item macros unimplemented" }
+ item_enum(*) | item_trait(*) => (),
+ item_mac(*) => fail ~"item macros unimplemented"
}
}
cx.rmap.insert(ty.id, ());
alt ty.node {
- ty_path(p, p_id) {
+ ty_path(p, p_id) => {
alt cx.tcx.def_map.find(p_id) {
// Kind of a hack to check this here, but I'm not sure what else
// to do
- some(def_prim_ty(_)) { /* do nothing */ }
- some(d) { traverse_def_id(cx, def_id_of_def(d)); }
- none { /* do nothing -- but should we fail here? */ }
+ some(def_prim_ty(_)) => { /* do nothing */ }
+ some(d) => traverse_def_id(cx, def_id_of_def(d)),
+ none => { /* do nothing -- but should we fail here? */ }
}
for p.types.each |t| { v.visit_ty(t, cx, v); };
}
- _ { visit::visit_ty(ty, cx, v); }
+ _ => visit::visit_ty(ty, cx, v)
}
}
fn traverse_inline_body(cx: ctx, body: blk) {
fn traverse_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
alt e.node {
- expr_path(_) {
+ expr_path(_) => {
alt cx.tcx.def_map.find(e.id) {
- some(d) {
+ some(d) => {
traverse_def_id(cx, def_id_of_def(d));
}
- none { cx.tcx.sess.span_bug(e.span, fmt!{"Unbound node \
- id %? while traversing %s", e.id, expr_to_str(e)}); }
+ none => cx.tcx.sess.span_bug(e.span, fmt!{"Unbound node \
+ id %? while traversing %s", e.id, expr_to_str(e)})
}
}
- expr_field(_, _, _) {
+ expr_field(_, _, _) => {
alt cx.method_map.find(e.id) {
- some({origin: typeck::method_static(did), _}) {
+ some({origin: typeck::method_static(did), _}) => {
traverse_def_id(cx, did);
}
- _ {}
+ _ => ()
}
}
- _ {}
+ _ => ()
}
visit::visit_expr(e, cx, v);
}
visit_item: |i, cx, v| {
visit::visit_item(i, cx, v);
alt i.node {
- item_class(_, _, _, _, some(_)) {
+ item_class(_, _, _, _, some(_)) => {
traverse_public_item(cx, i);
}
- item_impl(*) {
+ item_impl(*) => {
traverse_public_item(cx, i);
}
- _ {}
+ _ => ()
}
}
with *visit::default_visitor()
vstore: ty::vstore,
f: fn(~str,~[ValueRef])) {
alt vstore {
- ty::vstore_fixed(n) {
+ ty::vstore_fixed(n) => {
let extra = vec::append(~[self.c_uint(n)],
self.c_size_and_align(t));
f(~"fixed", extra)
}
- ty::vstore_slice(_) { f(~"slice", ~[]) }
- ty::vstore_uniq { f(~"uniq", ~[]);}
- ty::vstore_box { f(~"box", ~[]); }
+ ty::vstore_slice(_) => f(~"slice", ~[]),
+ ty::vstore_uniq => f(~"uniq", ~[]),
+ ty::vstore_box => f(~"box", ~[])
}
}
ty_to_str(bcx.ccx().tcx, t)};
alt ty::get(t).struct {
- ty::ty_bot { self.leaf(~"bot") }
- ty::ty_nil { self.leaf(~"nil") }
- ty::ty_bool { self.leaf(~"bool") }
- ty::ty_int(ast::ty_i) { self.leaf(~"int") }
- ty::ty_int(ast::ty_char) { self.leaf(~"char") }
- ty::ty_int(ast::ty_i8) { self.leaf(~"i8") }
- ty::ty_int(ast::ty_i16) { self.leaf(~"i16") }
- ty::ty_int(ast::ty_i32) { self.leaf(~"i32") }
- ty::ty_int(ast::ty_i64) { self.leaf(~"i64") }
- ty::ty_uint(ast::ty_u) { self.leaf(~"uint") }
- ty::ty_uint(ast::ty_u8) { self.leaf(~"u8") }
- ty::ty_uint(ast::ty_u16) { self.leaf(~"u16") }
- ty::ty_uint(ast::ty_u32) { self.leaf(~"u32") }
- ty::ty_uint(ast::ty_u64) { self.leaf(~"u64") }
- ty::ty_float(ast::ty_f) { self.leaf(~"float") }
- ty::ty_float(ast::ty_f32) { self.leaf(~"f32") }
- ty::ty_float(ast::ty_f64) { self.leaf(~"f64") }
+ ty::ty_bot => self.leaf(~"bot"),
+ ty::ty_nil => self.leaf(~"nil"),
+ ty::ty_bool => self.leaf(~"bool"),
+ ty::ty_int(ast::ty_i) => self.leaf(~"int"),
+ ty::ty_int(ast::ty_char) => self.leaf(~"char"),
+ ty::ty_int(ast::ty_i8) => self.leaf(~"i8"),
+ ty::ty_int(ast::ty_i16) => self.leaf(~"i16"),
+ ty::ty_int(ast::ty_i32) => self.leaf(~"i32"),
+ ty::ty_int(ast::ty_i64) => self.leaf(~"i64"),
+ ty::ty_uint(ast::ty_u) => self.leaf(~"uint"),
+ ty::ty_uint(ast::ty_u8) => self.leaf(~"u8"),
+ ty::ty_uint(ast::ty_u16) => self.leaf(~"u16"),
+ ty::ty_uint(ast::ty_u32) => self.leaf(~"u32"),
+ ty::ty_uint(ast::ty_u64) => self.leaf(~"u64"),
+ ty::ty_float(ast::ty_f) => self.leaf(~"float"),
+ ty::ty_float(ast::ty_f32) => self.leaf(~"f32"),
+ ty::ty_float(ast::ty_f64) => self.leaf(~"f64"),
- ty::ty_unboxed_vec(mt) { self.visit(~"vec", self.c_mt(mt)) }
- ty::ty_estr(vst) {
+ ty::ty_unboxed_vec(mt) => self.visit(~"vec", self.c_mt(mt)),
+ ty::ty_estr(vst) => {
do self.vstore_name_and_extra(t, vst) |name, extra| {
self.visit(~"estr_" + name, extra)
}
}
- ty::ty_evec(mt, vst) {
+ ty::ty_evec(mt, vst) => {
do self.vstore_name_and_extra(t, vst) |name, extra| {
self.visit(~"evec_" + name, extra +
self.c_mt(mt))
}
}
- ty::ty_box(mt) { self.visit(~"box", self.c_mt(mt)) }
- ty::ty_uniq(mt) { self.visit(~"uniq", self.c_mt(mt)) }
- ty::ty_ptr(mt) { self.visit(~"ptr", self.c_mt(mt)) }
- ty::ty_rptr(_, mt) { self.visit(~"rptr", self.c_mt(mt)) }
+ ty::ty_box(mt) => self.visit(~"box", self.c_mt(mt)),
+ ty::ty_uniq(mt) => self.visit(~"uniq", self.c_mt(mt)),
+ ty::ty_ptr(mt) => self.visit(~"ptr", self.c_mt(mt)),
+ ty::ty_rptr(_, mt) => self.visit(~"rptr", self.c_mt(mt)),
- ty::ty_rec(fields) {
+ ty::ty_rec(fields) => {
do self.bracketed(~"rec",
~[self.c_uint(vec::len(fields))]
+ self.c_size_and_align(t)) {
}
}
- ty::ty_tup(tys) {
+ ty::ty_tup(tys) => {
do self.bracketed(~"tup",
~[self.c_uint(vec::len(tys))]
+ self.c_size_and_align(t)) {
// FIXME (#2594): fetch constants out of intrinsic:: for the
// numbers.
- ty::ty_fn(fty) {
+ ty::ty_fn(fty) => {
let pureval = alt fty.purity {
- ast::pure_fn { 0u }
- ast::unsafe_fn { 1u }
- ast::impure_fn { 2u }
- ast::extern_fn { 3u }
+ ast::pure_fn => 0u,
+ ast::unsafe_fn => 1u,
+ ast::impure_fn => 2u,
+ ast::extern_fn => 3u
};
let protoval = alt fty.proto {
- ast::proto_bare { 0u }
- ast::proto_uniq { 2u }
- ast::proto_box { 3u }
- ast::proto_block { 4u }
+ ast::proto_bare => 0u,
+ ast::proto_uniq => 2u,
+ ast::proto_box => 3u,
+ ast::proto_block => 4u
};
let retval = alt fty.ret_style {
- ast::noreturn { 0u }
- ast::return_val { 1u }
+ ast::noreturn => 0u,
+ ast::return_val => 1u
};
let extra = ~[self.c_uint(pureval),
self.c_uint(protoval),
self.visit(~"enter_fn", extra);
for fty.inputs.eachi |i, arg| {
let modeval = alt arg.mode {
- ast::infer(_) { 0u }
- ast::expl(e) {
- alt e {
- ast::by_ref { 1u }
- ast::by_val { 2u }
- ast::by_mutbl_ref { 3u }
- ast::by_move { 4u }
- ast::by_copy { 5u }
- }
+ ast::infer(_) => 0u,
+ ast::expl(e) => alt e {
+ ast::by_ref => 1u,
+ ast::by_val => 2u,
+ ast::by_mutbl_ref => 3u,
+ ast::by_move => 4u,
+ ast::by_copy => 5u
}
};
self.visit(~"fn_input",
self.visit(~"leave_fn", extra);
}
- ty::ty_class(did, substs) {
+ ty::ty_class(did, substs) => {
let bcx = self.bcx;
let tcx = bcx.ccx().tcx;
let fields = ty::class_items_as_fields(tcx, did, substs);
// not ideal. It'll work but will get costly on big enums. Maybe
// let the visitor tell us if it wants to visit only a particular
// variant?
- ty::ty_enum(did, substs) {
+ ty::ty_enum(did, substs) => {
let bcx = self.bcx;
let tcx = bcx.ccx().tcx;
let variants = ty::substd_enum_variants(tcx, did, substs);
}
// Miscallaneous extra types
- ty::ty_trait(_, _) { self.leaf(~"trait") }
- ty::ty_var(_) { self.leaf(~"var") }
- ty::ty_var_integral(_) { self.leaf(~"var_integral") }
- ty::ty_param(p) { self.visit(~"param", ~[self.c_uint(p.idx)]) }
- ty::ty_self { self.leaf(~"self") }
- ty::ty_type { self.leaf(~"type") }
- ty::ty_opaque_box { self.leaf(~"opaque_box") }
- ty::ty_opaque_closure_ptr(ck) {
+ ty::ty_trait(_, _) => self.leaf(~"trait"),
+ ty::ty_var(_) => self.leaf(~"var"),
+ ty::ty_var_integral(_) => self.leaf(~"var_integral"),
+ ty::ty_param(p) => self.visit(~"param", ~[self.c_uint(p.idx)]),
+ ty::ty_self => self.leaf(~"self"),
+ ty::ty_type => self.leaf(~"type"),
+ ty::ty_opaque_box => self.leaf(~"opaque_box"),
+ ty::ty_opaque_closure_ptr(ck) => {
let ckval = alt ck {
- ty::ck_block { 0u }
- ty::ck_box { 1u }
- ty::ck_uniq { 2u }
+ ty::ck_block => 0u,
+ ty::ck_box => 1u,
+ ty::ck_uniq => 2u
};
self.visit(~"closure_ptr", ~[self.c_uint(ckval)])
}
// Returns the code corresponding to the pointer size on this architecture.
fn s_int(tcx: ty_ctxt) -> u8 {
return alt tcx.sess.targ_cfg.arch {
- session::arch_x86 { shape_i32 }
- session::arch_x86_64 { shape_i64 }
- session::arch_arm { shape_i32 }
+ session::arch_x86 => shape_i32,
+ session::arch_x86_64 => shape_i64,
+ session::arch_arm => shape_i32
};
}
fn s_uint(tcx: ty_ctxt) -> u8 {
return alt tcx.sess.targ_cfg.arch {
- session::arch_x86 { shape_u32 }
- session::arch_x86_64 { shape_u64 }
- session::arch_arm { shape_u32 }
+ session::arch_x86 => shape_u32,
+ session::arch_x86_64 => shape_u64,
+ session::arch_arm => shape_u32
};
}
fn s_float(tcx: ty_ctxt) -> u8 {
return alt tcx.sess.targ_cfg.arch {
- session::arch_x86 { shape_f64 }
- session::arch_x86_64 { shape_f64 }
- session::arch_arm { shape_f64 }
+ session::arch_x86 => shape_f64,
+ session::arch_x86_64 => shape_f64,
+ session::arch_arm => shape_f64
};
}
fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] {
alt ty::get(t).struct {
ty::ty_nil | ty::ty_bool | ty::ty_uint(ast::ty_u8) |
- ty::ty_bot { ~[shape_u8] }
- ty::ty_int(ast::ty_i) { ~[s_int(ccx.tcx)] }
- ty::ty_float(ast::ty_f) { ~[s_float(ccx.tcx)] }
- ty::ty_uint(ast::ty_u) | ty::ty_ptr(_) { ~[s_uint(ccx.tcx)] }
- ty::ty_type { ~[s_tydesc(ccx.tcx)] }
- ty::ty_int(ast::ty_i8) { ~[shape_i8] }
- ty::ty_uint(ast::ty_u16) { ~[shape_u16] }
- ty::ty_int(ast::ty_i16) { ~[shape_i16] }
- ty::ty_uint(ast::ty_u32) { ~[shape_u32] }
- ty::ty_int(ast::ty_i32) | ty::ty_int(ast::ty_char) { ~[shape_i32] }
- ty::ty_uint(ast::ty_u64) { ~[shape_u64] }
- ty::ty_int(ast::ty_i64) { ~[shape_i64] }
- ty::ty_float(ast::ty_f32) { ~[shape_f32] }
- ty::ty_float(ast::ty_f64) { ~[shape_f64] }
- ty::ty_estr(ty::vstore_uniq) {
+ ty::ty_bot => ~[shape_u8],
+ ty::ty_int(ast::ty_i) => ~[s_int(ccx.tcx)],
+ ty::ty_float(ast::ty_f) => ~[s_float(ccx.tcx)],
+ ty::ty_uint(ast::ty_u) | ty::ty_ptr(_) => ~[s_uint(ccx.tcx)],
+ ty::ty_type => ~[s_tydesc(ccx.tcx)],
+ ty::ty_int(ast::ty_i8) => ~[shape_i8],
+ ty::ty_uint(ast::ty_u16) => ~[shape_u16],
+ ty::ty_int(ast::ty_i16) => ~[shape_i16],
+ ty::ty_uint(ast::ty_u32) => ~[shape_u32],
+ ty::ty_int(ast::ty_i32) | ty::ty_int(ast::ty_char) => ~[shape_i32],
+ ty::ty_uint(ast::ty_u64) => ~[shape_u64],
+ ty::ty_int(ast::ty_i64) => ~[shape_i64],
+ ty::ty_float(ast::ty_f32) => ~[shape_f32],
+ ty::ty_float(ast::ty_f64) => ~[shape_f64],
+ ty::ty_estr(ty::vstore_uniq) => {
shape_of(ccx, tvec::expand_boxed_vec_ty(ccx.tcx, t))
}
- ty::ty_enum(did, substs) {
+ ty::ty_enum(did, substs) => {
alt enum_kind(ccx, did) {
- tk_unit { ~[s_variant_enum_t(ccx.tcx)] }
- tk_enum { ~[s_variant_enum_t(ccx.tcx)] }
- tk_newtype | tk_complex {
+ tk_unit => ~[s_variant_enum_t(ccx.tcx)],
+ tk_enum => ~[s_variant_enum_t(ccx.tcx)],
+ tk_newtype | tk_complex => {
let mut s = ~[shape_enum], id;
let nom_id = mk_nominal_id(ccx.tcx, did, none, substs.tps);
alt ccx.shape_cx.tag_id_to_index.find(nom_id) {
- none {
+ none => {
id = ccx.shape_cx.next_tag_id;
ccx.shape_cx.tag_id_to_index.insert(nom_id, id);
ccx.shape_cx.tag_order.push({did: did, substs: substs});
ccx.shape_cx.next_tag_id += 1u16;
}
- some(existing_id) { id = existing_id; }
+ some(existing_id) => id = existing_id,
}
add_u16(s, id as u16);
}
ty::ty_estr(ty::vstore_box) |
ty::ty_evec(_, ty::vstore_box) |
- ty::ty_box(_) | ty::ty_opaque_box { ~[shape_box] }
- ty::ty_uniq(mt) {
+ ty::ty_box(_) | ty::ty_opaque_box => ~[shape_box],
+ ty::ty_uniq(mt) => {
let mut s = ~[shape_uniq];
add_substr(s, shape_of(ccx, mt.ty));
s
}
- ty::ty_unboxed_vec(mt) {
+ ty::ty_unboxed_vec(mt) => {
let mut s = ~[shape_unboxed_vec];
add_bool(s, ty::type_is_pod(ccx.tcx, mt.ty));
add_substr(s, shape_of(ccx, mt.ty));
s
}
- ty::ty_evec(mt, ty::vstore_uniq) {
+ ty::ty_evec(mt, ty::vstore_uniq) => {
shape_of(ccx, tvec::expand_boxed_vec_ty(ccx.tcx, t))
}
- ty::ty_estr(ty::vstore_fixed(n)) {
+ ty::ty_estr(ty::vstore_fixed(n)) => {
let mut s = ~[shape_fixedvec];
let u8_t = ty::mk_mach_uint(ccx.tcx, ast::ty_u8);
assert (n + 1u) <= 0xffffu;
s
}
- ty::ty_evec(mt, ty::vstore_fixed(n)) {
+ ty::ty_evec(mt, ty::vstore_fixed(n)) => {
let mut s = ~[shape_fixedvec];
assert n <= 0xffffu;
add_u16(s, n as u16);
s
}
- ty::ty_estr(ty::vstore_slice(r)) {
+ ty::ty_estr(ty::vstore_slice(r)) => {
let mut s = ~[shape_slice];
let u8_t = ty::mk_mach_uint(ccx.tcx, ast::ty_u8);
add_bool(s, true); // is_pod
s
}
- ty::ty_evec(mt, ty::vstore_slice(r)) {
+ ty::ty_evec(mt, ty::vstore_slice(r)) => {
let mut s = ~[shape_slice];
add_bool(s, ty::type_is_pod(ccx.tcx, mt.ty));
add_bool(s, false); // is_str
s
}
- ty::ty_rec(fields) {
+ ty::ty_rec(fields) => {
let mut s = ~[shape_struct], sub = ~[];
for vec::each(fields) |f| {
sub += shape_of(ccx, f.mt.ty);
add_substr(s, sub);
s
}
- ty::ty_tup(elts) {
+ ty::ty_tup(elts) => {
let mut s = ~[shape_struct], sub = ~[];
for vec::each(elts) |elt| {
sub += shape_of(ccx, elt);
add_substr(s, sub);
s
}
- ty::ty_trait(_, _) { ~[shape_box_fn] }
- ty::ty_class(did, substs) {
+ ty::ty_trait(_, _) => ~[shape_box_fn],
+ ty::ty_class(did, substs) => {
// same as records, unless there's a dtor
let tps = substs.tps;
let m_dtor_did = ty::ty_dtor(ccx.tcx, did);
add_substr(s, sub);
s
}
- ty::ty_rptr(_, mt) {
+ ty::ty_rptr(_, mt) => {
let mut s = ~[shape_rptr];
add_substr(s, shape_of(ccx, mt.ty));
s
}
- ty::ty_param(*) {
+ ty::ty_param(*) => {
ccx.tcx.sess.bug(~"non-monomorphized type parameter");
}
- ty::ty_fn({proto: ast::proto_box, _}) { ~[shape_box_fn] }
- ty::ty_fn({proto: ast::proto_uniq, _}) { ~[shape_uniq_fn] }
- ty::ty_fn({proto: ast::proto_block, _}) { ~[shape_stack_fn] }
- ty::ty_fn({proto: ast::proto_bare, _}) { ~[shape_bare_fn] }
- ty::ty_opaque_closure_ptr(_) { ~[shape_opaque_closure_ptr] }
- ty::ty_var(_) | ty::ty_var_integral(_) | ty::ty_self {
+ ty::ty_fn({proto: ast::proto_box, _}) => ~[shape_box_fn],
+ ty::ty_fn({proto: ast::proto_uniq, _}) => ~[shape_uniq_fn],
+ ty::ty_fn({proto: ast::proto_block, _}) => ~[shape_stack_fn],
+ ty::ty_fn({proto: ast::proto_bare, _}) => ~[shape_bare_fn],
+ ty::ty_opaque_closure_ptr(_) => ~[shape_opaque_closure_ptr],
+ ty::ty_var(_) | ty::ty_var_integral(_) | ty::ty_self => {
ccx.sess.bug(~"shape_of: unexpected type struct found");
}
}
fn static_size_of_enum(cx: @crate_ctxt, t: ty::t) -> uint {
if cx.enum_sizes.contains_key(t) { return cx.enum_sizes.get(t); }
alt ty::get(t).struct {
- ty::ty_enum(tid, substs) {
+ ty::ty_enum(tid, substs) => {
// Compute max(variant sizes).
let mut max_size = 0u;
let variants = ty::enum_variants(cx.tcx, tid);
cx.enum_sizes.insert(t, max_size);
return max_size;
}
- _ { cx.sess.bug(~"static_size_of_enum called on non-enum"); }
+ _ => cx.sess.bug(~"static_size_of_enum called on non-enum")
}
}
ty::ty_box(_) | ty::ty_opaque_box | ty::ty_uniq(_) |
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_evec(_, ty::vstore_box) |
ty::ty_estr(ty::vstore_uniq) | ty::ty_estr(ty::vstore_box) |
- ty::ty_ptr(_) | ty::ty_rptr(_,_) { nilptr(tcx) }
- ty::ty_fn(_) { ty::mk_tup(tcx, ~[nilptr(tcx), nilptr(tcx)]) }
+ ty::ty_ptr(_) | ty::ty_rptr(_,_) => nilptr(tcx),
+ ty::ty_fn(_) => ty::mk_tup(tcx, ~[nilptr(tcx), nilptr(tcx)]),
ty::ty_evec(_, ty::vstore_slice(_)) |
- ty::ty_estr(ty::vstore_slice(_)) {
+ ty::ty_estr(ty::vstore_slice(_)) => {
ty::mk_tup(tcx, ~[nilptr(tcx), ty::mk_int(tcx)])
}
// Reduce a class type to a record type in which all the fields are
// simplified
- ty::ty_class(did, substs) {
+ ty::ty_class(did, substs) => {
let simpl_fields = (if is_some(ty::ty_dtor(tcx, did)) {
// remember the drop flag
~[{ident: @~"drop", mt: {ty:
};
ty::mk_rec(tcx, simpl_fields)
}
- _ { typ }
+ _ => typ
}
}
ty::fold_ty(tcx, typ, |t| simplifier(tcx, t))
let unit_ty = ty::sequence_element_type(tcx, t);
let unboxed_vec_ty = ty::mk_mut_unboxed_vec(tcx, unit_ty);
alt ty::get(t).struct {
- ty::ty_estr(ty::vstore_uniq) | ty::ty_evec(_, ty::vstore_uniq) {
+ ty::ty_estr(ty::vstore_uniq) | ty::ty_evec(_, ty::vstore_uniq) => {
ty::mk_imm_uniq(tcx, unboxed_vec_ty)
}
- ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) {
+ ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) => {
ty::mk_imm_box(tcx, unboxed_vec_ty)
}
- _ { tcx.sess.bug(~"non boxed-vec type \
- in tvec::expand_boxed_vec_ty");
- }
+ _ => tcx.sess.bug(~"non boxed-vec type \
+ in tvec::expand_boxed_vec_ty")
}
}
let mut {bcx, val, dataptr} =
alt vst {
- ast::vstore_fixed(_) {
+ ast::vstore_fixed(_) => {
// Destination should be pre-allocated for us.
let v = alt dest {
- base::save_in(v) {
+ base::save_in(v) => {
PointerCast(bcx, v, T_ptr(llunitty))
}
- _ {
+ _ => {
bcx.ccx().sess.bug(~"bad dest for vstore_fixed \
in tvec::trans_evec");
}
};
{bcx: bcx, val: v, dataptr: v}
}
- ast::vstore_slice(_) {
+ ast::vstore_slice(_) => {
// Make a fake type to use for the cleanup
let ty = ty::mk_evec(bcx.tcx(),
{ty: unit_ty, mutbl: ast::m_mutbl},
{bcx: bcx, val: p, dataptr: vp}
}
- ast::vstore_uniq {
+ ast::vstore_uniq => {
let {bcx, val} = alloc_vec(bcx, unit_ty, count, heap_exchange);
add_clean_free(bcx, val, heap_exchange);
let dataptr = get_dataptr(bcx, get_bodyptr(bcx, val));
{bcx: bcx, val: val, dataptr: dataptr}
}
- ast::vstore_box {
+ ast::vstore_box => {
let {bcx, val} = alloc_vec(bcx, unit_ty, count, heap_shared);
add_clean_free(bcx, val, heap_shared);
let dataptr = get_dataptr(bcx, get_bodyptr(bcx, val));
for vec::each(temp_cleanups) |cln| { revoke_clean(bcx, cln); }
alt vst {
- ast::vstore_fixed(_) {
+ ast::vstore_fixed(_) => {
// We wrote into the destination in the fixed case.
return bcx;
}
- ast::vstore_slice(_) {
+ ast::vstore_slice(_) => {
return base::store_in_dest(bcx, Load(bcx, val), dest);
}
- _ {
+ _ => {
return base::store_in_dest(bcx, val, dest);
}
}
let unit_sz = llsize_of(ccx, llunitty);
let vstore = alt ty::get(vec_ty).struct {
- ty::ty_estr(vst) | ty::ty_evec(_, vst) { vst }
- _ { ty::vstore_uniq }
+ ty::ty_estr(vst) | ty::ty_evec(_, vst) => vst,
+ _ => ty::vstore_uniq
};
alt vstore {
- ty::vstore_fixed(n) {
+ ty::vstore_fixed(n) => {
let base = GEPi(cx, v, ~[0u, 0u]);
let n = if ty::type_is_str(e_ty) { n + 1u } else { n };
let len = Mul(cx, C_uint(ccx, n), unit_sz);
(base, len)
}
- ty::vstore_slice(_) {
+ ty::vstore_slice(_) => {
let base = Load(cx, GEPi(cx, v, ~[0u, abi::slice_elt_base]));
let len = Load(cx, GEPi(cx, v, ~[0u, abi::slice_elt_len]));
(base, len)
}
- ty::vstore_uniq | ty::vstore_box {
+ ty::vstore_uniq | ty::vstore_box => {
debug!{"get_base_and_len: %s", val_str(ccx.tn, v)};
let body = tvec::get_bodyptr(cx, v);
(tvec::get_dataptr(cx, body), tvec::get_fill(cx, body))
let arg_ty = arg.ty;
let llty = type_of(cx, arg_ty);
alt ty::resolved_mode(cx.tcx, arg.mode) {
- ast::by_val { llty }
- _ { T_ptr(llty) }
+ ast::by_val => llty,
+ _ => T_ptr(llty)
}
}
}
type_of_non_gc_box(cx, t_norm)
} else {
alt ty::get(t).struct {
- ty::ty_box(mt) {
+ ty::ty_box(mt) => {
T_ptr(T_box(cx, type_of(cx, mt.ty)))
}
- ty::ty_uniq(mt) {
+ ty::ty_uniq(mt) => {
T_ptr(T_unique(cx, type_of(cx, mt.ty)))
}
- _ {
+ _ => {
cx.sess.bug(~"non-box in type_of_non_gc_box");
}
}
cx.lltypes.insert(t, llty);
} else {
llty = alt ty::get(t).struct {
- ty::ty_nil | ty::ty_bot { T_nil() }
- ty::ty_bool { T_bool() }
- ty::ty_int(t) { T_int_ty(cx, t) }
- ty::ty_uint(t) { T_uint_ty(cx, t) }
- ty::ty_float(t) { T_float_ty(cx, t) }
- ty::ty_estr(ty::vstore_uniq) {
+ ty::ty_nil | ty::ty_bot => T_nil(),
+ ty::ty_bool => T_bool(),
+ ty::ty_int(t) => T_int_ty(cx, t),
+ ty::ty_uint(t) => T_uint_ty(cx, t),
+ ty::ty_float(t) => T_float_ty(cx, t),
+ ty::ty_estr(ty::vstore_uniq) => {
T_unique_ptr(T_unique(cx, T_vec(cx, T_i8())))
}
- ty::ty_enum(did, _) { type_of_enum(cx, did, t) }
- ty::ty_estr(ty::vstore_box) {
+ ty::ty_enum(did, _) => type_of_enum(cx, did, t),
+ ty::ty_estr(ty::vstore_box) => {
T_box_ptr(T_box(cx, T_vec(cx, T_i8())))
}
- ty::ty_evec(mt, ty::vstore_box) {
+ ty::ty_evec(mt, ty::vstore_box) => {
T_box_ptr(T_box(cx, T_vec(cx, type_of(cx, mt.ty))))
}
- ty::ty_box(mt) { T_box_ptr(T_box(cx, type_of(cx, mt.ty))) }
- ty::ty_opaque_box { T_box_ptr(T_box(cx, T_i8())) }
- ty::ty_uniq(mt) { T_unique_ptr(T_unique(cx, type_of(cx, mt.ty))) }
- ty::ty_evec(mt, ty::vstore_uniq) {
+ ty::ty_box(mt) => T_box_ptr(T_box(cx, type_of(cx, mt.ty))),
+ ty::ty_opaque_box => T_box_ptr(T_box(cx, T_i8())),
+ ty::ty_uniq(mt) => T_unique_ptr(T_unique(cx, type_of(cx, mt.ty))),
+ ty::ty_evec(mt, ty::vstore_uniq) => {
T_unique_ptr(T_unique(cx, T_vec(cx, type_of(cx, mt.ty))))
}
- ty::ty_unboxed_vec(mt) {
+ ty::ty_unboxed_vec(mt) => {
T_vec(cx, type_of(cx, mt.ty))
}
- ty::ty_ptr(mt) { T_ptr(type_of(cx, mt.ty)) }
- ty::ty_rptr(_, mt) { T_ptr(type_of(cx, mt.ty)) }
+ ty::ty_ptr(mt) => T_ptr(type_of(cx, mt.ty)),
+ ty::ty_rptr(_, mt) => T_ptr(type_of(cx, mt.ty)),
- ty::ty_evec(mt, ty::vstore_slice(_)) {
+ ty::ty_evec(mt, ty::vstore_slice(_)) => {
T_struct(~[T_ptr(type_of(cx, mt.ty)),
T_uint_ty(cx, ast::ty_u)])
}
- ty::ty_estr(ty::vstore_slice(_)) {
+ ty::ty_estr(ty::vstore_slice(_)) => {
T_struct(~[T_ptr(T_i8()),
T_uint_ty(cx, ast::ty_u)])
}
- ty::ty_estr(ty::vstore_fixed(n)) {
+ ty::ty_estr(ty::vstore_fixed(n)) => {
T_array(T_i8(), n + 1u /* +1 for trailing null */)
}
- ty::ty_evec(mt, ty::vstore_fixed(n)) {
+ ty::ty_evec(mt, ty::vstore_fixed(n)) => {
T_array(type_of(cx, mt.ty), n)
}
- ty::ty_rec(fields) {
+ ty::ty_rec(fields) => {
let mut tys: ~[TypeRef] = ~[];
for vec::each(fields) |f| {
let mt_ty = f.mt.ty;
}
T_struct(tys)
}
- ty::ty_fn(_) { T_fn_pair(cx, type_of_fn_from_ty(cx, t)) }
- ty::ty_trait(_, _) { T_opaque_trait(cx) }
- ty::ty_type { T_ptr(cx.tydesc_type) }
- ty::ty_tup(elts) {
+ ty::ty_fn(_) => T_fn_pair(cx, type_of_fn_from_ty(cx, t)),
+ ty::ty_trait(_, _) => T_opaque_trait(cx),
+ ty::ty_type => T_ptr(cx.tydesc_type),
+ ty::ty_tup(elts) => {
let mut tys = ~[];
for vec::each(elts) |elt| {
vec::push(tys, type_of(cx, elt));
}
T_struct(tys)
}
- ty::ty_opaque_closure_ptr(_) { T_opaque_box_ptr(cx) }
- ty::ty_class(*) {
+ ty::ty_opaque_closure_ptr(_) => T_opaque_box_ptr(cx),
+ ty::ty_class(*) => {
// Only create the named struct, but don't fill it in. We fill it
// in *after* placing it into the type cache. This prevents
// infinite recursion with recursive class types.
common::T_named_struct(llvm_type_name(cx, t))
}
- ty::ty_self { cx.tcx.sess.unimpl(~"type_of: ty_self"); }
- ty::ty_var(_) { cx.tcx.sess.bug(~"type_of with ty_var"); }
- ty::ty_param(*) { cx.tcx.sess.bug(~"type_of with ty_param"); }
- ty::ty_var_integral(_) {
+ ty::ty_self => cx.tcx.sess.unimpl(~"type_of: ty_self"),
+ ty::ty_var(_) => cx.tcx.sess.bug(~"type_of with ty_var"),
+ ty::ty_param(*) => cx.tcx.sess.bug(~"type_of with ty_param"),
+ ty::ty_var_integral(_) => {
cx.tcx.sess.bug(~"type_of shouldn't see a ty_var_integral");
}
};
// If this was a class, fill in the type now.
alt ty::get(t).struct {
- ty::ty_class(did, ts) {
+ ty::ty_class(did, ts) => {
// Only instance vars are record fields at runtime.
let fields = ty::lookup_class_fields(cx.tcx, did);
let mut tys = do vec::map(fields) |f| {
common::set_struct_body(llty, tys);
}
- _ {
+ _ => {
// Nothing more to do.
}
}
fn llvm_type_name(cx: @crate_ctxt, t: ty::t) -> ~str {
let (name, did, tps) = alt check ty::get(t).struct {
- ty::ty_enum(did, substs) {
- (~"enum", did, substs.tps)
- }
- ty::ty_class(did, substs) {
- (~"class", did, substs.tps)
- }
+ ty::ty_enum(did, substs) => (~"enum", did, substs.tps),
+ ty::ty_class(did, substs) => (~"class", did, substs.tps)
};
return fmt!{
"%s %s[#%d]",
fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
-> ~[type_uses] {
alt ccx.type_use_cache.find(fn_id) {
- some(uses) { return uses; }
- none {}
+ some(uses) => return uses,
+ none => ()
}
let fn_id_loc = if fn_id.crate == local_crate { fn_id }
else { base::maybe_instantiate_inline(ccx, fn_id) };
let cx = {ccx: ccx, uses: vec::to_mut(vec::from_elem(n_tps, 0u))};
alt ty::get(ty::lookup_item_type(cx.ccx.tcx, fn_id).ty).struct {
- ty::ty_fn({inputs, _}) {
+ ty::ty_fn({inputs, _}) => {
for vec::each(inputs) |arg| {
if arg.mode == expl(by_val) { type_needs(cx, use_repr, arg.ty); }
}
}
- _ {}
+ _ => ()
}
if fn_id_loc.crate != local_crate {
return uses;
}
let map_node = alt ccx.tcx.items.find(fn_id_loc.node) {
- some(x) { x }
- none { ccx.sess.bug(fmt!{"type_uses_for: unbound item ID %?",
- fn_id_loc}); }
+ some(x) => x,
+ none => ccx.sess.bug(fmt!{"type_uses_for: unbound item ID %?",
+ fn_id_loc})
};
alt check map_node {
ast_map::node_item(@{node: item_fn(_, _, body), _}, _) |
- ast_map::node_method(@{body, _}, _, _) {
+ ast_map::node_method(@{body, _}, _, _) => {
handle_body(cx, body);
}
- ast_map::node_variant(_, _, _) {
+ ast_map::node_variant(_, _, _) => {
for uint::range(0u, n_tps) |n| { cx.uses[n] |= use_repr;}
}
ast_map::node_foreign_item(i@@{node: foreign_item_fn(_, _), _},
- abi, _) {
+ abi, _) => {
if abi == foreign_abi_rust_intrinsic {
let flags = alt check *i.ident {
~"size_of" | ~"pref_align_of" | ~"min_align_of" |
~"init" | ~"reinterpret_cast" |
- ~"move_val" | ~"move_val_init" {
+ ~"move_val" | ~"move_val_init" => {
use_repr
}
- ~"get_tydesc" | ~"needs_drop" { use_tydesc }
+ ~"get_tydesc" | ~"needs_drop" => {
+ use_tydesc
+ }
~"atomic_xchng" | ~"atomic_add" | ~"atomic_sub" |
~"atomic_xchng_acq" | ~"atomic_add_acq" | ~"atomic_sub_acq" |
- ~"atomic_xchng_rel" | ~"atomic_add_rel" | ~"atomic_sub_rel" {
+ ~"atomic_xchng_rel" | ~"atomic_add_rel" | ~"atomic_sub_rel" => {
+ 0u
+ }
+ ~"visit_tydesc" | ~"forget" | ~"addr_of" => {
0u
}
- ~"visit_tydesc" | ~"forget" | ~"addr_of" { 0u }
};
for uint::range(0u, n_tps) |n| { cx.uses[n] |= flags;}
}
}
- ast_map::node_ctor(_, _, ctor, _, _){
+ ast_map::node_ctor(_, _, ctor, _, _) => {
handle_body(cx, ctor.node.body);
}
- ast_map::node_dtor(_, dtor, _, _){
+ ast_map::node_dtor(_, dtor, _, _) => {
handle_body(cx, dtor.node.body);
}
right tydesc into the result)
*/
ty::ty_fn(_) | ty::ty_ptr(_) | ty::ty_rptr(_, _)
- | ty::ty_trait(_, _) { false }
- ty::ty_enum(did, substs) {
+ | ty::ty_trait(_, _) => false,
+ ty::ty_enum(did, substs) => {
if option::is_none(list::find(enums_seen, |id| id == did)) {
let seen = @cons(did, enums_seen);
for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| {
}
false
}
- ty::ty_param(p) {
+ ty::ty_param(p) => {
cx.uses[p.idx] |= use;
false
}
- _ { true }
+ _ => true
}
} else { false }
}
expr_repeat(*) => {
node_type_needs(cx, use_repr, e.id);
}
- expr_cast(base, _) {
+ expr_cast(base, _) => {
let result_t = ty::node_id_to_type(cx.ccx.tcx, e.id);
alt ty::get(result_t).struct {
- ty::ty_trait(*) {
+ ty::ty_trait(*) => {
// When we're casting to an trait, we need the
// tydesc for the expr that's being cast.
node_type_needs(cx, use_tydesc, base.id);
}
- _ {}
+ _ => ()
}
}
- expr_binary(op, lhs, _) {
+ expr_binary(op, lhs, _) => {
alt op {
- eq | lt | le | ne | ge | gt {
+ eq | lt | le | ne | ge | gt => {
node_type_needs(cx, use_tydesc, lhs.id)
}
- _ {}
+ _ => ()
}
}
- expr_path(_) {
+ expr_path(_) => {
do cx.ccx.tcx.node_type_substs.find(e.id).iter |ts| {
let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get(e.id));
vec::iter2(type_uses_for(cx.ccx, id, ts.len()), ts,
})
}
}
- expr_fn(*) | expr_fn_block(*) {
+ expr_fn(*) | expr_fn_block(*) => {
alt ty::ty_fn_proto(ty::expr_ty(cx.ccx.tcx, e)) {
- proto_bare | proto_uniq {}
- proto_box | proto_block {
+ proto_bare | proto_uniq => {}
+ proto_box | proto_block => {
for vec::each(*freevars::get_freevars(cx.ccx.tcx, e.id)) |fv| {
let node_id = ast_util::def_id_of_def(fv.def).node;
node_type_needs(cx, use_repr, node_id);
}
}
expr_assign(val, _) | expr_swap(val, _) | expr_assign_op(_, val, _) |
- expr_ret(some(val)) {
+ expr_ret(some(val)) => {
node_type_needs(cx, use_repr, val.id);
}
- expr_index(base, _) | expr_field(base, _, _) {
+ expr_index(base, _) | expr_field(base, _, _) => {
// FIXME (#2537): could be more careful and not count fields after
// the chosen field.
let base_ty = ty::node_id_to_type(cx.ccx.tcx, base.id);
do option::iter(cx.ccx.maps.method_map.find(e.id)) |mth| {
alt mth.origin {
- typeck::method_static(did) {
+ typeck::method_static(did) => {
do option::iter(cx.ccx.tcx.node_type_substs.find(e.id)) |ts| {
do vec::iter2(type_uses_for(cx.ccx, did, ts.len()), ts)
|uses, subst| { type_needs(cx, uses, subst)}
}
}
- typeck::method_param({param_num: param, _}) {
+ typeck::method_param({param_num: param, _}) => {
cx.uses[param] |= use_tydesc;
}
- typeck::method_trait(_, _) {}
+ typeck::method_trait(_, _) => (),
}
}
}
- expr_log(_, _, val) {
+ expr_log(_, _, val) => {
node_type_needs(cx, use_tydesc, val.id);
}
- expr_call(f, _, _) {
+ expr_call(f, _, _) => {
vec::iter(ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, f.id)), |a| {
alt a.mode {
- expl(by_move) | expl(by_copy) | expl(by_val) {
+ expl(by_move) | expl(by_copy) | expl(by_val) => {
type_needs(cx, use_repr, a.ty);
}
- _ {}
+ _ => ()
}
})
}
expr_unary(_, _) | expr_lit(_) | expr_assert(_) |
expr_mac(_) | expr_addr_of(_, _) |
expr_ret(_) | expr_loop(_) |
- expr_loop_body(_) | expr_do_body(_) {}
+ expr_loop_body(_) | expr_do_body(_) => ()
}
}
fn content_ty(t: ty::t) -> ty::t {
alt ty::get(t).struct {
- ty::ty_uniq({ty: ct, _}) { ct }
- _ { core::unreachable(); }
+ ty::ty_uniq({ty: ct, _}) => ct,
+ _ => core::unreachable()
}
}
let mut kind = kind_noncopyable();
for vec::each(*bounds) |bound| {
alt bound {
- bound_copy {
+ bound_copy => {
kind = raise_kind(kind, kind_implicitly_copyable());
}
- bound_owned {
+ bound_owned => {
kind = raise_kind(kind, kind_owned());
}
- bound_send {
+ bound_send => {
kind = raise_kind(kind, kind_send_only() | kind_owned());
}
- bound_const {
+ bound_const => {
kind = raise_kind(kind, kind_const());
}
- bound_trait(_) {}
+ bound_trait(_) => ()
}
}
kind
fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t {
let key = {struct: st, o_def_id: o_def_id};
alt cx.interner.find(key) {
- some(t) { unsafe { return unsafe::reinterpret_cast(t); } }
- _ {}
+ some(t) => unsafe { return unsafe::reinterpret_cast(t); }
+ _ => ()
}
let mut flags = 0u;
fn rflags(r: region) -> uint {
(has_regions as uint) | {
alt r {
- ty::re_var(_) {needs_infer as uint}
- _ {0u}
+ ty::re_var(_) => needs_infer as uint,
+ _ => 0u
}
}
}
return f;
}
alt st {
- ty_estr(vstore_slice(r)) {
+ ty_estr(vstore_slice(r)) => {
flags |= rflags(r);
}
- ty_evec(mt, vstore_slice(r)) {
+ ty_evec(mt, vstore_slice(r)) => {
flags |= rflags(r);
flags |= get(mt.ty).flags;
}
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
ty_estr(_) | ty_type | ty_opaque_closure_ptr(_) |
- ty_opaque_box {}
- ty_param(_) { flags |= has_params as uint; }
- ty_var(_) | ty_var_integral(_) { flags |= needs_infer as uint; }
- ty_self { flags |= has_self as uint; }
- ty_enum(_, substs) | ty_class(_, substs) | ty_trait(_, substs) {
+ ty_opaque_box => (),
+ ty_param(_) => flags |= has_params as uint,
+ ty_var(_) | ty_var_integral(_) => flags |= needs_infer as uint,
+ ty_self => flags |= has_self as uint,
+ ty_enum(_, substs) | ty_class(_, substs) | ty_trait(_, substs) => {
flags |= sflags(substs);
}
ty_box(m) | ty_uniq(m) | ty_evec(m, _) |
- ty_ptr(m) | ty_unboxed_vec(m) {
+ ty_ptr(m) | ty_unboxed_vec(m) => {
flags |= get(m.ty).flags;
}
- ty_rptr(r, m) {
+ ty_rptr(r, m) => {
flags |= rflags(r);
flags |= get(m.ty).flags;
}
- ty_rec(flds) {
- for flds.each |f| { flags |= get(f.mt.ty).flags; }
- }
- ty_tup(ts) {
- for ts.each |tt| { flags |= get(tt).flags; }
- }
- ty_fn(f) {
+ ty_rec(flds) => for flds.each |f| { flags |= get(f.mt.ty).flags; }
+ ty_tup(ts) => for ts.each |tt| { flags |= get(tt).flags; }
+ ty_fn(f) => {
for f.inputs.each |a| { flags |= get(a.ty).flags; }
flags |= get(f.output).flags;
}
// Converts s to its machine type equivalent
pure fn mach_sty(cfg: @session::config, t: t) -> sty {
alt get(t).struct {
- ty_int(ast::ty_i) { ty_int(cfg.int_type) }
- ty_uint(ast::ty_u) { ty_uint(cfg.uint_type) }
- ty_float(ast::ty_f) { ty_float(cfg.float_type) }
- s { s }
+ ty_int(ast::ty_i) => ty_int(cfg.int_type),
+ ty_uint(ast::ty_u) => ty_uint(cfg.uint_type),
+ ty_float(ast::ty_f) => ty_float(cfg.float_type),
+ s => s
}
}
// with id `id`.
fn encl_region(cx: ctxt, id: ast::node_id) -> ty::region {
alt cx.region_map.find(id) {
- some(encl_scope) {ty::re_scope(encl_scope)}
- none {ty::re_static}
+ some(encl_scope) => ty::re_scope(encl_scope),
+ none => ty::re_static
}
}
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
ty_estr(_) | ty_type | ty_opaque_box | ty_self |
ty_opaque_closure_ptr(_) | ty_var(_) | ty_var_integral(_) |
- ty_param(_) {
+ ty_param(_) => {
}
ty_box(tm) | ty_evec(tm, _) | ty_unboxed_vec(tm) |
- ty_ptr(tm) | ty_rptr(_, tm) {
+ ty_ptr(tm) | ty_rptr(_, tm) => {
maybe_walk_ty(tm.ty, f);
}
ty_enum(_, substs) | ty_class(_, substs) |
- ty_trait(_, substs) {
+ ty_trait(_, substs) => {
for substs.tps.each |subty| { maybe_walk_ty(subty, f); }
}
- ty_rec(fields) {
+ ty_rec(fields) => {
for fields.each |fl| { maybe_walk_ty(fl.mt.ty, f); }
}
- ty_tup(ts) { for ts.each |tt| { maybe_walk_ty(tt, f); } }
- ty_fn(ft) {
+ ty_tup(ts) => { for ts.each |tt| { maybe_walk_ty(tt, f); } }
+ ty_fn(ft) => {
for ft.inputs.each |a| { maybe_walk_ty(a.ty, f); }
maybe_walk_ty(ft.output, f);
}
- ty_uniq(tm) { maybe_walk_ty(tm.ty, f); }
+ ty_uniq(tm) => { maybe_walk_ty(tm.ty, f); }
}
}
}
alt sty {
- ty_box(tm) {
+ ty_box(tm) => {
ty_box({ty: fldop(tm.ty), mutbl: tm.mutbl})
}
- ty_uniq(tm) {
+ ty_uniq(tm) => {
ty_uniq({ty: fldop(tm.ty), mutbl: tm.mutbl})
}
- ty_ptr(tm) {
+ ty_ptr(tm) => {
ty_ptr({ty: fldop(tm.ty), mutbl: tm.mutbl})
}
- ty_unboxed_vec(tm) {
+ ty_unboxed_vec(tm) => {
ty_unboxed_vec({ty: fldop(tm.ty), mutbl: tm.mutbl})
}
- ty_evec(tm, vst) {
+ ty_evec(tm, vst) => {
ty_evec({ty: fldop(tm.ty), mutbl: tm.mutbl}, vst)
}
- ty_enum(tid, substs) {
+ ty_enum(tid, substs) => {
ty_enum(tid, fold_substs(substs, fldop))
}
- ty_trait(did, substs) {
+ ty_trait(did, substs) => {
ty_trait(did, fold_substs(substs, fldop))
}
- ty_rec(fields) {
+ ty_rec(fields) => {
let new_fields = do vec::map(fields) |fl| {
let new_ty = fldop(fl.mt.ty);
let new_mt = {ty: new_ty, mutbl: fl.mt.mutbl};
};
ty_rec(new_fields)
}
- ty_tup(ts) {
+ ty_tup(ts) => {
let new_ts = vec::map(ts, |tt| fldop(tt));
ty_tup(new_ts)
}
- ty_fn(f) {
+ ty_fn(f) => {
let new_args = vec::map(f.inputs, |a| {
let new_ty = fldop(a.ty);
{mode: a.mode, ty: new_ty}
let new_output = fldop(f.output);
ty_fn({inputs: new_args, output: new_output with f})
}
- ty_rptr(r, tm) {
+ ty_rptr(r, tm) => {
ty_rptr(r, {ty: fldop(tm.ty), mutbl: tm.mutbl})
}
- ty_class(did, substs) {
+ ty_class(did, substs) => {
ty_class(did, fold_substs(substs, fldop))
}
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
ty_estr(_) | ty_type | ty_opaque_closure_ptr(_) |
- ty_opaque_box | ty_var(_) | ty_var_integral(_) | ty_param(*) | ty_self {
+ ty_opaque_box | ty_var(_) | ty_var_integral(_) |
+ ty_param(*) | ty_self => {
sty
}
}
let tb = ty::get(ty);
alt tb.struct {
- ty::ty_rptr(r, mt) {
+ ty::ty_rptr(r, mt) => {
let m_r = fldr(r);
let m_t = fldt(mt.ty);
ty::mk_rptr(cx, m_r, {ty: m_t, mutbl: mt.mutbl})
}
- ty_estr(vstore_slice(r)) {
+ ty_estr(vstore_slice(r)) => {
let m_r = fldr(r);
ty::mk_estr(cx, vstore_slice(m_r))
}
- ty_evec(mt, vstore_slice(r)) {
+ ty_evec(mt, vstore_slice(r)) => {
let m_r = fldr(r);
let m_t = fldt(mt.ty);
ty::mk_evec(cx, {ty: m_t, mutbl: mt.mutbl}, vstore_slice(m_r))
}
- ty_enum(def_id, substs) {
+ ty_enum(def_id, substs) => {
ty::mk_enum(cx, def_id, fold_substs(substs, fldr, fldt))
}
- ty_class(def_id, substs) {
+ ty_class(def_id, substs) => {
ty::mk_class(cx, def_id, fold_substs(substs, fldr, fldt))
}
- ty_trait(def_id, substs) {
+ ty_trait(def_id, substs) => {
ty::mk_trait(cx, def_id, fold_substs(substs, fldr, fldt))
}
- sty @ ty_fn(_) {
+ sty @ ty_fn(_) => {
fold_sty_to_ty(cx, sty, |t| fldfnt(t))
}
- sty {
+ sty => {
fold_sty_to_ty(cx, sty, |t| fldt(t))
}
}
let tb = get(t0);
if !tbox_has_flag(tb, has_regions) { return t0; }
alt tb.struct {
- ty_rptr(r, {ty: t1, mutbl: m}) {
+ ty_rptr(r, {ty: t1, mutbl: m}) => {
let m_r = fldop(r, under_r);
let m_t1 = do_fold(cx, t1, true, fldop);
ty::mk_rptr(cx, m_r, {ty: m_t1, mutbl: m})
}
- ty_estr(vstore_slice(r)) {
+ ty_estr(vstore_slice(r)) => {
let m_r = fldop(r, under_r);
ty::mk_estr(cx, vstore_slice(m_r))
}
- ty_evec({ty: t1, mutbl: m}, vstore_slice(r)) {
+ ty_evec({ty: t1, mutbl: m}, vstore_slice(r)) => {
let m_r = fldop(r, under_r);
let m_t1 = do_fold(cx, t1, true, fldop);
ty::mk_evec(cx, {ty: m_t1, mutbl: m}, vstore_slice(m_r))
}
- ty_fn(_) {
+ ty_fn(_) => {
// do not recurse into functions, which introduce fresh bindings
t0
}
- sty {
+ sty => {
do fold_sty_to_ty(cx, sty) |t| {
do_fold(cx, t, under_r, fldop)
}
let tb = ty::get(typ);
if !tbox_has_flag(tb, has_params) { return typ; }
alt tb.struct {
- ty_param(p) { tps[p.idx] }
- sty { fold_sty_to_ty(cx, sty, |t| subst_tps(cx, tps, t)) }
+ ty_param(p) => tps[p.idx],
+ sty => fold_sty_to_ty(cx, sty, |t| subst_tps(cx, tps, t))
}
}
let tb = get(typ);
if !tbox_has_flag(tb, needs_subst) { return typ; }
alt tb.struct {
- ty_param(p) {substs.tps[p.idx]}
- ty_self {substs.self_ty.get()}
- _ {
+ ty_param(p) => substs.tps[p.idx],
+ ty_self => substs.self_ty.get(),
+ _ => {
fold_regions_and_ty(
cx, typ,
|r| alt r {
- re_bound(br_self) {substs.self_r.get()}
- _ {r}
+ re_bound(br_self) => substs.self_r.get(),
+ _ => r
},
|t| do_subst(cx, substs, t),
|t| do_subst(cx, substs, t))
fn type_is_var(ty: t) -> bool {
alt get(ty).struct {
- ty_var(_) { true }
- _ { false }
+ ty_var(_) => true,
+ _ => false
}
}
fn type_is_var_integral(ty: t) -> bool {
alt get(ty).struct {
- ty_var_integral(_) { true }
- _ { false }
+ ty_var_integral(_) => true,
+ _ => false
}
}
ty_trait(*) |
ty_evec(_, vstore_fixed(_)) | ty_estr(vstore_fixed(_)) |
ty_evec(_, vstore_slice(_)) | ty_estr(vstore_slice(_))
- { true }
- _ { false }
+ => true,
+ _ => false
}
}
fn type_is_sequence(ty: t) -> bool {
alt get(ty).struct {
- ty_estr(_) | ty_evec(_, _) { true }
- _ { false }
+ ty_estr(_) | ty_evec(_, _) => true,
+ _ => false
}
}
fn type_is_str(ty: t) -> bool {
alt get(ty).struct {
- ty_estr(_) { true }
- _ { false }
+ ty_estr(_) => true,
+ _ => false
}
}
fn sequence_element_type(cx: ctxt, ty: t) -> t {
alt get(ty).struct {
- ty_estr(_) { return mk_mach_uint(cx, ast::ty_u8); }
- ty_evec(mt, _) | ty_unboxed_vec(mt) { return mt.ty; }
- _ { cx.sess.bug(
- ~"sequence_element_type called on non-sequence value");
- }
+ ty_estr(_) => return mk_mach_uint(cx, ast::ty_u8),
+ ty_evec(mt, _) | ty_unboxed_vec(mt) => return mt.ty,
+ _ => cx.sess.bug(
+ ~"sequence_element_type called on non-sequence value"),
}
}
fn get_element_type(ty: t, i: uint) -> t {
alt get(ty).struct {
- ty_rec(flds) { return flds[i].mt.ty; }
- ty_tup(ts) { return ts[i]; }
- _ { fail ~"get_element_type called on invalid type"; }
+ ty_rec(flds) => return flds[i].mt.ty,
+ ty_tup(ts) => return ts[i],
+ _ => fail ~"get_element_type called on invalid type"
}
}
pure fn type_is_box(ty: t) -> bool {
alt get(ty).struct {
- ty_box(_) { return true; }
- _ { return false; }
+ ty_box(_) => return true,
+ _ => return false
}
}
pure fn type_is_boxed(ty: t) -> bool {
alt get(ty).struct {
ty_box(_) | ty_opaque_box |
- ty_evec(_, vstore_box) | ty_estr(vstore_box) { true }
- _ { false }
+ ty_evec(_, vstore_box) | ty_estr(vstore_box) => true,
+ _ => false
}
}
pure fn type_is_region_ptr(ty: t) -> bool {
alt get(ty).struct {
- ty_rptr(_, _) { true }
- _ { false }
+ ty_rptr(_, _) => true,
+ _ => false
}
}
pure fn type_is_slice(ty: t) -> bool {
alt get(ty).struct {
- ty_evec(_, vstore_slice(_)) | ty_estr(vstore_slice(_)) { true }
- _ { return false; }
+ ty_evec(_, vstore_slice(_)) | ty_estr(vstore_slice(_)) => true,
+ _ => return false
}
}
pure fn type_is_unique_box(ty: t) -> bool {
alt get(ty).struct {
- ty_uniq(_) { return true; }
- _ { return false; }
+ ty_uniq(_) => return true,
+ _ => return false
}
}
pure fn type_is_unsafe_ptr(ty: t) -> bool {
alt get(ty).struct {
- ty_ptr(_) { return true; }
- _ { return false; }
+ ty_ptr(_) => return true,
+ _ => return false
}
}
pure fn type_is_vec(ty: t) -> bool {
return alt get(ty).struct {
- ty_evec(_, _) | ty_unboxed_vec(_) { true }
- ty_estr(_) { true }
- _ { false }
+ ty_evec(_, _) | ty_unboxed_vec(_) => true,
+ ty_estr(_) => true,
+ _ => false
};
}
pure fn type_is_unique(ty: t) -> bool {
alt get(ty).struct {
- ty_uniq(_) { return true; }
- ty_evec(_, vstore_uniq) { true }
- ty_estr(vstore_uniq) { true }
- _ { return false; }
+ ty_uniq(_) => return true,
+ ty_evec(_, vstore_uniq) => true,
+ ty_estr(vstore_uniq) => true,
+ _ => return false
}
}
pure fn type_is_scalar(ty: t) -> bool {
alt get(ty).struct {
ty_nil | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
- ty_var_integral(_) | ty_type | ty_ptr(_) { true }
- _ { false }
+ ty_var_integral(_) | ty_type | ty_ptr(_) => true,
+ _ => false
}
}
fn type_needs_drop(cx: ctxt, ty: t) -> bool {
alt cx.needs_drop_cache.find(ty) {
- some(result) { return result; }
- none {/* fall through */ }
+ some(result) => return result,
+ none => {/* fall through */ }
}
let mut accum = false;
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
ty_type | ty_ptr(_) | ty_rptr(_, _) |
ty_estr(vstore_fixed(_)) | ty_estr(vstore_slice(_)) |
- ty_evec(_, vstore_slice(_)) { false }
- ty_evec(mt, vstore_fixed(_)) { type_needs_drop(cx, mt.ty) }
- ty_unboxed_vec(mt) { type_needs_drop(cx, mt.ty) }
- ty_rec(flds) {
+ ty_evec(_, vstore_slice(_)) => false,
+ ty_evec(mt, vstore_fixed(_)) => type_needs_drop(cx, mt.ty),
+ ty_unboxed_vec(mt) => type_needs_drop(cx, mt.ty),
+ ty_rec(flds) => {
for flds.each |f| {
if type_needs_drop(cx, f.mt.ty) { accum = true; }
}
accum
}
- ty_class(did, substs) {
+ ty_class(did, substs) => {
// Any class with a dtor needs a drop
option::is_some(ty_dtor(cx, did)) || {
for vec::each(ty::class_items_as_fields(cx, did, substs)) |f| {
accum
}
}
- ty_tup(elts) {
+ ty_tup(elts) => {
for elts.each |m| { if type_needs_drop(cx, m) { accum = true; } }
accum
}
- ty_enum(did, substs) {
+ ty_enum(did, substs) => {
let variants = enum_variants(cx, did);
for vec::each(*variants) |variant| {
for variant.args.each |aty| {
}
accum
}
- ty_fn(fty) {
+ ty_fn(fty) => {
alt fty.proto {
- proto_bare | proto_block { false }
- _ { true }
+ proto_bare | proto_block => false,
+ _ => true
}
}
- _ { true }
+ _ => true
};
cx.needs_drop_cache.insert(ty, result);
// cleanups.
fn type_needs_unwind_cleanup(cx: ctxt, ty: t) -> bool {
alt cx.needs_unwind_cleanup_cache.find(ty) {
- some(result) { return result; }
- none { }
+ some(result) => return result,
+ none => ()
}
let tycache = new_ty_hash();
// Prevent infinite recursion
alt tycache.find(ty) {
- some(_) { return false; }
- none { tycache.insert(ty, ()); }
+ some(_) => return false,
+ none => { tycache.insert(ty, ()); }
}
let mut encountered_box = encountered_box;
do maybe_walk_ty(ty) |ty| {
let old_encountered_box = encountered_box;
let result = alt get(ty).struct {
- ty_box(_) | ty_opaque_box {
+ ty_box(_) | ty_opaque_box => {
encountered_box = true;
true
}
ty_nil | ty_bot | ty_bool |
ty_int(_) | ty_uint(_) | ty_float(_) |
- ty_rec(_) | ty_tup(_) | ty_ptr(_) {
+ ty_rec(_) | ty_tup(_) | ty_ptr(_) => {
true
}
- ty_enum(did, substs) {
+ ty_enum(did, substs) => {
for vec::each(*enum_variants(cx, did)) |v| {
for v.args.each |aty| {
let t = subst(cx, substs, aty);
ty_estr(vstore_box) |
ty_evec(_, vstore_uniq) |
ty_evec(_, vstore_box)
- {
+ => {
// Once we're inside a box, the annihilator will find
// it and destroy it.
if !encountered_box {
true
}
}
- _ {
+ _ => {
needs_unwind_cleanup = true;
false
}
fn proto_kind(p: proto) -> kind {
alt p {
- ast::proto_block { kind_noncopyable() }
- ast::proto_box { kind_safe_for_default_mode() | kind_owned() }
- ast::proto_uniq { kind_send_copy() | kind_owned() }
- ast::proto_bare { kind_safe_for_default_mode_send() | kind_const() |
- kind_owned() }
+ ast::proto_block => kind_noncopyable(),
+ ast::proto_box => kind_safe_for_default_mode() | kind_owned(),
+ ast::proto_uniq => kind_send_copy() | kind_owned(),
+ ast::proto_bare => kind_safe_for_default_mode_send() | kind_const() |
+ kind_owned()
}
}
// implicitly copied and to compute whether things have const kind.
fn mutability_kind(m: mutability) -> kind {
alt (m) {
- m_mutbl { remove_const(remove_implicit(kind_top())) }
- m_const { remove_implicit(kind_top()) }
- m_imm { kind_top() }
+ m_mutbl => remove_const(remove_implicit(kind_top())),
+ m_const => remove_implicit(kind_top()),
+ m_imm => kind_top()
}
}
fn type_kind(cx: ctxt, ty: t) -> kind {
alt cx.kind_cache.find(ty) {
- some(result) { return result; }
- none {/* fall through */ }
+ some(result) => return result,
+ none => {/* fall through */ }
}
// Insert a default in case we loop back on self recursively.
let mut result = alt get(ty).struct {
// Scalar and unique types are sendable, constant, and owned
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
- ty_ptr(_) {
+ ty_ptr(_) => {
kind_safe_for_default_mode_send() | kind_const() | kind_owned()
}
// Implicit copyability of strs is configurable
- ty_estr(vstore_uniq) {
+ ty_estr(vstore_uniq) => {
if cx.vecs_implicitly_copyable {
kind_implicitly_sendable() | kind_const() | kind_owned()
} else {
}
// functions depend on the protocol
- ty_fn(f) { proto_kind(f.proto) }
+ ty_fn(f) => proto_kind(f.proto),
// Those with refcounts raise noncopyable to copyable,
// lower sendable to copyable. Therefore just set result to copyable.
- ty_box(tm) {
+ ty_box(tm) => {
remove_send(mutable_type_kind(cx, tm) | kind_safe_for_default_mode())
}
// Trait instances are (for now) like shared boxes, basically
- ty_trait(_, _) { kind_safe_for_default_mode() | kind_owned() }
+ ty_trait(_, _) => kind_safe_for_default_mode() | kind_owned(),
// Region pointers are copyable but NOT owned nor sendable
- ty_rptr(_, _) { kind_safe_for_default_mode() }
+ ty_rptr(_, _) => kind_safe_for_default_mode(),
// Unique boxes and vecs have the kind of their contained type,
// but unique boxes can't be implicitly copyable.
- ty_uniq(tm) { remove_implicit(mutable_type_kind(cx, tm)) }
+ ty_uniq(tm) => remove_implicit(mutable_type_kind(cx, tm)),
// Implicit copyability of vecs is configurable
- ty_evec(tm, vstore_uniq) {
+ ty_evec(tm, vstore_uniq) => {
if cx.vecs_implicitly_copyable {
mutable_type_kind(cx, tm)
} else {
// Slices, refcounted evecs are copyable; uniques depend on the their
// contained type, but aren't implicitly copyable. Fixed vectors have
// the kind of the element they contain, taking mutability into account.
- ty_evec(tm, vstore_box) {
+ ty_evec(tm, vstore_box) => {
remove_send(kind_safe_for_default_mode() | mutable_type_kind(cx, tm))
}
- ty_evec(tm, vstore_slice(_)) {
+ ty_evec(tm, vstore_slice(_)) => {
remove_owned_send(kind_safe_for_default_mode() |
mutable_type_kind(cx, tm))
}
- ty_evec(tm, vstore_fixed(_)) {
+ ty_evec(tm, vstore_fixed(_)) => {
mutable_type_kind(cx, tm)
}
// All estrs are copyable; uniques and interiors are sendable.
- ty_estr(vstore_box) {
+ ty_estr(vstore_box) => {
kind_safe_for_default_mode() | kind_const() | kind_owned()
}
- ty_estr(vstore_slice(_)) {
+ ty_estr(vstore_slice(_)) => {
kind_safe_for_default_mode() | kind_const()
}
- ty_estr(vstore_fixed(_)) {
+ ty_estr(vstore_fixed(_)) => {
kind_safe_for_default_mode_send() | kind_const() | kind_owned()
}
// Records lower to the lowest of their members.
- ty_rec(flds) {
+ ty_rec(flds) => {
let mut lowest = kind_top();
for flds.each |f| {
lowest = lower_kind(lowest, mutable_type_kind(cx, f.mt));
lowest
}
- ty_class(did, substs) {
+ ty_class(did, substs) => {
// Classes are sendable if all their fields are sendable,
// likewise for copyable...
// also factor out this code, copied from the records case
}
// Tuples lower to the lowest of their members.
- ty_tup(tys) {
+ ty_tup(tys) => {
let mut lowest = kind_top();
for tys.each |ty| { lowest = lower_kind(lowest, type_kind(cx, ty)); }
lowest
}
// Enums lower to the lowest of their variants.
- ty_enum(did, substs) {
+ ty_enum(did, substs) => {
let mut lowest = kind_top();
let variants = enum_variants(cx, did);
if vec::len(*variants) == 0u {
lowest
}
- ty_param(p) {
+ ty_param(p) => {
param_bounds_to_kind(cx.ty_param_bounds.get(p.def_id.node))
}
// self is a special type parameter that can only appear in traits; it
// is never bounded in any way, hence it has the bottom kind.
- ty_self { kind_noncopyable() }
+ ty_self => kind_noncopyable(),
- ty_var(_) | ty_var_integral(_) {
+ ty_var(_) | ty_var_integral(_) => {
cx.sess.bug(~"Asked to compute kind of a type variable");
}
- ty_type | ty_opaque_closure_ptr(_) | ty_opaque_box | ty_unboxed_vec(_) {
+ ty_type | ty_opaque_closure_ptr(_)
+ | ty_opaque_box | ty_unboxed_vec(_) => {
cx.sess.bug(~"Asked to compute kind of fictitious type");
}
};
flds.foldl(0, |s, f| s + type_size(cx, f.mt.ty))
}
- ty_class(did, substs) {
+ ty_class(did, substs) => {
let flds = class_items_as_fields(cx, did, substs);
flds.foldl(0, |s, f| s + type_size(cx, f.mt.ty))
}
- ty_tup(tys) {
+ ty_tup(tys) => {
tys.foldl(0, |s, t| s + type_size(cx, t))
}
- ty_enum(did, substs) {
+ ty_enum(did, substs) => {
let variants = substd_enum_variants(cx, did, substs);
variants.foldl( // find max size of any variant
0,
v.args.foldl(0, |s, a| s + type_size(cx, a))))
}
- ty_param(_) | ty_self {
+ ty_param(_) | ty_self => {
1
}
- ty_var(_) | ty_var_integral(_) {
+ ty_var(_) | ty_var_integral(_) => {
cx.sess.bug(~"Asked to compute kind of a type variable");
}
- ty_type | ty_opaque_closure_ptr(_) | ty_opaque_box | ty_unboxed_vec(_) {
+ ty_type | ty_opaque_closure_ptr(_)
+ | ty_opaque_box | ty_unboxed_vec(_) => {
cx.sess.bug(~"Asked to compute kind of fictitious type");
}
}
ty_opaque_box |
ty_opaque_closure_ptr(_) |
ty_evec(_, _) |
- ty_unboxed_vec(_) {
+ ty_unboxed_vec(_) => {
false
}
ty_box(mt) |
ty_uniq(mt) |
- ty_rptr(_, mt) {
+ ty_rptr(_, mt) => {
return type_requires(cx, seen, r_ty, mt.ty);
}
- ty_ptr(mt) {
+ ty_ptr(mt) => {
false // unsafe ptrs can always be NULL
}
- ty_rec(fields) {
+ ty_rec(fields) => {
do vec::any(fields) |field| {
type_requires(cx, seen, r_ty, field.mt.ty)
}
}
- ty_trait(_, _) {
+ ty_trait(_, _) => {
false
}
- ty_class(did, _) if vec::contains(*seen, did) {
+ ty_class(did, _) if vec::contains(*seen, did) => {
false
}
- ty_class(did, substs) {
+ ty_class(did, substs) => {
vec::push(*seen, did);
let r = vec::any(class_items_as_fields(cx, did, substs),
|f| type_requires(cx, seen, r_ty, f.mt.ty));
r
}
- ty_tup(ts) {
+ ty_tup(ts) => {
vec::any(ts, |t| type_requires(cx, seen, r_ty, t))
}
- ty_enum(did, _) if vec::contains(*seen, did) {
+ ty_enum(did, _) if vec::contains(*seen, did) => {
false
}
- ty_enum(did, substs) {
+ ty_enum(did, substs) => {
vec::push(*seen, did);
let vs = enum_variants(cx, did);
let r = vec::len(*vs) > 0u && vec::all(*vs, |variant| {
debug!{"type_structurally_contains: %s", ty_to_str(cx, ty)};
if test(sty) { return true; }
alt sty {
- ty_enum(did, substs) {
+ ty_enum(did, substs) => {
for vec::each(*enum_variants(cx, did)) |variant| {
for variant.args.each |aty| {
let sty = subst(cx, substs, aty);
}
return false;
}
- ty_rec(fields) {
+ ty_rec(fields) => {
for fields.each |field| {
if type_structurally_contains(cx, field.mt.ty, test) {
return true;
}
return false;
}
- ty_class(did, substs) {
+ ty_class(did, substs) => {
for lookup_class_fields(cx, did).each |field| {
let ft = lookup_field_type(cx, did, field.id, substs);
if type_structurally_contains(cx, ft, test) { return true; }
return false;
}
- ty_tup(ts) {
+ ty_tup(ts) => {
for ts.each |tt| {
if type_structurally_contains(cx, tt, test) { return true; }
}
return false;
}
- ty_evec(mt, vstore_fixed(_)) {
+ ty_evec(mt, vstore_fixed(_)) => {
return type_structurally_contains(cx, mt.ty, test);
}
- _ { return false; }
+ _ => return false
}
}
alt sty {
ty_uniq(_) |
ty_evec(_, vstore_uniq) |
- ty_estr(vstore_uniq) { true }
- _ { false }
+ ty_estr(vstore_uniq) => true,
+ _ => false,
}
});
}
fn type_is_integral(ty: t) -> bool {
alt get(ty).struct {
- ty_var_integral(_) | ty_int(_) | ty_uint(_) | ty_bool { true }
- _ { false }
+ ty_var_integral(_) | ty_int(_) | ty_uint(_) | ty_bool => true,
+ _ => false
}
}
fn type_is_fp(ty: t) -> bool {
alt get(ty).struct {
- ty_float(_) { true }
- _ { false }
+ ty_float(_) => true,
+ _ => false
}
}
fn type_is_signed(ty: t) -> bool {
alt get(ty).struct {
- ty_int(_) { true }
- _ { false }
+ ty_int(_) => true,
+ _ => false
}
}
alt get(ty).struct {
// Scalar types
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
- ty_type | ty_ptr(_) { result = true; }
+ ty_type | ty_ptr(_) => result = true,
// Boxed types
ty_box(_) | ty_uniq(_) | ty_fn(_) |
ty_estr(vstore_uniq) | ty_estr(vstore_box) |
ty_evec(_, vstore_uniq) | ty_evec(_, vstore_box) |
- ty_trait(_, _) | ty_rptr(_,_) | ty_opaque_box { result = false; }
+ ty_trait(_, _) | ty_rptr(_,_) | ty_opaque_box => result = false,
// Structural types
- ty_enum(did, substs) {
+ ty_enum(did, substs) => {
let variants = enum_variants(cx, did);
for vec::each(*variants) |variant| {
let tup_ty = mk_tup(cx, variant.args);
if !type_is_pod(cx, tup_ty) { result = false; }
}
}
- ty_rec(flds) {
+ ty_rec(flds) => {
for flds.each |f| {
if !type_is_pod(cx, f.mt.ty) { result = false; }
}
}
- ty_tup(elts) {
+ ty_tup(elts) => {
for elts.each |elt| { if !type_is_pod(cx, elt) { result = false; } }
}
- ty_estr(vstore_fixed(_)) { result = true; }
- ty_evec(mt, vstore_fixed(_)) | ty_unboxed_vec(mt) {
+ ty_estr(vstore_fixed(_)) => result = true,
+ ty_evec(mt, vstore_fixed(_)) | ty_unboxed_vec(mt) => {
result = type_is_pod(cx, mt.ty);
}
- ty_param(_) { result = false; }
- ty_opaque_closure_ptr(_) { result = true; }
- ty_class(did, substs) {
+ ty_param(_) => result = false,
+ ty_opaque_closure_ptr(_) => result = true,
+ ty_class(did, substs) => {
result = vec::any(lookup_class_fields(cx, did), |f| {
let fty = ty::lookup_item_type(cx, f.id);
let sty = subst(cx, substs, fty.ty);
});
}
- ty_estr(vstore_slice(*)) | ty_evec(_, vstore_slice(*)) {
+ ty_estr(vstore_slice(*)) | ty_evec(_, vstore_slice(*)) => {
result = false;
}
- ty_var(*) | ty_var_integral(*) | ty_self(*) {
+ ty_var(*) | ty_var_integral(*) | ty_self(*) => {
cx.sess.bug(~"non concrete type in type_is_pod");
}
}
fn type_is_enum(ty: t) -> bool {
alt get(ty).struct {
- ty_enum(_, _) { return true; }
- _ { return false;}
+ ty_enum(_, _) => return true,
+ _ => return false
}
}
// constructors
fn type_is_c_like_enum(cx: ctxt, ty: t) -> bool {
alt get(ty).struct {
- ty_enum(did, substs) {
+ ty_enum(did, substs) => {
let variants = enum_variants(cx, did);
let some_n_ary = vec::any(*variants, |v| vec::len(v.args) > 0u);
return !some_n_ary;
}
- _ { return false;}
+ _ => return false
}
}
fn type_param(ty: t) -> option<uint> {
alt get(ty).struct {
- ty_param(p) { return some(p.idx); }
- _ {/* fall through */ }
+ ty_param(p) => return some(p.idx),
+ _ => {/* fall through */ }
}
return none;
}
}
fn deref_sty(cx: ctxt, sty: sty, expl: bool) -> option<mt> {
alt sty {
- ty_rptr(_, mt) | ty_box(mt) | ty_uniq(mt) {
+ ty_rptr(_, mt) | ty_box(mt) | ty_uniq(mt) => {
some(mt)
}
- ty_ptr(mt) if expl {
+ ty_ptr(mt) if expl => {
some(mt)
}
- ty_enum(did, substs) {
+ ty_enum(did, substs) => {
let variants = enum_variants(cx, did);
if vec::len(*variants) == 1u && vec::len(variants[0].args) == 1u {
let v_t = subst(cx, substs, variants[0].args[0]);
}
}
- _ { none }
+ _ => none
}
}
let mut t = t;
loop {
alt deref(cx, t, false) {
- none { return t; }
- some(mt) { t = mt.ty; }
+ none => return t,
+ some(mt) => t = mt.ty
}
}
}
fn index_sty(cx: ctxt, sty: sty) -> option<mt> {
alt sty {
- ty_evec(mt, _) { some(mt) }
- ty_estr(_) { some({ty: mk_u8(cx), mutbl: ast::m_imm}) }
- _ { none }
+ ty_evec(mt, _) => some(mt),
+ ty_estr(_) => some({ty: mk_u8(cx), mutbl: ast::m_imm}),
+ _ => none
}
}
pure fn hash_bound_region(br: &bound_region) -> uint {
alt *br { // no idea if this is any good
- ty::br_self { 0u }
- ty::br_anon { 1u }
- ty::br_named(str) { str::hash(str) }
- ty::br_cap_avoid(id, br) { id as uint | hash_bound_region(br) }
+ ty::br_self => 0u,
+ ty::br_anon => 1u,
+ ty::br_named(str) => str::hash(str),
+ ty::br_cap_avoid(id, br) => id as uint | hash_bound_region(br)
}
}
}
pure fn hash_region(r: ®ion) -> uint {
alt *r { // no idea if this is any good
- re_bound(br) { (hash_bound_region(&br)) << 2u | 0u }
- re_free(id, br) { ((id as uint) << 4u) |
- (hash_bound_region(&br)) << 2u | 1u }
- re_scope(id) { ((id as uint) << 2u) | 2u }
- re_var(id) { (id.to_uint() << 2u) | 3u }
- re_bot { 4u }
+ re_bound(br) => (hash_bound_region(&br)) << 2u | 0u,
+ re_free(id, br) => ((id as uint) << 4u) |
+ (hash_bound_region(&br)) << 2u | 1u,
+ re_scope(id) => ((id as uint) << 2u) | 2u,
+ re_var(id) => (id.to_uint() << 2u) | 3u,
+ re_bot => 4u
}
}
pure fn hash_substs(h: uint, substs: substs) -> uint {
h + substs.self_r.map_default(0u, |r| hash_region(&r))
}
alt st {
- ty_nil { 0u } ty_bool { 1u }
- ty_int(t) {
- alt t {
- ast::ty_i { 2u } ast::ty_char { 3u } ast::ty_i8 { 4u }
- ast::ty_i16 { 5u } ast::ty_i32 { 6u } ast::ty_i64 { 7u }
- }
- }
- ty_uint(t) {
- alt t {
- ast::ty_u { 8u } ast::ty_u8 { 9u } ast::ty_u16 { 10u }
- ast::ty_u32 { 11u } ast::ty_u64 { 12u }
- }
- }
- ty_float(t) {
- alt t { ast::ty_f { 13u } ast::ty_f32 { 14u } ast::ty_f64 { 15u } }
- }
- ty_estr(_) { 16u }
- ty_enum(did, substs) {
+ ty_nil => 0u,
+ ty_bool => 1u,
+ ty_int(t) => alt t {
+ ast::ty_i => 2u,
+ ast::ty_char => 3u,
+ ast::ty_i8 => 4u,
+ ast::ty_i16 => 5u,
+ ast::ty_i32 => 6u,
+ ast::ty_i64 => 7u
+ }
+ ty_uint(t) => alt t {
+ ast::ty_u => 8u,
+ ast::ty_u8 => 9u,
+ ast::ty_u16 => 10u,
+ ast::ty_u32 => 11u,
+ ast::ty_u64 => 12u
+ }
+ ty_float(t) => alt t {
+ ast::ty_f => 13u,
+ ast::ty_f32 => 14u,
+ ast::ty_f64 => 15u
+ }
+ ty_estr(_) => 16u,
+ ty_enum(did, substs) => {
let mut h = hash_def(18u, did);
hash_substs(h, substs)
}
- ty_box(mt) { hash_subty(19u, mt.ty) }
- ty_evec(mt, _) { hash_subty(20u, mt.ty) }
- ty_unboxed_vec(mt) { hash_subty(22u, mt.ty) }
- ty_tup(ts) { hash_subtys(25u, ts) }
- ty_rec(fields) {
+ ty_box(mt) => hash_subty(19u, mt.ty),
+ ty_evec(mt, _) => hash_subty(20u, mt.ty),
+ ty_unboxed_vec(mt) => hash_subty(22u, mt.ty),
+ ty_tup(ts) => hash_subtys(25u, ts),
+ ty_rec(fields) => {
let mut h = 26u;
for vec::each(fields) |f| { h = hash_subty(h, f.mt.ty); }
h
}
- ty_fn(f) {
+ ty_fn(f) => {
let mut h = 27u;
for vec::each(f.inputs) |a| { h = hash_subty(h, a.ty); }
hash_subty(h, f.output)
}
- ty_self { 28u }
- ty_var(v) { hash_uint(29u, v.to_uint()) }
- ty_var_integral(v) { hash_uint(30u, v.to_uint()) }
- ty_param(p) { hash_def(hash_uint(31u, p.idx), p.def_id) }
- ty_type { 32u }
- ty_bot { 34u }
- ty_ptr(mt) { hash_subty(35u, mt.ty) }
- ty_uniq(mt) { hash_subty(37u, mt.ty) }
- ty_trait(did, substs) {
+ ty_self => 28u,
+ ty_var(v) => hash_uint(29u, v.to_uint()),
+ ty_var_integral(v) => hash_uint(30u, v.to_uint()),
+ ty_param(p) => hash_def(hash_uint(31u, p.idx), p.def_id),
+ ty_type => 32u,
+ ty_bot => 34u,
+ ty_ptr(mt) => hash_subty(35u, mt.ty),
+ ty_uniq(mt) => hash_subty(37u, mt.ty),
+ ty_trait(did, substs) => {
let mut h = hash_def(40u, did);
hash_substs(h, substs)
}
- ty_opaque_closure_ptr(ck_block) { 41u }
- ty_opaque_closure_ptr(ck_box) { 42u }
- ty_opaque_closure_ptr(ck_uniq) { 43u }
- ty_opaque_box { 44u }
- ty_class(did, substs) {
+ ty_opaque_closure_ptr(ck_block) => 41u,
+ ty_opaque_closure_ptr(ck_box) => 42u,
+ ty_opaque_closure_ptr(ck_uniq) => 43u,
+ ty_opaque_box => 44u,
+ ty_class(did, substs) => {
let mut h = hash_def(45u, did);
hash_substs(h, substs)
}
- ty_rptr(region, mt) {
+ ty_rptr(region, mt) => {
let mut h = (46u << 2u) + hash_region(®ion);
hash_subty(h, mt.ty)
}
fn node_id_to_type(cx: ctxt, id: ast::node_id) -> t {
alt smallintmap::find(*cx.node_types, id as uint) {
- some(t) { t }
- none { cx.sess.bug(fmt!{"node_id_to_type: unbound node ID %s",
- ast_map::node_id_to_str(cx.items, id)}); }
+ some(t) => t,
+ none => cx.sess.bug(fmt!{"node_id_to_type: unbound node ID %s",
+ ast_map::node_id_to_str(cx.items, id)})
}
}
fn node_id_to_type_params(cx: ctxt, id: ast::node_id) -> ~[t] {
alt cx.node_type_substs.find(id) {
- none { return ~[]; }
- some(ts) { return ts; }
+ none => return ~[],
+ some(ts) => return ts
}
}
// Type accessors for substructures of types
fn ty_fn_args(fty: t) -> ~[arg] {
alt get(fty).struct {
- ty_fn(f) { f.inputs }
- _ { fail ~"ty_fn_args() called on non-fn type"; }
+ ty_fn(f) => f.inputs,
+ _ => fail ~"ty_fn_args() called on non-fn type"
}
}
fn ty_fn_proto(fty: t) -> ast::proto {
alt get(fty).struct {
- ty_fn(f) { f.proto }
- _ { fail ~"ty_fn_proto() called on non-fn type"; }
+ ty_fn(f) => f.proto,
+ _ => fail ~"ty_fn_proto() called on non-fn type"
}
}
pure fn ty_fn_ret(fty: t) -> t {
alt get(fty).struct {
- ty_fn(f) { f.output }
- _ { fail ~"ty_fn_ret() called on non-fn type"; }
+ ty_fn(f) => f.output,
+ _ => fail ~"ty_fn_ret() called on non-fn type"
}
}
fn ty_fn_ret_style(fty: t) -> ast::ret_style {
alt get(fty).struct {
- ty_fn(f) { f.ret_style }
- _ { fail ~"ty_fn_ret_style() called on non-fn type"; }
+ ty_fn(f) => f.ret_style,
+ _ => fail ~"ty_fn_ret_style() called on non-fn type"
}
}
fn is_fn_ty(fty: t) -> bool {
alt get(fty).struct {
- ty_fn(_) { return true; }
- _ { return false; }
+ ty_fn(_) => return true,
+ _ => return false
}
}
fn ty_var_id(typ: t) -> tv_vid {
alt get(typ).struct {
- ty_var(vid) { return vid; }
- _ { error!{"ty_var_id called on non-var ty"}; fail; }
+ ty_var(vid) => return vid,
+ _ => { error!{"ty_var_id called on non-var ty"}; fail; }
}
}
fn ty_var_integral_id(typ: t) -> tvi_vid {
alt get(typ).struct {
- ty_var_integral(vid) { return vid; }
- _ { error!{"ty_var_integral_id called on ty other than \
+ ty_var_integral(vid) => return vid,
+ _ => { error!{"ty_var_integral_id called on ty other than \
ty_var_integral"};
fail; }
}
fn expr_is_lval(method_map: typeck::method_map, e: @ast::expr) -> bool {
alt e.node {
- ast::expr_path(_) | ast::expr_unary(ast::deref, _) { true }
- ast::expr_field(_, _, _) | ast::expr_index(_, _) {
+ ast::expr_path(_) | ast::expr_unary(ast::deref, _) => true,
+ ast::expr_field(_, _, _) | ast::expr_index(_, _) => {
!method_map.contains_key(e.id)
}
- _ { false }
+ _ => false
}
}
fn stmt_node_id(s: @ast::stmt) -> ast::node_id {
alt s.node {
- ast::stmt_decl(_, id) | stmt_expr(_, id) | stmt_semi(_, id) {
+ ast::stmt_decl(_, id) | stmt_expr(_, id) | stmt_semi(_, id) => {
return id;
}
}
fn get_field(rec_ty: t, id: ast::ident) -> field {
alt check vec::find(get_fields(rec_ty), |f| str::eq(f.ident, id)) {
- some(f) { f }
+ some(f) => f
}
}
fn get_fields(rec_ty:t) -> ~[field] {
alt check get(rec_ty).struct {
- ty_rec(fields) { fields }
+ ty_rec(fields) => fields
}
}
let mut rslt = ~[];
do walk_ty(ty) |ty| {
alt get(ty).struct {
- ty_param(p) {
+ ty_param(p) => {
vec::push(rslt, p);
}
- _ { }
+ _ => ()
}
}
rslt
fn vars_in_type(ty: t) -> ~[tv_vid] {
let mut rslt = ~[];
do walk_ty(ty) |ty| {
- alt get(ty).struct { ty_var(v) { vec::push(rslt, v); } _ { } }
+ alt get(ty).struct {
+ ty_var(v) => vec::push(rslt, v),
+ _ => ()
+ }
}
rslt
}
fn canon<T:copy>(tbl: hashmap<ast::node_id, ast::inferable<T>>,
m0: ast::inferable<T>) -> ast::inferable<T> {
alt m0 {
- ast::infer(id) {
- alt tbl.find(id) {
- none { m0 }
- some(m1) {
+ ast::infer(id) => alt tbl.find(id) {
+ none => m0,
+ some(m1) => {
let cm1 = canon(tbl, m1);
// path compression:
if cm1 != m1 { tbl.insert(id, cm1); }
cm1
- }
}
}
- _ { m0 }
+ _ => m0
}
}
// was never inferred. This should be safe for use after typeck.
fn resolved_mode(cx: ctxt, m: ast::mode) -> ast::rmode {
alt canon_mode(cx, m) {
- ast::infer(_) {
+ ast::infer(_) => {
cx.sess.bug(fmt!{"mode %? was never resolved", m});
}
- ast::expl(m0) { m0 }
+ ast::expl(m0) => m0
}
}
fn unify_mode(cx: ctxt, m1: ast::mode, m2: ast::mode)
-> result<ast::mode, type_err> {
alt (canon_mode(cx, m1), canon_mode(cx, m2)) {
- (m1, m2) if (m1 == m2) {
+ (m1, m2) if (m1 == m2) => {
result::ok(m1)
}
- (ast::infer(id1), ast::infer(id2)) {
+ (ast::infer(id1), ast::infer(id2)) => {
cx.inferred_modes.insert(id2, m1);
result::ok(m1)
}
- (ast::infer(id), m) | (m, ast::infer(id)) {
+ (ast::infer(id), m) | (m, ast::infer(id)) => {
cx.inferred_modes.insert(id, m);
result::ok(m1)
}
- (m1, m2) {
+ (m1, m2) => {
result::err(terr_mode_mismatch(m1, m2))
}
}
// for `m`.
fn set_default_mode(cx: ctxt, m: ast::mode, m_def: ast::rmode) {
alt canon_mode(cx, m) {
- ast::infer(id) {
+ ast::infer(id) => {
cx.inferred_modes.insert(id, ast::expl(m_def));
}
- ast::expl(_) { }
+ ast::expl(_) => ()
}
}
alt get(t).struct {
ty_nil | ty_bot | ty_bool | ty_int(_) |
ty_uint(_) | ty_float(_) | ty_estr(_) |
- ty_type | ty_opaque_box | ty_opaque_closure_ptr(_) {
+ ty_type | ty_opaque_box | ty_opaque_closure_ptr(_) => {
ty_to_str(cx, t)
}
- ty_enum(id, _) { fmt!{"enum %s", item_path_str(cx, id)} }
- ty_box(_) { ~"@-ptr" }
- ty_uniq(_) { ~"~-ptr" }
- ty_evec(_, _) { ~"vector" }
- ty_unboxed_vec(_) { ~"unboxed vector" }
- ty_ptr(_) { ~"*-ptr" }
- ty_rptr(_, _) { ~"&-ptr" }
- ty_rec(_) { ~"record" }
- ty_fn(_) { ~"fn" }
- ty_trait(id, _) { fmt!{"trait %s", item_path_str(cx, id)} }
- ty_class(id, _) { fmt!{"class %s", item_path_str(cx, id)} }
- ty_tup(_) { ~"tuple" }
- ty_var(_) { ~"variable" }
- ty_var_integral(_) { ~"integral variable" }
- ty_param(_) { ~"type parameter" }
- ty_self { ~"self" }
+ ty_enum(id, _) => fmt!{"enum %s", item_path_str(cx, id)},
+ ty_box(_) => ~"@-ptr",
+ ty_uniq(_) => ~"~-ptr",
+ ty_evec(_, _) => ~"vector",
+ ty_unboxed_vec(_) => ~"unboxed vector",
+ ty_ptr(_) => ~"*-ptr",
+ ty_rptr(_, _) => ~"&-ptr",
+ ty_rec(_) => ~"record",
+ ty_fn(_) => ~"fn",
+ ty_trait(id, _) => fmt!{"trait %s", item_path_str(cx, id)},
+ ty_class(id, _) => fmt!{"class %s", item_path_str(cx, id)},
+ ty_tup(_) => ~"tuple",
+ ty_var(_) => ~"variable",
+ ty_var_integral(_) => ~"integral variable",
+ ty_param(_) => ~"type parameter",
+ ty_self => ~"self"
}
}
fn type_err_to_str(cx: ctxt, err: type_err) -> ~str {
fn terr_vstore_kind_to_str(k: terr_vstore_kind) -> ~str {
- alt k { terr_vec { ~"[]" } terr_str { ~"str" } }
+ alt k { terr_vec => ~"[]", terr_str => ~"str" }
}
alt err {
- terr_mismatch { return ~"types differ"; }
- terr_ret_style_mismatch(expect, actual) {
+ terr_mismatch => return ~"types differ",
+ terr_ret_style_mismatch(expect, actual) => {
fn to_str(s: ast::ret_style) -> ~str {
alt s {
- ast::noreturn { ~"non-returning" }
- ast::return_val { ~"return-by-value" }
+ ast::noreturn => ~"non-returning",
+ ast::return_val => ~"return-by-value"
}
}
return to_str(actual) + ~" function found where " + to_str(expect) +
~" function was expected";
}
- terr_purity_mismatch(f1, f2) {
+ terr_purity_mismatch(f1, f2) => {
return fmt!{"expected %s fn but found %s fn",
purity_to_str(f1), purity_to_str(f2)};
}
- terr_proto_mismatch(e, a) {
+ terr_proto_mismatch(e, a) => {
return fmt!{"closure protocol mismatch (%s vs %s)",
proto_to_str(e), proto_to_str(a)};
}
- terr_mutability { return ~"values differ in mutability"; }
- terr_box_mutability { return ~"boxed values differ in mutability"; }
- terr_vec_mutability { return ~"vectors differ in mutability"; }
- terr_ptr_mutability { return ~"pointers differ in mutability"; }
- terr_ref_mutability { return ~"references differ in mutability"; }
- terr_ty_param_size(e_sz, a_sz) {
+ terr_mutability => return ~"values differ in mutability",
+ terr_box_mutability => return ~"boxed values differ in mutability",
+ terr_vec_mutability => return ~"vectors differ in mutability",
+ terr_ptr_mutability => return ~"pointers differ in mutability",
+ terr_ref_mutability => return ~"references differ in mutability",
+ terr_ty_param_size(e_sz, a_sz) => {
return ~"expected a type with " + uint::to_str(e_sz, 10u) +
~" type params but found one with " + uint::to_str(a_sz, 10u) +
~" type params";
}
- terr_tuple_size(e_sz, a_sz) {
+ terr_tuple_size(e_sz, a_sz) => {
return ~"expected a tuple with " + uint::to_str(e_sz, 10u) +
~" elements but found one with " + uint::to_str(a_sz, 10u) +
~" elements";
}
- terr_record_size(e_sz, a_sz) {
+ terr_record_size(e_sz, a_sz) => {
return ~"expected a record with " + uint::to_str(e_sz, 10u) +
~" fields but found one with " + uint::to_str(a_sz, 10u) +
~" fields";
}
- terr_record_mutability {
+ terr_record_mutability => {
return ~"record elements differ in mutability";
}
- terr_record_fields(e_fld, a_fld) {
+ terr_record_fields(e_fld, a_fld) => {
return ~"expected a record with field `" + *e_fld +
~"` but found one with field `" + *a_fld + ~"`";
}
- terr_arg_count { return ~"incorrect number of function parameters"; }
- terr_mode_mismatch(e_mode, a_mode) {
+ terr_arg_count => return ~"incorrect number of function parameters",
+ terr_mode_mismatch(e_mode, a_mode) => {
return ~"expected argument mode " + mode_to_str(e_mode) +
~" but found " + mode_to_str(a_mode);
}
- terr_regions_differ(subregion, superregion) {
+ terr_regions_differ(subregion, superregion) => {
return fmt!{"%s does not necessarily outlive %s",
explain_region(cx, subregion),
explain_region(cx, superregion)};
}
- terr_vstores_differ(k, e_vs, a_vs) {
+ terr_vstores_differ(k, e_vs, a_vs) => {
return fmt!{"%s storage differs: expected %s but found %s",
terr_vstore_kind_to_str(k),
vstore_to_str(cx, e_vs),
vstore_to_str(cx, a_vs)};
}
- terr_in_field(err, fname) {
+ terr_in_field(err, fname) => {
return fmt!{"in field `%s`, %s", *fname, type_err_to_str(cx, *err)};
}
- terr_sorts(exp, act) {
+ terr_sorts(exp, act) => {
return fmt!{"%s vs %s", ty_sort_str(cx, exp), ty_sort_str(cx, act)};
}
- terr_self_substs {
+ terr_self_substs => {
return ~"inconsistent self substitution"; // XXX this is more of a bug
}
- terr_no_integral_type {
+ terr_no_integral_type => {
return ~"couldn't determine an appropriate integral type for integer \
literal";
}
fn def_has_ty_params(def: ast::def) -> bool {
alt def {
ast::def_fn(_, _) | ast::def_variant(_, _) | ast::def_class(_, _)
- { true }
- _ { false }
+ => true,
+ _ => false
}
}
fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] {
alt cx.trait_method_cache.find(id) {
- some(ms) { return ms; }
- _ {}
+ some(ms) => return ms,
+ _ => ()
}
// Local traits are supposed to have been added explicitly.
assert id.crate != ast::local_crate;
some(ast_map::node_item(@{
node: ast::item_impl(_, trait_refs, _, _),
_},
- _)) {
+ _)) => {
do vec::map(trait_refs) |trait_ref| {
node_id_to_type(cx, trait_ref.ref_id)
}
}
some(ast_map::node_item(@{node: ast::item_class(*),
- _},_)) {
+ _},_)) => {
alt cx.def_map.find(id.node) {
- some(def_ty(trait_id)) {
+ some(def_ty(trait_id)) => {
// XXX: Doesn't work cross-crate.
debug!{"(impl_traits) found trait id %?", trait_id};
~[node_id_to_type(cx, trait_id.node)]
}
- some(x) {
+ some(x) => {
cx.sess.bug(fmt!{"impl_traits: trait ref is in trait map \
but is bound to %?", x});
}
- none {
+ none => {
~[]
}
}
}
- _ { ~[] }
+ _ => ~[]
}
} else {
csearch::get_impl_traits(cx, id)
fn ty_to_def_id(ty: t) -> option<ast::def_id> {
alt get(ty).struct {
- ty_trait(id, _) | ty_class(id, _) | ty_enum(id, _) {
- some(id)
- }
- _ { none }
+ ty_trait(id, _) | ty_class(id, _) | ty_enum(id, _) => some(id),
+ _ => none
}
}
alt cx.items.find(class_id.node) {
some(ast_map::node_item(@{node: ast::item_class(_, _, _, _,
some(dtor)), _}, _))
- { some(local_def(dtor.node.id)) }
- _ { none }
+ => some(local_def(dtor.node.id)),
+ _ => none
}
}
else {
} else {
let node = cx.items.get(id.node);
alt node {
- ast_map::node_item(item, path) {
+ ast_map::node_item(item, path) => {
let item_elt = alt item.node {
- item_mod(_) | item_foreign_mod(_) {
+ item_mod(_) | item_foreign_mod(_) => {
ast_map::path_mod(item.ident)
}
- _ {
+ _ => {
ast_map::path_name(item.ident)
}
};
vec::append_one(*path, item_elt)
}
- ast_map::node_foreign_item(nitem, _, path) {
+ ast_map::node_foreign_item(nitem, _, path) => {
vec::append_one(*path, ast_map::path_name(nitem.ident))
}
- ast_map::node_method(method, _, path) {
+ ast_map::node_method(method, _, path) => {
vec::append_one(*path, ast_map::path_name(method.ident))
}
- ast_map::node_trait_method(trait_method, _, path) {
+ ast_map::node_trait_method(trait_method, _, path) => {
let method = ast_util::trait_method_to_ty_method(*trait_method);
vec::append_one(*path, ast_map::path_name(method.ident))
}
- ast_map::node_variant(variant, _, path) {
+ ast_map::node_variant(variant, _, path) => {
vec::append_one(vec::init(*path),
ast_map::path_name(variant.node.name))
}
- ast_map::node_ctor(nm, _, _, _, path) {
+ ast_map::node_ctor(nm, _, _, _, path) => {
vec::append_one(*path, ast_map::path_name(nm))
}
- ast_map::node_dtor(_, _, _, path) {
+ ast_map::node_dtor(_, _, _, path) => {
vec::append_one(*path, ast_map::path_name(@~"dtor"))
}
ast_map::node_expr(_) | ast_map::node_arg(_, _) |
ast_map::node_local(_) | ast_map::node_export(_, _) |
- ast_map::node_block(_) {
+ ast_map::node_block(_) => {
cx.sess.bug(fmt!{"cannot find item_path for node %?", node});
}
}
fn type_is_empty(cx: ctxt, t: t) -> bool {
alt ty::get(t).struct {
- ty_enum(did, _) {
- (*enum_variants(cx, did)).is_empty()
- }
- _ { false }
+ ty_enum(did, _) => (*enum_variants(cx, did)).is_empty(),
+ _ => false
}
}
fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[variant_info] {
alt cx.enum_var_cache.find(id) {
- some(variants) { return variants; }
- _ { /* fallthrough */ }
+ some(variants) => return variants,
+ _ => { /* fallthrough */ }
}
let result = if ast::local_crate != id.crate {
expr, since check_enum_variants also updates the enum_var_cache
*/
alt cx.items.get(id.node) {
- ast_map::node_item(@{node: ast::item_enum(variants, _), _}, _) {
+ ast_map::node_item(@{node: ast::item_enum(variants, _), _}, _) => {
let mut disr_val = -1;
@vec::map(variants, |variant| {
let ctor_ty = node_id_to_type(cx, variant.node.id);
} else { ~[] }
};
alt variant.node.disr_expr {
- some (ex) {
+ some (ex) => {
// FIXME: issue #1417
disr_val = alt const_eval::eval_const_expr(cx, ex) {
- const_eval::const_int(val) {val as int}
- _ { cx.sess.bug(~"tag_variants: bad disr expr"); }
+ const_eval::const_int(val) =>val as int,
+ _ => cx.sess.bug(~"tag_variants: bad disr expr")
}
}
- _ {disr_val += 1;}
+ _ => disr_val += 1
}
@{args: arg_tys,
ctor_ty: ctor_ty,
}
})
}
- _ { cx.sess.bug(~"tag_variants: id not bound to an enum"); }
+ _ => cx.sess.bug(~"tag_variants: id not bound to an enum")
}
};
cx.enum_var_cache.insert(id, result);
// the type cache. Returns the type parameters and type.
fn lookup_item_type(cx: ctxt, did: ast::def_id) -> ty_param_bounds_and_ty {
alt cx.tcache.find(did) {
- some(tpt) { return tpt; }
- none {
+ some(tpt) => return tpt,
+ none => {
// The item is in this crate. The caller should have added it to the
// type cache already
assert did.crate != ast::local_crate;
}
else {
alt tcx.tcache.find(id) {
- some(tpt) { tpt.ty }
- none {
+ some(tpt) => tpt.ty,
+ none => {
let tpt = csearch::get_field_type(tcx, class_id, id);
tcx.tcache.insert(id, tpt);
tpt.ty
fn lookup_class_fields(cx: ctxt, did: ast::def_id) -> ~[field_ty] {
if did.crate == ast::local_crate {
alt cx.items.find(did.node) {
- some(ast_map::node_item(i,_)) {
+ some(ast_map::node_item(i,_)) => {
alt i.node {
- ast::item_class(_, _, items, _, _) {
+ ast::item_class(_, _, items, _, _) => {
class_field_tys(items)
}
- _ { cx.sess.bug(~"class ID bound to non-class"); }
+ _ => cx.sess.bug(~"class ID bound to non-class")
}
}
- _ {
+ _ => {
cx.sess.bug(fmt!{"class ID not bound to an item: %s",
ast_map::node_id_to_str(cx.items, did.node)});
}
-> field_ty {
alt vec::find(lookup_class_fields(cx, parent),
|f| f.id.node == field_id.node) {
- some(t) { t }
- none { cx.sess.bug(~"class ID not found in parent's fields"); }
+ some(t) => t,
+ none => cx.sess.bug(~"class ID not found in parent's fields")
}
}
assert is_local(did);
alt cx.items.find(did.node) {
- some(ast_map::node_item(@{node: item_class(_,_,items,_,_), _}, _)) {
+ some(ast_map::node_item(@{
+ node: item_class(_,_,items,_,_), _
+ }, _)) => {
let (_,ms) = split_class_items(items);
vec::map(ms, |m| {name: m.ident, id: m.id,
vis: m.vis})
}
- _ {
+ _ => {
cx.sess.bug(~"lookup_class_method_ids: id not bound to a class");
}
}
let mut rslt = ~[];
for items.each |it| {
alt it.node {
- instance_var(nm, _, cm, id, vis) {
+ instance_var(nm, _, cm, id, vis) => {
vec::push(rslt, {ident: nm, id: ast_util::local_def(id),
vis: vis, mutability: cm});
}
- class_method(_) { }
+ class_method(_) => ()
}
}
rslt
fn class_items_as_fields(cx:ctxt, did: ast::def_id,
substs: substs) -> ~[field] {
class_item_fields(cx, did, substs, |mt| alt mt {
- class_mutable { m_mutbl }
- class_immutable { m_imm }})
+ class_mutable => m_mutbl,
+ class_immutable => m_imm })
}
fn opcat(op: ast::binop) -> int {
alt op {
- ast::add { opcat_add }
- ast::subtract { opcat_sub }
- ast::mul { opcat_mult }
- ast::div { opcat_mult }
- ast::rem { opcat_mult }
- ast::and { opcat_logic }
- ast::or { opcat_logic }
- ast::bitxor { opcat_bit }
- ast::bitand { opcat_bit }
- ast::bitor { opcat_bit }
- ast::shl { opcat_shift }
- ast::shr { opcat_shift }
- ast::eq { opcat_eq }
- ast::ne { opcat_eq }
- ast::lt { opcat_rel }
- ast::le { opcat_rel }
- ast::ge { opcat_rel }
- ast::gt { opcat_rel }
+ ast::add => opcat_add,
+ ast::subtract => opcat_sub,
+ ast::mul => opcat_mult,
+ ast::div => opcat_mult,
+ ast::rem => opcat_mult,
+ ast::and => opcat_logic,
+ ast::or => opcat_logic,
+ ast::bitxor => opcat_bit,
+ ast::bitand => opcat_bit,
+ ast::bitor => opcat_bit,
+ ast::shl => opcat_shift,
+ ast::shr => opcat_shift,
+ ast::eq => opcat_eq,
+ ast::ne => opcat_eq,
+ ast::lt => opcat_rel,
+ ast::le => opcat_rel,
+ ast::ge => opcat_rel,
+ ast::gt => opcat_rel
}
}
fn tycat(ty: t) -> int {
alt get(ty).struct {
- ty_bool { tycat_bool }
- ty_int(_) | ty_uint(_) | ty_var_integral(_) { tycat_int }
- ty_float(_) { tycat_float }
- ty_rec(_) | ty_tup(_) | ty_enum(_, _) { tycat_struct }
- ty_bot { tycat_bot }
- _ { tycat_other }
+ ty_bool => tycat_bool,
+ ty_int(_) | ty_uint(_) | ty_var_integral(_) => tycat_int,
+ ty_float(_) => tycat_float,
+ ty_rec(_) | ty_tup(_) | ty_enum(_, _) => tycat_struct,
+ ty_bot => tycat_bot,
+ _ => tycat_other
}
}
}
alt cx.normalized_cache.find(t) {
- some(t) { return t; }
- none { }
+ some(t) => return t,
+ none => ()
}
let t = match get(t).struct {
fn lookup_def_tcx(tcx: ty::ctxt, sp: span, id: ast::node_id) -> ast::def {
alt tcx.def_map.find(id) {
- some(x) { x }
- _ {
+ some(x) => x,
+ _ => {
tcx.sess.span_fatal(sp, ~"internal error looking up a definition")
}
}
let l_tcx, l_infcx;
alt maybe_infcx {
- none {
+ none => {
l_tcx = tcx;
l_infcx = infer::new_infer_ctxt(tcx);
}
- some(i) {
+ some(i) => {
l_tcx = i.tcx;
l_infcx = i;
}
}
alt infer::mk_eqty(l_infcx, t1, t2) {
- result::ok(()) { true }
- result::err(terr) {
+ result::ok(()) => true,
+ result::err(terr) => {
l_tcx.sess.span_err(span, msg() + ~": " +
ty::type_err_to_str(l_tcx, terr));
false
fn arg_is_argv_ty(_tcx: ty::ctxt, a: ty::arg) -> bool {
alt ty::get(a.ty).struct {
- ty::ty_evec(mt, vstore_uniq) {
+ ty::ty_evec(mt, vstore_uniq) => {
if mt.mutbl != ast::m_imm { return false; }
alt ty::get(mt.ty).struct {
- ty::ty_estr(vstore_uniq) { return true; }
- _ { return false; }
+ ty::ty_estr(vstore_uniq) => return true,
+ _ => return false
}
}
- _ { return false; }
+ _ => return false
}
}
let main_t = ty::node_id_to_type(tcx, main_id);
alt ty::get(main_t).struct {
ty::ty_fn({purity: ast::impure_fn, proto: ast::proto_bare,
- inputs, output, ret_style: ast::return_val}) {
+ inputs, output, ret_style: ast::return_val}) => {
alt tcx.items.find(main_id) {
- some(ast_map::node_item(it,_)) {
+ some(ast_map::node_item(it,_)) => {
alt it.node {
- ast::item_fn(_,ps,_) if vec::is_not_empty(ps) {
+ ast::item_fn(_,ps,_) if vec::is_not_empty(ps) => {
tcx.sess.span_err(main_span,
~"main function is not allowed to have type parameters");
return;
}
- _ {}
+ _ => ()
}
}
- _ {}
+ _ => ()
}
let mut ok = ty::type_is_nil(output);
let num_args = vec::len(inputs);
ty_to_str(tcx, main_t)});
}
}
- _ {
+ _ => {
tcx.sess.span_bug(main_span,
~"main has a non-function type: found `" +
ty_to_str(tcx, main_t) + ~"`");
let tcx = ccx.tcx;
if !tcx.sess.building_library {
alt copy tcx.sess.main_fn {
- some((id, sp)) { check_main_fn_ty(ccx, id, sp); }
- none { tcx.sess.err(~"main function not found"); }
+ some((id, sp)) => check_main_fn_ty(ccx, id, sp),
+ none => tcx.sess.err(~"main function not found")
}
}
}
res: result<ty::region, ~str>) -> ty::region {
alt res {
- result::ok(r) { r }
- result::err(e) {
+ result::ok(r) => r,
+ result::err(e) => {
tcx.sess.span_err(span, e);
ty::re_static
}
self: AC, rscope: RS, span: span, a_r: @ast::region) -> ty::region {
let res = alt a_r.node {
- ast::re_anon { rscope.anon_region() }
- ast::re_named(id) { rscope.named_region(id) }
+ ast::re_anon => rscope.anon_region(),
+ ast::re_named(id) => rscope.named_region(id)
};
get_region_reporting_err(self.tcx(), span, res)
// region with the current anon region binding (in other words,
// whatever & would get replaced with).
let self_r = alt (decl_rp, path.rp) {
- (false, none) {
+ (false, none) => {
none
}
- (false, some(_)) {
+ (false, some(_)) => {
tcx.sess.span_err(
path.span,
fmt!{"no region bound is allowed on `%s`, \
ty::item_path_str(tcx, did)});
none
}
- (true, none) {
+ (true, none) => {
let res = rscope.anon_region();
let r = get_region_reporting_err(self.tcx(), path.span, res);
some(r)
}
- (true, some(r)) {
+ (true, some(r)) => {
some(ast_region_to_region(self, rscope, path.span, r))
}
};
alt a_seq_ty.ty.node {
// to convert to an e{vec,str}, there can't be a mutability argument
- _ if a_seq_ty.mutbl != ast::m_imm {}
- ast::ty_vec(mt) {
+ _ if a_seq_ty.mutbl != ast::m_imm => (),
+ ast::ty_vec(mt) => {
return ty::mk_evec(tcx, ast_mt_to_mt(self, rscope, mt), vst);
}
- ast::ty_path(path, id) {
+ ast::ty_path(path, id) => {
alt tcx.def_map.find(id) {
- some(ast::def_prim_ty(ast::ty_str)) {
+ some(ast::def_prim_ty(ast::ty_str)) => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
return ty::mk_estr(tcx, vst);
}
- _ {}
+ _ => ()
}
}
- _ {}
+ _ => ()
}
let seq_ty = ast_mt_to_mt(self, rscope, a_seq_ty);
let tcx = self.tcx();
alt tcx.ast_ty_to_ty_cache.find(ast_ty) {
- some(ty::atttce_resolved(ty)) { return ty; }
- some(ty::atttce_unresolved) {
+ some(ty::atttce_resolved(ty)) => return ty,
+ some(ty::atttce_unresolved) => {
tcx.sess.span_fatal(ast_ty.span, ~"illegal recursive type; \
insert an enum in the cycle, \
if this is desired");
}
- none { /* go on */ }
+ none => { /* go on */ }
}
tcx.ast_ty_to_ty_cache.insert(ast_ty, ty::atttce_unresolved);
let typ = alt ast_ty.node {
- ast::ty_nil { ty::mk_nil(tcx) }
- ast::ty_bot { ty::mk_bot(tcx) }
- ast::ty_box(mt) {
+ ast::ty_nil => ty::mk_nil(tcx),
+ ast::ty_bot => ty::mk_bot(tcx),
+ ast::ty_box(mt) => {
mk_maybe_vstore(self, rscope, mt, ty::vstore_box,
|tmt| ty::mk_box(tcx, tmt))
}
- ast::ty_uniq(mt) {
+ ast::ty_uniq(mt) => {
mk_maybe_vstore(self, rscope, mt, ty::vstore_uniq,
|tmt| ty::mk_uniq(tcx, tmt))
}
- ast::ty_vec(mt) {
+ ast::ty_vec(mt) => {
tcx.sess.span_err(ast_ty.span,
~"bare `[]` is not a type");
// return /something/ so they can at least get more errors
ty::mk_evec(tcx, ast_mt_to_mt(self, rscope, mt),
ty::vstore_uniq)
}
- ast::ty_ptr(mt) {
+ ast::ty_ptr(mt) => {
ty::mk_ptr(tcx, ast_mt_to_mt(self, rscope, mt))
}
- ast::ty_rptr(region, mt) {
+ ast::ty_rptr(region, mt) => {
let r = ast_region_to_region(self, rscope, ast_ty.span, region);
mk_maybe_vstore(self, in_anon_rscope(rscope, r), mt,
ty::vstore_slice(r),
|tmt| ty::mk_rptr(tcx, r, tmt))
}
- ast::ty_tup(fields) {
+ ast::ty_tup(fields) => {
let flds = vec::map(fields, |t| ast_ty_to_ty(self, rscope, t));
ty::mk_tup(tcx, flds)
}
- ast::ty_rec(fields) {
+ ast::ty_rec(fields) => {
let flds = do fields.map |f| {
let tm = ast_mt_to_mt(self, rscope, f.node.mt);
{ident: f.node.ident, mt: tm}
};
ty::mk_rec(tcx, flds)
}
- ast::ty_fn(proto, decl) {
+ ast::ty_fn(proto, decl) => {
ty::mk_fn(tcx, ty_of_fn_decl(self, rscope, proto, decl, none))
}
- ast::ty_path(path, id) {
+ ast::ty_path(path, id) => {
let a_def = alt tcx.def_map.find(id) {
- none { tcx.sess.span_fatal(ast_ty.span, fmt!{"unbound path %s",
- path_to_str(path)}); }
- some(d) { d }};
+ none => tcx.sess.span_fatal(ast_ty.span, fmt!{"unbound path %s",
+ path_to_str(path)}),
+ some(d) => d
+ };
alt a_def {
- ast::def_ty(did) | ast::def_class(did, _) {
+ ast::def_ty(did) | ast::def_class(did, _) => {
ast_path_to_ty(self, rscope, did, path, id).ty
}
- ast::def_prim_ty(nty) {
+ ast::def_prim_ty(nty) => {
alt nty {
- ast::ty_bool {
+ ast::ty_bool => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
ty::mk_bool(tcx)
}
- ast::ty_int(it) {
+ ast::ty_int(it) => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
ty::mk_mach_int(tcx, it)
}
- ast::ty_uint(uit) {
+ ast::ty_uint(uit) => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
ty::mk_mach_uint(tcx, uit)
}
- ast::ty_float(ft) {
+ ast::ty_float(ft) => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
ty::mk_mach_float(tcx, ft)
}
- ast::ty_str {
+ ast::ty_str => {
tcx.sess.span_err(ast_ty.span,
~"bare `str` is not a type");
// return /something/ so they can at least get more errors
}
}
}
- ast::def_ty_param(id, n) {
+ ast::def_ty_param(id, n) => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
ty::mk_param(tcx, n, id)
}
- ast::def_self(_) {
+ ast::def_self(_) => {
// n.b.: resolve guarantees that the self type only appears in a
// trait, which we rely upon in various places when creating
// substs
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
ty::mk_self(tcx)
}
- _ {
+ _ => {
tcx.sess.span_fatal(ast_ty.span,
~"found type name used as a variable");
}
}
}
- ast::ty_fixed_length(a_t, some(u)) {
+ ast::ty_fixed_length(a_t, some(u)) => {
mk_maybe_vstore(self, rscope, {ty: a_t, mutbl: ast::m_imm},
ty::vstore_fixed(u),
|ty| {
ty.ty
})
}
- ast::ty_fixed_length(_, none) {
+ ast::ty_fixed_length(_, none) => {
tcx.sess.span_bug(
ast_ty.span,
~"implied fixed length for bound");
}
- ast::ty_infer {
+ ast::ty_infer => {
// ty_infer should only appear as the type of arguments or return
// values in a fn_expr, or as the type of local variables. Both of
// these cases are handled specially and should not descend into this
ast_ty.span,
~"found `ty_infer` in unexpected place");
}
- ast::ty_mac(_) {
+ ast::ty_mac(_) => {
tcx.sess.span_bug(ast_ty.span,
~"found `ty_mac` in unexpected place");
}
expected_ty: option<ty::arg>) -> ty::arg {
let ty = alt a.ty.node {
- ast::ty_infer if expected_ty.is_some() {expected_ty.get().ty}
- ast::ty_infer {self.ty_infer(a.ty.span)}
- _ {ast_ty_to_ty(self, rscope, a.ty)}
+ ast::ty_infer if expected_ty.is_some() => expected_ty.get().ty,
+ ast::ty_infer => self.ty_infer(a.ty.span),
+ _ => ast_ty_to_ty(self, rscope, a.ty)
};
let mode = {
alt a.mode {
- ast::infer(_) if expected_ty.is_some() {
+ ast::infer(_) if expected_ty.is_some() => {
result::get(ty::unify_mode(self.tcx(), a.mode,
expected_ty.get().mode))
}
- ast::infer(_) {
+ ast::infer(_) => {
alt ty::get(ty).struct {
// If the type is not specified, then this must be a fn expr.
// Leave the mode as infer(_), it will get inferred based
// on constraints elsewhere.
- ty::ty_var(_) {a.mode}
+ ty::ty_var(_) => a.mode,
// If the type is known, then use the default for that type.
// Here we unify m and the default. This should update the
// tables in tcx but should never fail, because nothing else
// will have been unified with m yet:
- _ {
+ _ => {
let m1 = ast::expl(ty::default_arg_mode_for_ty(ty));
result::get(ty::unify_mode(self.tcx(), a.mode, m1))
}
}
}
- ast::expl(_) {a.mode}
+ ast::expl(_) => a.mode
}
};
let expected_ret_ty = expected_tys.map(|e| e.output);
let output_ty = alt decl.output.node {
- ast::ty_infer if expected_ret_ty.is_some() {expected_ret_ty.get()}
- ast::ty_infer {self.ty_infer(decl.output.span)}
- _ {ast_ty_to_ty(self, rb, decl.output)}
+ ast::ty_infer if expected_ret_ty.is_some() => expected_ret_ty.get(),
+ ast::ty_infer => self.ty_infer(decl.output.span),
+ _ => ast_ty_to_ty(self, rb, decl.output)
};
{purity: decl.purity, proto: proto, inputs: input_tys,
id: ast::node_id,
self_info: option<self_info>) {
let fty = ty::node_id_to_type(ccx.tcx, id);
- let fn_ty = alt check ty::get(fty).struct { ty::ty_fn(f) {f} };
+ let fn_ty = alt check ty::get(fty).struct { ty::ty_fn(f) => f };
check_fn(ccx, self_info, fn_ty, decl, body, false, none);
}
let fcx: @fn_ctxt = {
let {infcx, locals, purity, node_types, node_type_substs} =
alt old_fcx {
- none {
+ none => {
{infcx: infer::new_infer_ctxt(tcx),
locals: int_hash(),
purity: decl.purity,
node_types: map::int_hash(),
node_type_substs: map::int_hash()}
}
- some(fcx) {
+ some(fcx) => {
assert decl.purity == ast::impure_fn;
{infcx: fcx.infcx,
locals: fcx.locals,
let indirect_ret_ty = if indirect_ret {
let ofcx = option::get(old_fcx);
alt ofcx.indirect_ret_ty {
- some(t) { some(t) }
- none { some(ofcx.ret_ty) }
+ some(t) => some(t),
+ none => some(ofcx.ret_ty)
}
} else { none };
// We unify the tail expr's type with the
// function result type, if there is a tail expr.
alt body.node.expr {
- some(tail_expr) {
+ some(tail_expr) => {
let tail_expr_ty = fcx.expr_ty(tail_expr);
demand::suptype(fcx, tail_expr.span, fcx.ret_ty, tail_expr_ty);
}
- none { }
+ none => ()
}
let mut i = 0u;
let var_id = fcx.infcx.next_ty_var_id();
fcx.locals.insert(nid, var_id);
alt ty_opt {
- none {/* nothing to do */ }
- some(typ) {
+ none => {/* nothing to do */ }
+ some(typ) => {
infer::mk_eqty(fcx.infcx, ty::mk_var(tcx, var_id), typ);
}
}
let visit_local = fn@(local: @ast::local,
&&e: (), v: visit::vt<()>) {
let o_ty = alt local.node.ty.node {
- ast::ty_infer { none }
- _ { some(fcx.to_ty(local.node.ty)) }
+ ast::ty_infer => none,
+ _ => some(fcx.to_ty(local.node.ty))
};
assign(local.node.id, o_ty);
debug!{"Local variable %s is assigned to %s",
fn check_class_member(ccx: @crate_ctxt, class_t: self_info,
cm: @ast::class_member) {
alt cm.node {
- ast::instance_var(_,t,_,_,_) { }
- ast::class_method(m) {
- check_method(ccx, m, class_t);
- }
+ ast::instance_var(_,t,_,_,_) => (),
+ ast::class_method(m) => check_method(ccx, m, class_t)
}
}
for fields.each |p| {
let (id, sp) = p;
alt field_names.find(id) {
- some(orig_sp) {
+ some(orig_sp) => {
tcx.sess.span_err(sp, fmt!{"Duplicate field \
name %s in record type declaration",
*id});
this field occurred here");
break;
}
- none {
+ none => {
field_names.insert(id, sp);
}
}
fn check_item(ccx: @crate_ctxt, it: @ast::item) {
alt it.node {
- ast::item_const(_, e) { check_const(ccx, it.span, e, it.id); }
- ast::item_enum(vs, _) {
+ ast::item_const(_, e) => check_const(ccx, it.span, e, it.id),
+ ast::item_enum(vs, _) => {
check_enum_variants(ccx, it.span, vs, it.id);
}
- ast::item_fn(decl, tps, body) {
+ ast::item_fn(decl, tps, body) => {
check_bare_fn(ccx, decl, body, it.id, none);
}
- ast::item_impl(tps, _, ty, ms) {
+ ast::item_impl(tps, _, ty, ms) => {
let rp = ccx.tcx.region_paramd_items.contains_key(it.id);
debug!{"item_impl %s with id %d rp %b",
*it.ident, it.id, rp};
node_id: it.id };
for ms.each |m| { check_method(ccx, m, self_info);}
}
- ast::item_trait(_, _, trait_methods) {
+ ast::item_trait(_, _, trait_methods) => {
for trait_methods.each |trait_method| {
alt trait_method {
- required(ty_m) {
+ required(ty_m) => {
// Nothing to do, since required methods don't have
// bodies to check.
}
- provided(m) {
+ provided(m) => {
let self_info = {self_ty: ty::mk_self(ccx.tcx),
node_id: it.id};
check_method(ccx, m, self_info);
}
}
}
- ast::item_class(tps, _, members, m_ctor, m_dtor) {
+ ast::item_class(tps, _, members, m_ctor, m_dtor) => {
let tcx = ccx.tcx;
let class_t = {self_ty: ty::node_id_to_type(tcx, it.id),
node_id: it.id};
// Check that the class is instantiable
check_instantiable(ccx.tcx, it.span, it.id);
}
- ast::item_ty(t, tps) {
+ ast::item_ty(t, tps) => {
let tpt_ty = ty::node_id_to_type(ccx.tcx, it.id);
check_bounds_are_used(ccx, t.span, tps, tpt_ty);
// If this is a record ty, check for duplicate fields
alt t.node {
- ast::ty_rec(fields) {
+ ast::ty_rec(fields) => {
check_no_duplicate_fields(ccx.tcx, fields.map(|f|
(f.node.ident, f.span)));
}
- _ {}
+ _ => ()
}
}
- ast::item_foreign_mod(m) {
+ ast::item_foreign_mod(m) => {
if syntax::attr::foreign_abi(it.attrs) ==
either::right(ast::foreign_abi_rust_intrinsic) {
for m.items.each |item| {
}
}
}
- _ {/* nothing to do */ }
+ _ => {/* nothing to do */ }
}
}
fn named_region(id: ast::ident) -> result<ty::region, ~str> {
do empty_rscope.named_region(id).chain_err |_e| {
alt self.in_scope_regions.find(ty::br_named(id)) {
- some(r) { result::ok(r) }
- none if *id == ~"blk" { self.block_region() }
- none {
+ some(r) => result::ok(r),
+ none if *id == ~"blk" => self.block_region(),
+ none => {
result::err(fmt!{"named region `%s` not in scope here", *id})
}
}
fn expr_ty(ex: @ast::expr) -> ty::t {
alt self.node_types.find(ex.id) {
- some(t) { t }
- none {
+ some(t) => t,
+ none => {
self.tcx().sess.bug(fmt!{"no type for expr %d (%s) in fcx %s",
ex.id, expr_to_str(ex), self.tag()});
}
}
fn node_ty(id: ast::node_id) -> ty::t {
alt self.node_types.find(id) {
- some(t) { t }
- none {
+ some(t) => t,
+ none => {
self.tcx().sess.bug(
fmt!{"no type for node %d: %s in fcx %s",
id, ast_map::node_id_to_str(self.tcx().items, id),
}
fn node_ty_substs(id: ast::node_id) -> ty::substs {
alt self.node_type_substs.find(id) {
- some(ts) { ts }
- none {
+ some(ts) => ts,
+ none => {
self.tcx().sess.bug(
fmt!{"no type substs for node %d: %s in fcx %s",
id, ast_map::node_id_to_str(self.tcx().items, id),
fn require_unsafe(sp: span, op: ~str) {
alt self.purity {
- ast::unsafe_fn {/*ok*/}
- _ {
+ ast::unsafe_fn => {/*ok*/}
+ _ => {
self.ccx.tcx.sess.span_err(
sp,
fmt!{"%s requires unsafe function or block", op});
// Some extra checks to detect weird cycles and so forth:
alt sty {
- ty::ty_box(inner) | ty::ty_uniq(inner) | ty::ty_rptr(_, inner) {
+ ty::ty_box(inner) | ty::ty_uniq(inner) | ty::ty_rptr(_, inner) => {
alt ty::get(t1).struct {
- ty::ty_var(v1) {
+ ty::ty_var(v1) => {
ty::occurs_check(fcx.ccx.tcx, sp, v1,
ty::mk_box(fcx.ccx.tcx, inner));
}
- _ { }
+ _ => ()
}
}
- ty::ty_enum(did, substs) {
+ ty::ty_enum(did, substs) => {
// Watch out for a type like `enum t = @t`. Such a type would
// otherwise infinitely auto-deref. This is the only autoderef
// loop that needs to be concerned with this, as an error will be
}
vec::push(enum_dids, did);
}
- _ { /*ok*/ }
+ _ => { /*ok*/ }
}
// Otherwise, deref if type is derefable:
alt ty::deref_sty(fcx.ccx.tcx, sty, false) {
- none { return t1; }
- some(mt) { t1 = mt.ty; }
+ none => return t1,
+ some(mt) => t1 = mt.ty
}
};
}
let tcx = fcx.ccx.tcx;
alt lit.node {
- ast::lit_str(s) => { ty::mk_estr(tcx, ty::vstore_slice(ty::re_static)) }
- ast::lit_int(_, t) { ty::mk_mach_int(tcx, t) }
- ast::lit_uint(_, t) { ty::mk_mach_uint(tcx, t) }
- ast::lit_int_unsuffixed(_) {
+ ast::lit_str(s) => ty::mk_estr(tcx, ty::vstore_slice(ty::re_static)),
+ ast::lit_int(_, t) => ty::mk_mach_int(tcx, t),
+ ast::lit_uint(_, t) => ty::mk_mach_uint(tcx, t),
+ ast::lit_int_unsuffixed(_) => {
// An unsuffixed integer literal could have any integral type,
// so we create an integral type variable for it.
ty::mk_var_integral(tcx, fcx.infcx.next_ty_var_integral_id())
}
- ast::lit_float(_, t) { ty::mk_mach_float(tcx, t) }
- ast::lit_nil { ty::mk_nil(tcx) }
- ast::lit_bool(_) { ty::mk_bool(tcx) }
+ ast::lit_float(_, t) => ty::mk_mach_float(tcx, t),
+ ast::lit_nil => ty::mk_nil(tcx),
+ ast::lit_bool(_) => ty::mk_bool(tcx)
}
}
let rp = fcx.tcx().region_paramd_items.contains_key(did.node);
alt check tcx.items.find(did.node) {
some(ast_map::node_item(@{node: ast::item_impl(ts, _, st, _),
- _}, _)) {
+ _}, _)) => {
{n_tps: ts.len(),
rp: rp,
raw_ty: fcx.ccx.to_ty(rscope::type_rscope(rp), st)}
}
some(ast_map::node_item(@{node: ast::item_class(ts,
- _,_,_,_), id: class_id, _},_)) {
+ _,_,_,_), id: class_id, _},_)) => {
/* If the impl is a class, the self ty is just the class ty
(doing a no-op subst for the ty params; in the next step,
we substitute in fresh vars for them)
self_ty: none,
tps: ty::ty_params_to_tys(tcx, ts)})}
}
- _ { tcx.sess.bug(~"impl_self_ty: unbound item or item that \
+ _ => { tcx.sess.bug(~"impl_self_ty: unbound item or item that \
doesn't have a self_ty"); }
}
} else {
// functions. Therefore, we match one level of structure.
let fn_ty =
alt structure_of(fcx, sp, in_fty) {
- sty @ ty::ty_fn(fn_ty) {
+ sty @ ty::ty_fn(fn_ty) => {
replace_bound_regions_in_fn_ty(
fcx.ccx.tcx, @nil, none, fn_ty,
|_br| fcx.infcx.next_region_var_nb()).fn_ty
}
- sty {
+ sty => {
// I would like to make this span_err, but it's
// really hard due to the way that expr_bind() is
// written.
for [false, true]/_.each |check_blocks| {
for args.eachi |i, a| {
let is_block = alt a.node {
- ast::expr_fn_block(*) { true }
- _ { false }
+ ast::expr_fn_block(*) => true,
+ _ => false
};
if is_block == check_blocks {
let arg_ty = arg_tys[i];
// Index expressions need to be handled seperately, to inform
// them that they appear in call position.
let mut bot = alt f.node {
- ast::expr_field(base, field, tys) {
+ ast::expr_field(base, field, tys) => {
check_field(fcx, f, true, base, field, tys)
}
- _ { check_expr(fcx, f, none) }
+ _ => check_expr(fcx, f, none)
};
let fn_ty = fcx.expr_ty(f);
// Pull the return type out of the type of the function.
alt structure_of(fcx, sp, fty) {
- ty::ty_fn(f) {
+ ty::ty_fn(f) => {
bot |= (f.ret_style == ast::noreturn);
fcx.write_ty(call_expr_id, f.output);
return bot;
}
- _ { fcx.ccx.tcx.sess.span_fatal(sp, ~"calling non-function"); }
+ _ => fcx.ccx.tcx.sess.span_fatal(sp, ~"calling non-function")
}
}
_sp: span) -> bool {
let (if_t, if_bot) =
alt elsopt {
- some(els) {
+ some(els) => {
let if_t = fcx.infcx.next_ty_var();
let thn_bot = check_block(fcx, thn);
let thn_t = fcx.node_ty(thn.node.id);
let els_bot = check_expr_with(fcx, els, if_t);
(if_t, thn_bot & els_bot)
}
- none {
+ none => {
check_block_no_value(fcx, thn);
(ty::mk_nil(fcx.ccx.tcx), false)
}
let lkup = method::lookup(fcx, op_ex, self_ex, op_ex.id,
op_ex.callee_id, @opname, self_t, ~[], false);
alt lkup.method() {
- some(origin) {
+ some(origin) => {
let {fty: method_ty, bot: bot} = {
let method_ty = fcx.node_ty(op_ex.callee_id);
check_call_inner(fcx, op_ex.span, op_ex.id,
fcx.ccx.method_map.insert(op_ex.id, origin);
some((ty::ty_fn_ret(method_ty), bot))
}
- _ { none }
+ _ => none
}
}
// could be either a expr_binop or an expr_assign_binop
let lhs_t = structurally_resolved_type(fcx, lhs.span, lhs_t);
return alt (op, ty::get(lhs_t).struct) {
(_, _) if ty::type_is_integral(lhs_t) &&
- ast_util::is_shift_binop(op) {
+ ast_util::is_shift_binop(op) => {
// Shift is a special case: rhs can be any integral type
let rhs_bot = check_expr(fcx, rhs, none);
let rhs_t = fcx.expr_ty(rhs);
lhs_bot | rhs_bot
}
- (_, _) if ty::is_binopable(tcx, lhs_t, op) {
+ (_, _) if ty::is_binopable(tcx, lhs_t, op) => {
let tvar = fcx.infcx.next_ty_var();
demand::suptype(fcx, expr.span, tvar, lhs_t);
let rhs_bot = check_expr_with(fcx, rhs, tvar);
let rhs_t = alt op {
ast::eq | ast::lt | ast::le | ast::ne | ast::ge |
- ast::gt {
+ ast::gt => {
// these comparison operators are handled in a
// separate case below.
tcx.sess.span_bug(
fmt!{"comparison operator in expr_binop: %s",
ast_util::binop_to_str(op)});
}
- _ { lhs_t }
+ _ => lhs_t
};
fcx.write_ty(expr.id, rhs_t);
if !ast_util::lazy_binop(op) { lhs_bot | rhs_bot }
else { lhs_bot }
}
- (_, _) {
+ (_, _) => {
let (result, rhs_bot) =
check_user_binop(fcx, expr, lhs, lhs_t, op, rhs);
fcx.write_ty(expr.id, result);
op: ast::binop, rhs: @ast::expr) -> (ty::t, bool) {
let tcx = fcx.ccx.tcx;
alt ast_util::binop_to_method_name(op) {
- some(name) {
+ some(name) => {
alt lookup_op_method(fcx, ex,
lhs_expr, lhs_resolved_t,
name, ~[rhs]) {
- some(pair) { return pair; }
- _ {}
+ some(pair) => return pair,
+ _ => ()
}
}
- _ {}
+ _ => ()
}
check_expr(fcx, rhs, none);
// supply the do keyword. Let's be more helpful in that situation.
if op == ast::or {
alt ty::get(lhs_resolved_t).struct {
- ty::ty_fn(f) {
+ ty::ty_fn(f) => {
tcx.sess.span_note(
ex.span, ~"did you forget the 'do' keyword for the call?");
}
- _ {}
+ _ => ()
}
}
ex: @ast::expr,
rhs_expr: @ast::expr, rhs_t: ty::t) -> ty::t {
alt lookup_op_method(fcx, ex, rhs_expr, rhs_t, mname, ~[]) {
- some((ret_ty, _)) { ret_ty }
- _ {
+ some((ret_ty, _)) => ret_ty,
+ _ => {
fcx.ccx.tcx.sess.span_err(
ex.span, fmt!{"cannot apply unary operator `%s` to type `%s`",
op_str, fcx.infcx.ty_to_str(rhs_t)});
unpack: fn(ty::sty) -> option<O>)
-> option<O> {
alt expected {
- some(t) {
+ some(t) => {
alt resolve_type(fcx.infcx, t, force_tvar) {
- result::ok(t) { unpack(ty::get(t).struct) }
- _ { none }
+ result::ok(t) => unpack(ty::get(t).struct),
+ _ => none
}
}
- _ { none }
+ _ => none
}
}
let mut handled = false;
let n_tys = vec::len(tys);
alt structure_of(fcx, expr.span, base_t) {
- ty::ty_rec(fields) {
+ ty::ty_rec(fields) => {
alt ty::field_idx(field, fields) {
- some(ix) {
+ some(ix) => {
if n_tys > 0u {
tcx.sess.span_err(expr.span,
~"can't provide type parameters \
fcx.write_ty(expr.id, fields[ix].mt.ty);
handled = true;
}
- _ {}
+ _ => ()
}
}
- ty::ty_class(base_id, substs) {
+ ty::ty_class(base_id, substs) => {
// This is just for fields -- the same code handles
// methods in both classes and traits
lookup_public_fields(tcx, base_id)
};
alt lookup_field_ty(tcx, base_id, cls_items, field, substs) {
- some(field_ty) {
+ some(field_ty) => {
// (2) look up what field's type is, and return it
fcx.write_ty(expr.id, field_ty);
handled = true;
}
- none {}
+ none => ()
}
}
- _ {}
+ _ => ()
}
if !handled {
let tps = vec::map(tys, |ty| fcx.to_ty(ty));
expr.id, field, expr_t, tps,
is_self_ref);
alt lkup.method() {
- some(entry) {
+ some(entry) => {
fcx.ccx.method_map.insert(expr.id, entry);
// If we have resolved to a method but this is not in
(try writing an anonymous function)");
}
}
- none {
+ none => {
let t_err = fcx.infcx.resolve_type_vars_if_possible(expr_t);
let msg = fmt!{"attempted access of field `%s` on type `%s`, \
but no public field or method with that name \
let id = expr.id;
let mut bot = false;
alt expr.node {
- ast::expr_vstore(ev, vst) {
+ ast::expr_vstore(ev, vst) => {
let typ = alt ev.node {
ast::expr_lit(@{node: ast::lit_str(s), span:_}) => {
let tt = ast_expr_vstore_to_vstore(fcx, ev, str::len(*s), vst);
fcx.write_ty(id, typ);
}
- ast::expr_lit(lit) {
+ ast::expr_lit(lit) => {
let typ = check_lit(fcx, lit);
fcx.write_ty(id, typ);
}
ast::expr_binary(ast::lt, lhs, rhs) |
ast::expr_binary(ast::le, lhs, rhs) |
ast::expr_binary(ast::gt, lhs, rhs) |
- ast::expr_binary(ast::ge, lhs, rhs) {
+ ast::expr_binary(ast::ge, lhs, rhs) => {
let tcx = fcx.ccx.tcx;
let tvar = fcx.infcx.next_ty_var();
bot |= check_expr_with(fcx, lhs, tvar);
bot |= check_expr_with(fcx, rhs, tvar);
fcx.write_ty(id, ty::mk_bool(tcx));
}
- ast::expr_binary(op, lhs, rhs) {
+ ast::expr_binary(op, lhs, rhs) => {
bot |= check_binop(fcx, expr, op, lhs, rhs);
}
- ast::expr_assign_op(op, lhs, rhs) {
+ ast::expr_assign_op(op, lhs, rhs) => {
bot |= check_binop(fcx, expr, op, lhs, rhs);
let lhs_t = fcx.expr_ty(lhs);
let result_t = fcx.expr_ty(expr);
// and so forth. - Niko
fcx.write_nil(expr.id);
}
- ast::expr_unary(unop, oprnd) {
+ ast::expr_unary(unop, oprnd) => {
let exp_inner = do unpack_expected(fcx, expected) |sty| {
alt unop {
- ast::box(_) | ast::uniq(_) {
- alt sty {
- ty::ty_box(mt) | ty::ty_uniq(mt) { some(mt.ty) }
- _ { none }
- }
+ ast::box(_) | ast::uniq(_) => alt sty {
+ ty::ty_box(mt) | ty::ty_uniq(mt) => some(mt.ty),
+ _ => none
}
- ast::not | ast::neg { expected }
- ast::deref { none }
+ ast::not | ast::neg => expected,
+ ast::deref => none
}
};
bot = check_expr(fcx, oprnd, exp_inner);
let mut oprnd_t = fcx.expr_ty(oprnd);
alt unop {
- ast::box(mutbl) {
+ ast::box(mutbl) => {
oprnd_t = ty::mk_box(tcx, {ty: oprnd_t, mutbl: mutbl});
}
- ast::uniq(mutbl) {
+ ast::uniq(mutbl) => {
oprnd_t = ty::mk_uniq(tcx, {ty: oprnd_t, mutbl: mutbl});
}
- ast::deref {
+ ast::deref => {
let sty = structure_of(fcx, expr.span, oprnd_t);
// deref'ing an unsafe pointer requires that we be in an unsafe
// context
alt sty {
- ty::ty_ptr(*) {
+ ty::ty_ptr(*) => {
fcx.require_unsafe(
expr.span,
~"dereference of unsafe pointer");
}
- _ { /*ok*/ }
+ _ => { /*ok*/ }
}
alt ty::deref_sty(tcx, sty, true) {
- some(mt) { oprnd_t = mt.ty }
- none {
+ some(mt) => { oprnd_t = mt.ty }
+ none => {
alt sty {
- ty::ty_enum(*) {
+ ty::ty_enum(*) => {
tcx.sess.span_err(
expr.span,
~"can only dereference enums \
with a single variant which has a \
single argument");
}
- _ {
+ _ => {
tcx.sess.span_err(
expr.span,
fmt!{"type %s cannot be dereferenced",
}
}
}
- ast::not {
+ ast::not => {
oprnd_t = structurally_resolved_type(fcx, oprnd.span, oprnd_t);
if !(ty::type_is_integral(oprnd_t) ||
ty::get(oprnd_t).struct == ty::ty_bool) {
oprnd, oprnd_t);
}
}
- ast::neg {
+ ast::neg => {
oprnd_t = structurally_resolved_type(fcx, oprnd.span, oprnd_t);
if !(ty::type_is_integral(oprnd_t) ||
ty::type_is_fp(oprnd_t)) {
}
fcx.write_ty(id, oprnd_t);
}
- ast::expr_addr_of(mutbl, oprnd) {
+ ast::expr_addr_of(mutbl, oprnd) => {
bot = check_expr(fcx, oprnd, unpack_expected(fcx, expected, |ty|
- alt ty { ty::ty_rptr(_, mt) { some(mt.ty) } _ { none } }
+ alt ty { ty::ty_rptr(_, mt) => some(mt.ty), _ => none }
));
//let region = region_of(fcx, oprnd);
let region = fcx.infcx.next_region_var_with_scope_lb(expr.id);
let oprnd_t = ty::mk_rptr(tcx, region, tm);
fcx.write_ty(id, oprnd_t);
}
- ast::expr_path(pth) {
+ ast::expr_path(pth) => {
let defn = lookup_def(fcx, pth.span, id);
let tpt = ty_param_bounds_and_ty_for_def(fcx, expr.span, defn);
instantiate_path(fcx, pth, tpt, expr.span, expr.id);
}
- ast::expr_mac(_) { tcx.sess.bug(~"unexpanded macro"); }
- ast::expr_fail(expr_opt) {
+ ast::expr_mac(_) => tcx.sess.bug(~"unexpanded macro"),
+ ast::expr_fail(expr_opt) => {
bot = true;
alt expr_opt {
- none {/* do nothing */ }
- some(e) { check_expr_with(fcx, e,
- ty::mk_estr(tcx, ty::vstore_uniq)); }
+ none => {/* do nothing */ }
+ some(e) => {
+ check_expr_with(fcx, e,
+ ty::mk_estr(tcx, ty::vstore_uniq));
+ }
}
fcx.write_bot(id);
}
- ast::expr_break { fcx.write_bot(id); bot = true; }
- ast::expr_again { fcx.write_bot(id); bot = true; }
- ast::expr_ret(expr_opt) {
+ ast::expr_break => { fcx.write_bot(id); bot = true; }
+ ast::expr_again => { fcx.write_bot(id); bot = true; }
+ ast::expr_ret(expr_opt) => {
bot = true;
let ret_ty = alt fcx.indirect_ret_ty {
- some(t) { t } none { fcx.ret_ty }
+ some(t) => t, none => fcx.ret_ty
};
alt expr_opt {
- none {
- alt fcx.mk_eqty(ret_ty, ty::mk_nil(tcx)) {
- result::ok(_) { /* fall through */ }
- result::err(_) {
+ none => alt fcx.mk_eqty(ret_ty, ty::mk_nil(tcx)) {
+ result::ok(_) => { /* fall through */ }
+ result::err(_) => {
tcx.sess.span_err(
expr.span,
- ~"`return;` in function returning non-nil"); }
+ ~"`return;` in function returning non-nil");
}
}
- some(e) { check_expr_with(fcx, e, ret_ty); }
+ some(e) => { check_expr_with(fcx, e, ret_ty); }
}
fcx.write_bot(id);
}
- ast::expr_log(_, lv, e) {
+ ast::expr_log(_, lv, e) => {
bot = check_expr_with(fcx, lv, ty::mk_mach_uint(tcx, ast::ty_u32));
// Note: this does not always execute, so do not propagate bot:
check_expr(fcx, e, none);
fcx.write_nil(id);
}
- ast::expr_assert(e) {
+ ast::expr_assert(e) => {
bot = check_expr_with(fcx, e, ty::mk_bool(tcx));
fcx.write_nil(id);
}
- ast::expr_copy(a) | ast::expr_unary_move(a) {
+ ast::expr_copy(a) | ast::expr_unary_move(a) => {
bot = check_expr(fcx, a, expected);
fcx.write_ty(id, fcx.expr_ty(a));
}
- ast::expr_move(lhs, rhs) {
+ ast::expr_move(lhs, rhs) => {
bot = check_assignment(fcx, expr.span, lhs, rhs, id);
}
- ast::expr_assign(lhs, rhs) {
+ ast::expr_assign(lhs, rhs) => {
bot = check_assignment(fcx, expr.span, lhs, rhs, id);
}
- ast::expr_swap(lhs, rhs) {
+ ast::expr_swap(lhs, rhs) => {
bot = check_assignment(fcx, expr.span, lhs, rhs, id);
}
- ast::expr_if(cond, thn, elsopt) {
+ ast::expr_if(cond, thn, elsopt) => {
bot = check_expr_with(fcx, cond, ty::mk_bool(tcx)) |
check_then_else(fcx, thn, elsopt, id, expr.span);
}
- ast::expr_while(cond, body) {
+ ast::expr_while(cond, body) => {
bot = check_expr_with(fcx, cond, ty::mk_bool(tcx));
check_block_no_value(fcx, body);
fcx.write_ty(id, ty::mk_nil(tcx));
}
- ast::expr_loop(body) {
+ ast::expr_loop(body) => {
check_block_no_value(fcx, body);
fcx.write_ty(id, ty::mk_nil(tcx));
bot = !may_break(body);
}
- ast::expr_alt(discrim, arms, _) {
+ ast::expr_alt(discrim, arms, _) => {
bot = alt::check_alt(fcx, expr, discrim, arms);
}
- ast::expr_fn(proto, decl, body, cap_clause) {
+ ast::expr_fn(proto, decl, body, cap_clause) => {
check_expr_fn(fcx, expr, proto, decl, body, false, expected);
capture::check_capture_clause(tcx, expr.id, cap_clause);
}
- ast::expr_fn_block(decl, body, cap_clause) {
+ ast::expr_fn_block(decl, body, cap_clause) => {
// Take the prototype from the expected type, but default to block:
let proto = unpack_expected(fcx, expected, |sty|
- alt sty { ty::ty_fn({proto, _}) { some(proto) } _ { none } }
+ alt sty { ty::ty_fn({proto, _}) => some(proto), _ => none }
).get_default(ast::proto_box);
check_expr_fn(fcx, expr, proto, decl, body, false, expected);
capture::check_capture_clause(tcx, expr.id, cap_clause);
}
- ast::expr_loop_body(b) {
+ ast::expr_loop_body(b) => {
// a loop body is the special argument to a `for` loop. We know that
// there will be an expected type in this context because it can only
// appear in the context of a call, so we get the expected type of the
// 2. the cloure that was given returns unit
let expected_sty = unpack_expected(fcx, expected, |x| some(x));
let (inner_ty, proto) = alt expected_sty {
- some(ty::ty_fn(fty)) {
+ some(ty::ty_fn(fty)) => {
alt infer::mk_subty(fcx.infcx, fty.output, ty::mk_bool(tcx)) {
- result::ok(_) {}
- result::err(err) {
+ result::ok(_) => (),
+ result::err(err) => {
tcx.sess.span_fatal(
expr.span, fmt!{"a `loop` function's last argument \
should return `bool`, not `%s`",
}
(ty::mk_fn(tcx, {output: ty::mk_nil(tcx) with fty}), fty.proto)
}
- _ {
+ _ => {
tcx.sess.span_fatal(expr.span, ~"a `loop` function's last \
argument should be of function \
type");
}
};
alt check b.node {
- ast::expr_fn_block(decl, body, cap_clause) {
+ ast::expr_fn_block(decl, body, cap_clause) => {
check_expr_fn(fcx, b, proto, decl, body, true, some(inner_ty));
demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b));
capture::check_capture_clause(tcx, b.id, cap_clause);
let block_ty = structurally_resolved_type(
fcx, expr.span, fcx.node_ty(b.id));
alt check ty::get(block_ty).struct {
- ty::ty_fn(fty) {
+ ty::ty_fn(fty) => {
fcx.write_ty(expr.id, ty::mk_fn(tcx, {output: ty::mk_bool(tcx)
with fty}));
}
}
}
- ast::expr_do_body(b) {
+ ast::expr_do_body(b) => {
let expected_sty = unpack_expected(fcx, expected, |x| some(x));
let (inner_ty, proto) = alt expected_sty {
- some(ty::ty_fn(fty)) {
+ some(ty::ty_fn(fty)) => {
(ty::mk_fn(tcx, fty), fty.proto)
}
- _ {
+ _ => {
tcx.sess.span_fatal(expr.span, ~"Non-function passed to a `do` \
function as its last argument, or wrong number of arguments \
passed to a `do` function");
}
};
alt check b.node {
- ast::expr_fn_block(decl, body, cap_clause) {
+ ast::expr_fn_block(decl, body, cap_clause) => {
check_expr_fn(fcx, b, proto, decl, body, true, some(inner_ty));
demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b));
capture::check_capture_clause(tcx, b.id, cap_clause);
let block_ty = structurally_resolved_type(
fcx, expr.span, fcx.node_ty(b.id));
alt check ty::get(block_ty).struct {
- ty::ty_fn(fty) {
+ ty::ty_fn(fty) => {
fcx.write_ty(expr.id, ty::mk_fn(tcx, fty));
}
}
}
- ast::expr_block(b) {
+ ast::expr_block(b) => {
// If this is an unchecked block, turn off purity-checking
bot = check_block(fcx, b);
let typ =
alt b.node.expr {
- some(expr) { fcx.expr_ty(expr) }
- none { ty::mk_nil(tcx) }
+ some(expr) => fcx.expr_ty(expr),
+ none => ty::mk_nil(tcx)
};
fcx.write_ty(id, typ);
}
- ast::expr_call(f, args, _) {
+ ast::expr_call(f, args, _) => {
bot = check_call(fcx, expr.span, expr.id, f, args);
}
- ast::expr_cast(e, t) {
+ ast::expr_cast(e, t) => {
bot = check_expr(fcx, e, none);
let t_1 = fcx.to_ty(t);
let t_e = fcx.expr_ty(e);
alt ty::get(t_1).struct {
// This will be looked up later on
- ty::ty_trait(*) {}
+ ty::ty_trait(*) => (),
- _ {
+ _ => {
if ty::type_is_nil(t_e) {
tcx.sess.span_err(expr.span, ~"cast from nil: " +
fcx.infcx.ty_to_str(t_e) + ~" as " +
}
fcx.write_ty(id, t_1);
}
- ast::expr_vec(args, mutbl) {
+ ast::expr_vec(args, mutbl) => {
let t: ty::t = fcx.infcx.next_ty_var();
for args.each |e| { bot |= check_expr_with(fcx, e, t); }
let typ = ty::mk_evec(tcx, {ty: t, mutbl: mutbl},
ty::vstore_fixed(args.len()));
fcx.write_ty(id, typ);
}
- ast::expr_repeat(element, count_expr, mutbl) {
+ ast::expr_repeat(element, count_expr, mutbl) => {
let count = ty::eval_repeat_count(tcx, count_expr, expr.span);
fcx.write_ty(count_expr.id, ty::mk_uint(tcx));
let t: ty::t = fcx.infcx.next_ty_var();
ty::vstore_fixed(count));
fcx.write_ty(id, t);
}
- ast::expr_tup(elts) {
+ ast::expr_tup(elts) => {
let mut elt_ts = ~[];
vec::reserve(elt_ts, vec::len(elts));
let flds = unpack_expected(fcx, expected, |sty| {
- alt sty { ty::ty_tup(flds) { some(flds) } _ { none } }
+ alt sty { ty::ty_tup(flds) => some(flds), _ => none }
});
for elts.eachi |i, e| {
check_expr(fcx, e, flds.map(|fs| fs[i]));
let typ = ty::mk_tup(tcx, elt_ts);
fcx.write_ty(id, typ);
}
- ast::expr_rec(fields, base) {
+ ast::expr_rec(fields, base) => {
option::iter(base, |b| { check_expr(fcx, b, expected); });
let expected = if expected == none && base != none {
some(fcx.expr_ty(base.get()))
} else { expected };
let flds = unpack_expected(fcx, expected, |sty|
- alt sty { ty::ty_rec(flds) { some(flds) } _ { none } }
+ alt sty { ty::ty_rec(flds) => some(flds), _ => none }
);
let fields_t = vec::map(fields, |f| {
bot |= check_expr(fcx, f.node.expr, flds.chain(|flds|
respan(f.node.expr.span, {ident: f.node.ident, mt: expr_mt})
});
alt base {
- none {
+ none => {
fn get_node(f: spanned<field>) -> field { f.node }
let typ = ty::mk_rec(tcx, vec::map(fields_t, get_node));
fcx.write_ty(id, typ);
check_no_duplicate_fields(tcx, fields.map(|f|
(f.node.ident, f.span)));
}
- some(bexpr) {
+ some(bexpr) => {
let bexpr_t = fcx.expr_ty(bexpr);
let base_fields = alt structure_of(fcx, expr.span, bexpr_t) {
- ty::ty_rec(flds) { flds }
- _ {
+ ty::ty_rec(flds) => flds,
+ _ => {
tcx.sess.span_fatal(expr.span,
~"record update has non-record base");
}
}
}
}
- ast::expr_struct(path, fields) {
+ ast::expr_struct(path, fields) => {
// Resolve the path.
let class_id;
alt tcx.def_map.find(id) {
// Write in the resulting type.
fcx.write_ty(id, struct_type);
}
- ast::expr_field(base, field, tys) {
+ ast::expr_field(base, field, tys) => {
bot = check_field(fcx, expr, false, base, field, tys);
}
- ast::expr_index(base, idx) {
+ ast::expr_index(base, idx) => {
bot |= check_expr(fcx, base, none);
let raw_base_t = fcx.expr_ty(base);
let base_t = do_autoderef(fcx, expr.span, raw_base_t);
bot |= check_expr(fcx, idx, none);
let idx_t = fcx.expr_ty(idx);
alt ty::index_sty(tcx, structure_of(fcx, expr.span, base_t)) {
- some(mt) {
+ some(mt) => {
require_integral(fcx, idx.span, idx_t);
fcx.write_ty(id, mt.ty);
}
- none {
+ none => {
let resolved = structurally_resolved_type(fcx, expr.span,
raw_base_t);
alt lookup_op_method(fcx, expr, base, resolved, ~"index",
~[idx]) {
- some((ret_ty, _)) { fcx.write_ty(id, ret_ty); }
- _ {
+ some((ret_ty, _)) => fcx.write_ty(id, ret_ty),
+ _ => {
tcx.sess.span_fatal(
expr.span, ~"cannot index a value of type `" +
fcx.infcx.ty_to_str(base_t) + ~"`");
syntax::print::pprust::expr_to_str(expr),
ty_to_str(tcx, fcx.expr_ty(expr)),
alt expected {
- some(t) { ty_to_str(tcx, t) }
- _ { ~"empty" }
+ some(t) => ty_to_str(tcx, t),
+ _ => ~"empty"
}};
unifier();
let t = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(local.node.id));
fcx.write_ty(local.node.id, t);
alt local.node.init {
- some(init) {
+ some(init) => {
bot = check_decl_initializer(fcx, local.node.id, init);
}
- _ {/* fall through */ }
+ _ => {/* fall through */ }
}
let region =
let mut node_id;
let mut bot = false;
alt stmt.node {
- ast::stmt_decl(decl, id) {
+ ast::stmt_decl(decl, id) => {
node_id = id;
alt decl.node {
- ast::decl_local(ls) {
- for ls.each |l| { bot |= check_decl_local(fcx, l); }
+ ast::decl_local(ls) => for ls.each |l| {
+ bot |= check_decl_local(fcx, l);
}
- ast::decl_item(_) {/* ignore for now */ }
+ ast::decl_item(_) => {/* ignore for now */ }
}
}
- ast::stmt_expr(expr, id) {
+ ast::stmt_expr(expr, id) => {
node_id = id;
bot = check_expr_with(fcx, expr, ty::mk_nil(fcx.ccx.tcx));
}
- ast::stmt_semi(expr, id) {
+ ast::stmt_semi(expr, id) => {
node_id = id;
bot = check_expr(fcx, expr, none);
}
fn check_block(fcx0: @fn_ctxt, blk: ast::blk) -> bool {
let fcx = alt blk.node.rules {
- ast::unchecked_blk { @fn_ctxt_({purity: ast::impure_fn with **fcx0}) }
- ast::unsafe_blk { @fn_ctxt_({purity: ast::unsafe_fn with **fcx0}) }
- ast::default_blk { fcx0 }
+ ast::unchecked_blk => @fn_ctxt_({purity: ast::impure_fn with **fcx0}),
+ ast::unsafe_blk => @fn_ctxt_({purity: ast::unsafe_fn with **fcx0}),
+ ast::default_blk => fcx0
};
do fcx.with_region_lb(blk.node.id) {
let mut bot = false;
if bot && !warned &&
alt s.node {
ast::stmt_decl(@{node: ast::decl_local(_), _}, _) |
- ast::stmt_expr(_, _) | ast::stmt_semi(_, _) {
+ ast::stmt_expr(_, _) | ast::stmt_semi(_, _) => {
true
}
- _ { false }
+ _ => false
} {
fcx.ccx.tcx.sess.span_warn(s.span, ~"unreachable statement");
warned = true;
bot |= check_stmt(fcx, s);
}
alt blk.node.expr {
- none { fcx.write_nil(blk.node.id); }
- some(e) {
+ none => fcx.write_nil(blk.node.id),
+ some(e) => {
if bot && !warned {
fcx.ccx.tcx.sess.span_warn(e.span, ~"unreachable expression");
}
let mut variants = ~[];
for vs.each |v| {
alt v.node.disr_expr {
- some(e) {
+ some(e) => {
let fcx = blank_fn_ctxt(ccx, rty, e.id);
check_expr(fcx, e, none);
let cty = fcx.expr_ty(e);
// the expression in an form that eval_const_expr can handle, so
// we may still get an internal compiler error
alt const_eval::eval_const_expr(ccx.tcx, e) {
- const_eval::const_int(val) {
+ const_eval::const_int(val) => {
disr_val = val as int;
}
- _ {
+ _ => {
ccx.tcx.sess.span_err(e.span,
~"expected signed integer constant");
}
}
}
- _ {}
+ _ => ()
}
if vec::contains(disr_vals, disr_val) {
ccx.tcx.sess.span_err(v.span,
let mut outer = true, did = local_def(id);
if ty::type_structurally_contains(ccx.tcx, rty, |sty| {
alt sty {
- ty::ty_enum(id, _) if id == did {
+ ty::ty_enum(id, _) if id == did => {
if outer { outer = false; false }
else { true }
}
- _ { false }
+ _ => false
}
}) {
ccx.tcx.sess.span_err(sp, ~"illegal recursive enum type; \
fn lookup_local(fcx: @fn_ctxt, sp: span, id: ast::node_id) -> tv_vid {
alt fcx.locals.find(id) {
- some(x) { x }
- _ {
+ some(x) => x,
+ _ => {
fcx.ccx.tcx.sess.span_fatal(sp,
~"internal error looking up a local var")
}
ty_param_bounds_and_ty {
alt defn {
- ast::def_arg(nid, _) {
+ ast::def_arg(nid, _) => {
assert (fcx.locals.contains_key(nid));
let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, nid));
return no_params(typ);
}
- ast::def_local(nid, _) {
+ ast::def_local(nid, _) => {
assert (fcx.locals.contains_key(nid));
let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, nid));
return no_params(typ);
}
- ast::def_self(_) {
+ ast::def_self(_) => {
alt fcx.self_info {
- some(self_info) {
+ some(self_info) => {
return no_params(self_info.self_ty);
}
- none {
+ none => {
fcx.ccx.tcx.sess.span_bug(sp, ~"def_self with no self_info");
}
}
}
- ast::def_fn(id, ast::extern_fn) {
+ ast::def_fn(id, ast::extern_fn) => {
// extern functions are just u8 pointers
return {
bounds: @~[],
};
}
- ast::def_fn(id, ast::unsafe_fn) {
+ ast::def_fn(id, ast::unsafe_fn) => {
// Unsafe functions can only be touched in an unsafe context
fcx.require_unsafe(sp, ~"access to unsafe function");
return ty::lookup_item_type(fcx.ccx.tcx, id);
}
ast::def_fn(id, _) | ast::def_const(id) |
- ast::def_variant(_, id) | ast::def_class(id, _) {
+ ast::def_variant(_, id) | ast::def_class(id, _) => {
return ty::lookup_item_type(fcx.ccx.tcx, id);
}
- ast::def_binding(nid, _) {
+ ast::def_binding(nid, _) => {
assert (fcx.locals.contains_key(nid));
let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, nid));
return no_params(typ);
}
- ast::def_ty(_) | ast::def_prim_ty(_) {
+ ast::def_ty(_) | ast::def_prim_ty(_) => {
fcx.ccx.tcx.sess.span_fatal(sp, ~"expected value but found type");
}
- ast::def_upvar(_, inner, _) {
+ ast::def_upvar(_, inner, _) => {
return ty_param_bounds_and_ty_for_def(fcx, sp, *inner);
}
- ast::def_ty_param(did, n) {
+ ast::def_ty_param(did, n) => {
return no_params(ty::mk_param(fcx.ccx.tcx, n, did));
}
- ast::def_mod(*) | ast::def_foreign_mod(*) {
+ ast::def_mod(*) | ast::def_foreign_mod(*) => {
fcx.ccx.tcx.sess.span_fatal(sp, ~"expected value but found module");
}
- ast::def_use(*) {
+ ast::def_use(*) => {
fcx.ccx.tcx.sess.span_fatal(sp, ~"expected value but found use");
}
- ast::def_region(*) {
+ ast::def_region(*) => {
fcx.ccx.tcx.sess.span_fatal(sp, ~"expected value but found region");
}
- ast::def_typaram_binder(*) {
+ ast::def_typaram_binder(*) => {
fcx.ccx.tcx.sess.span_fatal(sp, ~"expected value but found type \
parameter");
}
// resolution is possible, then an error is reported.
fn structurally_resolved_type(fcx: @fn_ctxt, sp: span, tp: ty::t) -> ty::t {
alt infer::resolve_type(fcx.infcx, tp, force_tvar) {
- result::ok(t_s) if !ty::type_is_var(t_s) { return t_s; }
- _ {
+ result::ok(t_s) if !ty::type_is_var(t_s) => return t_s,
+ _ => {
fcx.ccx.tcx.sess.span_fatal
(sp, ~"the type of this value must be known in this context");
}
fn ast_expr_vstore_to_vstore(fcx: @fn_ctxt, e: @ast::expr, n: uint,
v: ast::vstore) -> ty::vstore {
alt v {
- ast::vstore_fixed(none) { ty::vstore_fixed(n) }
- ast::vstore_fixed(some(u)) {
+ ast::vstore_fixed(none) => ty::vstore_fixed(n),
+ ast::vstore_fixed(some(u)) => {
if n != u {
let s = fmt!{"fixed-size sequence mismatch: %u vs. %u",u, n};
fcx.ccx.tcx.sess.span_err(e.span,s);
}
ty::vstore_fixed(u)
}
- ast::vstore_uniq { ty::vstore_uniq }
- ast::vstore_box { ty::vstore_box }
- ast::vstore_slice(a_r) {
- alt fcx.block_region() {
- result::ok(b_r) {
+ ast::vstore_uniq => ty::vstore_uniq,
+ ast::vstore_box => ty::vstore_box,
+ ast::vstore_slice(a_r) => alt fcx.block_region() {
+ result::ok(b_r) => {
let rscope = in_anon_rscope(fcx, b_r);
let r = astconv::ast_region_to_region(fcx, rscope, e.span, a_r);
ty::vstore_slice(r)
- }
- result::err(msg) {
+ }
+ result::err(msg) => {
fcx.ccx.tcx.sess.span_err(e.span, msg);
ty::vstore_slice(ty::re_static)
- }
}
}
}
|_r| {},
|t| {
alt ty::get(t).struct {
- ty::ty_param({idx, _}) { tps_used[idx] = true; }
- _ { }
+ ty::ty_param({idx, _}) => { tps_used[idx] = true; }
+ _ => ()
}
true
});
let tcx = ccx.tcx;
let (n_tps, inputs, output) = alt *it.ident {
~"size_of" |
- ~"pref_align_of" | ~"min_align_of" { (1u, ~[], ty::mk_uint(ccx.tcx)) }
- ~"init" { (1u, ~[], param(ccx, 0u)) }
- ~"forget" { (1u, ~[arg(ast::by_move, param(ccx, 0u))],
- ty::mk_nil(tcx)) }
- ~"reinterpret_cast" { (2u, ~[arg(ast::by_ref, param(ccx, 0u))],
- param(ccx, 1u)) }
- ~"addr_of" { (1u, ~[arg(ast::by_ref, param(ccx, 0u))],
- ty::mk_imm_ptr(tcx, param(ccx, 0u))) }
- ~"move_val" | ~"move_val_init" {
+ ~"pref_align_of" | ~"min_align_of" => (1u, ~[], ty::mk_uint(ccx.tcx)),
+ ~"init" => (1u, ~[], param(ccx, 0u)),
+ ~"forget" => (1u, ~[arg(ast::by_move, param(ccx, 0u))],
+ ty::mk_nil(tcx)),
+ ~"reinterpret_cast" => (2u, ~[arg(ast::by_ref, param(ccx, 0u))],
+ param(ccx, 1u)),
+ ~"addr_of" => (1u, ~[arg(ast::by_ref, param(ccx, 0u))],
+ ty::mk_imm_ptr(tcx, param(ccx, 0u))),
+ ~"move_val" | ~"move_val_init" => {
(1u, ~[arg(ast::by_mutbl_ref, param(ccx, 0u)),
- arg(ast::by_move, param(ccx, 0u))],
+ arg(ast::by_move, param(ccx, 0u))],
ty::mk_nil(tcx))
}
- ~"needs_drop" { (1u, ~[], ty::mk_bool(tcx)) }
+ ~"needs_drop" => (1u, ~[], ty::mk_bool(tcx)),
~"atomic_xchng" | ~"atomic_add" | ~"atomic_sub" |
~"atomic_xchng_acq" | ~"atomic_add_acq" | ~"atomic_sub_acq" |
- ~"atomic_xchng_rel" | ~"atomic_add_rel" | ~"atomic_sub_rel" {
+ ~"atomic_xchng_rel" | ~"atomic_add_rel" | ~"atomic_sub_rel" => {
(0u, ~[arg(ast::by_mutbl_ref, ty::mk_int(tcx)),
arg(ast::by_val, ty::mk_int(tcx))],
ty::mk_int(tcx))
}
- ~"get_tydesc" {
+ ~"get_tydesc" => {
// FIXME (#2712): return *intrinsic::tydesc, not *()
(1u, ~[], ty::mk_nil_ptr(tcx))
}
- ~"visit_tydesc" {
+ ~"visit_tydesc" => {
assert ccx.tcx.intrinsic_defs.contains_key(@~"tydesc");
assert ccx.tcx.intrinsic_defs.contains_key(@~"ty_visitor");
let (_, tydesc_ty) = ccx.tcx.intrinsic_defs.get(@~"tydesc");
(0u, ~[arg(ast::by_val, td_ptr),
arg(ast::by_ref, visitor_trait)], ty::mk_nil(tcx))
}
- ~"frame_address" {
+ ~"frame_address" => {
let fty = ty::mk_fn(ccx.tcx, {
purity: ast::impure_fn,
proto: ast::proto_block,
});
(0u, ~[arg(ast::by_ref, fty)], ty::mk_nil(tcx))
}
- other {
+ other => {
tcx.sess.span_err(it.span, ~"unrecognized intrinsic function: `" +
other + ~"`");
return;
let mut arm_non_bot = false;
for arms.each |arm| {
alt arm.guard {
- some(e) { check_expr_with(fcx, e, ty::mk_bool(tcx)); }
- none { }
+ some(e) => { check_expr_with(fcx, e, ty::mk_bool(tcx)); },
+ none => ()
}
if !check_block(fcx, arm.body) { arm_non_bot = true; }
let bty = fcx.node_ty(arm.body.node.id);
// Take the enum type params out of `expected`.
alt structure_of(pcx.fcx, pat.span, expected) {
- ty::ty_enum(_, expected_substs) {
+ ty::ty_enum(_, expected_substs) => {
// check that the type of the value being matched is a subtype
// of the type of the pattern:
let pat_ty = fcx.node_ty(pat.id);
vinfo.args.map(|t| { ty::subst(tcx, expected_substs, t) })
};
let arg_len = arg_types.len(), subpats_len = alt subpats {
- none { arg_len }
- some(ps) { ps.len() }};
+ none => arg_len,
+ some(ps) => ps.len()
+ };
if arg_len > 0u {
// N-ary variant.
if arg_len != subpats_len {
else { ~"s" }});
}
}
- _ {
+ _ => {
tcx.sess.span_fatal
(pat.span,
fmt!{"mismatched types: expected enum but found `%s`",
let tcx = pcx.fcx.ccx.tcx;
alt pat.node {
- ast::pat_wild {
+ ast::pat_wild => {
fcx.write_ty(pat.id, expected);
}
- ast::pat_lit(lt) {
+ ast::pat_lit(lt) => {
check_expr_with(fcx, lt, expected);
fcx.write_ty(pat.id, fcx.expr_ty(lt));
}
- ast::pat_range(begin, end) {
+ ast::pat_range(begin, end) => {
check_expr_with(fcx, begin, expected);
check_expr_with(fcx, end, expected);
let b_ty =
}
fcx.write_ty(pat.id, b_ty);
}
- ast::pat_ident(_, name, sub) if !pat_is_variant(tcx.def_map, pat) {
+ ast::pat_ident(_, name, sub) if !pat_is_variant(tcx.def_map, pat) => {
let vid = lookup_local(fcx, pat.span, pat.id);
let mut typ = ty::mk_var(tcx, vid);
demand::suptype(fcx, pat.span, expected, typ);
}
fcx.write_ty(pat.id, typ);
alt sub {
- some(p) { check_pat(pcx, p, expected); }
- _ {}
+ some(p) => check_pat(pcx, p, expected),
+ _ => ()
}
}
- ast::pat_ident(_, path, c) {
+ ast::pat_ident(_, path, c) => {
check_pat_variant(pcx, pat, path, some(~[]), expected);
}
- ast::pat_enum(path, subpats) {
+ ast::pat_enum(path, subpats) => {
check_pat_variant(pcx, pat, path, subpats, expected);
}
- ast::pat_rec(fields, etc) {
+ ast::pat_rec(fields, etc) => {
let ex_fields = alt structure_of(fcx, pat.span, expected) {
- ty::ty_rec(fields) { fields }
- _ {
+ ty::ty_rec(fields) => fields,
+ _ => {
tcx.sess.span_fatal
(pat.span,
fmt!{"mismatched types: expected `%s` but found record",
}
for fields.each |f| {
alt vec::find(ex_fields, |a| matches(f.ident, a)) {
- some(field) {
+ some(field) => {
check_pat(pcx, f.pat, field.mt.ty);
}
- none {
+ none => {
tcx.sess.span_fatal(pat.span,
fmt!{"mismatched types: did not \
expect a record with a field `%s`",
}
fcx.write_ty(pat.id, expected);
}
- ast::pat_tup(elts) {
+ ast::pat_tup(elts) => {
let ex_elts = alt structure_of(fcx, pat.span, expected) {
- ty::ty_tup(elts) { elts }
- _ {
+ ty::ty_tup(elts) => elts,
+ _ => {
tcx.sess.span_fatal
(pat.span,
fmt!{"mismatched types: expected `%s`, found tuple",
fcx.write_ty(pat.id, expected);
}
- ast::pat_box(inner) {
+ ast::pat_box(inner) => {
alt structure_of(fcx, pat.span, expected) {
- ty::ty_box(e_inner) {
+ ty::ty_box(e_inner) => {
check_pat(pcx, inner, e_inner.ty);
fcx.write_ty(pat.id, expected);
}
- _ {
+ _ => {
tcx.sess.span_fatal(
pat.span,
~"mismatched types: expected `" +
}
}
}
- ast::pat_uniq(inner) {
+ ast::pat_uniq(inner) => {
alt structure_of(fcx, pat.span, expected) {
- ty::ty_uniq(e_inner) {
+ ty::ty_uniq(e_inner) => {
check_pat(pcx, inner, e_inner.ty);
fcx.write_ty(pat.id, expected);
}
- _ {
+ _ => {
tcx.sess.span_fatal(
pat.span,
~"mismatched types: expected `" +
// n.b.: order of actual, expected is reversed
alt infer::mk_subty(fcx.infcx, actual, expected) {
- result::ok(()) { /* ok */ }
- result::err(err) {
+ result::ok(()) => { /* ok */ }
+ result::err(err) => {
fcx.report_mismatched_types(sp, expected, actual, err);
}
}
expected: ty::t, actual: ty::t) {
alt infer::mk_eqty(fcx.infcx, actual, expected) {
- result::ok(()) { /* ok */ }
- result::err(err) {
+ result::ok(()) => { /* ok */ }
+ result::err(err) => {
fcx.report_mismatched_types(sp, expected, actual, err);
}
}
expected: ty::t, expr: @ast::expr) {
let expr_ty = fcx.expr_ty(expr);
alt fcx.mk_assignty(expr, borrow_lb, expr_ty, expected) {
- result::ok(()) { /* ok */ }
- result::err(err) {
+ result::ok(()) => { /* ok */ }
+ result::err(err) => {
fcx.report_mismatched_types(sp, expected, expr_ty, err);
}
}
alt get_base_type_def_id(self.fcx.infcx,
self.self_expr.span,
self.self_ty) {
- none {
+ none => {
optional_inherent_methods = none;
}
- some(base_type_def_id) {
+ some(base_type_def_id) => {
debug!{"(checking method) found base type"};
optional_inherent_methods =
self.fcx.ccx.coherence_info.inherent_methods.find
loop {
// First, see whether this is a bounded parameter.
alt ty::get(self.self_ty).struct {
- ty::ty_param(p) {
+ ty::ty_param(p) => {
self.add_candidates_from_param(p.idx, p.def_id);
}
- ty::ty_trait(did, substs) {
+ ty::ty_trait(did, substs) => {
self.add_candidates_from_trait(did, substs);
}
- ty::ty_class(did, substs) {
+ ty::ty_class(did, substs) => {
self.add_candidates_from_class(did, substs);
}
- _ { }
+ _ => ()
}
// if we found anything, stop now. otherwise continue to
// check whether we can autoderef and if so loop around again.
alt ty::deref(self.tcx(), self.self_ty, false) {
- none { break; }
- some(mt) {
+ none => break,
+ some(mt) => {
self.self_ty = mt.ty;
self.derefs += 1u;
}
for self.candidates.eachi |i, candidate| {
alt candidate.entry.origin {
- method_static(did) {
+ method_static(did) => {
self.report_static_candidate(i, did);
}
- method_param(p) {
+ method_param(p) => {
self.report_param_candidate(i, p.trait_id);
}
- method_trait(did, _) {
+ method_trait(did, _) => {
self.report_trait_candidate(i, did);
}
}
fn report_static_candidate(idx: uint, did: ast::def_id) {
let span = if did.crate == ast::local_crate {
alt check self.tcx().items.get(did.node) {
- ast_map::node_method(m, _, _) { m.span }
+ ast_map::node_method(m, _, _) => m.span,
}
} else {
self.expr.span
for vec::each(*bounds) |bound| {
let (iid, bound_substs) = alt bound {
ty::bound_copy | ty::bound_send | ty::bound_const |
- ty::bound_owned {
+ ty::bound_owned => {
again; /* ok */
}
- ty::bound_trait(bound_t) {
+ ty::bound_trait(bound_t) => {
alt check ty::get(bound_t).struct {
- ty::ty_trait(i, substs) { (i, substs) }
+ ty::ty_trait(i, substs) => (i, substs)
}
}
};
let trt_methods = ty::trait_methods(tcx, iid);
alt vec::position(*trt_methods, |m| m.ident == self.m_name) {
- none {
+ none => {
/* check next bound */
trait_bnd_idx += 1u;
}
- some(pos) {
+ some(pos) => {
// Replace any appearance of `self` with the type of the
// generic parameter itself. Note that this is the only case
// where this replacement is necessary: in all other cases, we
fn ty_from_did(did: ast::def_id) -> ty::t {
alt check ty::get(ty::lookup_item_type(self.tcx(), did).ty).struct {
- ty::ty_fn(fty) {
+ ty::ty_fn(fty) => {
ty::mk_fn(self.tcx(), {proto: ast::proto_box with fty})
}
}
};
debug!{"matches = %?", matches};
alt matches {
- result::err(_) { /* keep looking */ }
- result::ok(_) {
+ result::err(_) => { /* keep looking */ }
+ result::ok(_) => {
if !self.candidate_impls.contains_key(im.did) {
let fty = self.ty_from_did(m.did);
self.candidates.push(
// Add inherent methods.
alt optional_inherent_methods {
- none {
+ none => {
// Continue.
}
- some(inherent_methods) {
+ some(inherent_methods) => {
debug!{"(adding inherent and extension candidates) adding \
inherent candidates"};
for inherent_methods.each |implementation| {
// Add trait methods.
alt self.fcx.ccx.trait_map.find(self.expr.id) {
- none {
+ none => {
// Should only happen for placement new right now.
}
- some(trait_ids) {
+ some(trait_ids) => {
for (*trait_ids).each |trait_id| {
debug!{"(adding inherent and extension candidates) \
trying trait: %s",
let coherence_info = self.fcx.ccx.coherence_info;
alt coherence_info.extension_methods.find(trait_id) {
- none {
+ none => {
// Do nothing.
}
- some(extension_methods) {
+ some(extension_methods) => {
for extension_methods.each |implementation| {
debug!{"(adding inherent and extension \
candidates) adding impl %s",
// from an impl, this'll basically be a no-nop.
alt self.fcx.mk_assignty(self.self_expr, self.borrow_lb,
cand.self_ty, cand.rcvr_ty) {
- result::ok(_) {}
- result::err(_) {
+ result::ok(_) => (),
+ result::err(_) => {
self.tcx().sess.span_bug(
self.expr.span,
fmt!{"%s was assignable to %s but now is not?",
let fcx = rcx.fcx;
alt p.node {
ast::pat_ident(_, path, _)
- if !pat_util::pat_is_variant(fcx.ccx.tcx.def_map, p) {
+ if !pat_util::pat_is_variant(fcx.ccx.tcx.def_map, p) => {
debug!{"visit_pat binding=%s", *path.idents[0]};
visit_node(p.id, p.span, rcx);
}
- _ {}
+ _ => ()
}
visit::visit_pat(p, rcx, v);
debug!{"visit_expr(e=%s)", pprust::expr_to_str(e)};
alt e.node {
- ast::expr_path(*) {
+ ast::expr_path(*) => {
// Avoid checking the use of local variables, as we already
// check their definitions. The def'n always encloses the
// use. So if the def'n is enclosed by the region, then the
// uses will also be enclosed (and otherwise, an error will
// have been reported at the def'n site).
alt lookup_def(rcx.fcx, e.span, e.id) {
- ast::def_local(*) | ast::def_arg(*) | ast::def_upvar(*) { return; }
- _ { }
+ ast::def_local(*) | ast::def_arg(*) | ast::def_upvar(*) => return,
+ _ => ()
}
}
- ast::expr_cast(source, _) {
+ ast::expr_cast(source, _) => {
// Determine if we are casting `source` to an trait instance.
// If so, we have to be sure that the type of the source obeys
// the trait's region bound.
result::err(_) => { return; /* typeck will fail anyhow */ }
result::ok(target_ty) => {
alt ty::get(target_ty).struct {
- ty::ty_trait(_, substs) {
+ ty::ty_trait(_, substs) => {
let trait_region = alt substs.self_r {
some(r) => {r}
none => {ty::re_static}
constrain_regions_in_type(rcx, trait_region,
e.span, source_ty);
}
- _ { }
+ _ => ()
}
}
};
}
- _ { }
+ _ => ()
}
if !visit_node(e.id, e.span, rcx) { return; }
// is going to fail anyway, so just stop here and let typeck
// report errors later on in the writeback phase.
let ty = alt rcx.resolve_node_type(id) {
- result::err(_) { return true; }
- result::ok(ty) { ty }
+ result::err(_) => return true,
+ result::ok(ty) => ty
};
// find the region where this expr evaluation is taking place
ppaux::region_to_str(tcx, region)};
alt region {
- ty::re_bound(_) {
+ ty::re_bound(_) => {
// a bound region is one which appears inside an fn type.
// (e.g., the `&` in `fn(&T)`). Such regions need not be
// constrained by `encl_region` as they are placeholders
// for regions that are as-yet-unknown.
return;
}
- _ {}
+ _ => ()
}
alt rcx.fcx.mk_subr(encl_region, region) {
- result::err(_) {
+ result::err(_) => {
let region1 = rcx.fcx.infcx.resolve_region_if_possible(region);
tcx.sess.span_err(
span,
ppaux::region_to_str(tcx, region1)});
rcx.errors_reported += 1u;
}
- result::ok(()) {
+ result::ok(()) => {
}
}
}
// Take self_info apart; the self_ty part is the only one we want
// to update here.
let self_ty = alt self_info {
- some(s) { some(s.self_ty) }
- none { none }
+ some(s) => some(s.self_ty),
+ none => none
};
let mut all_tys = ty::tys_in_fn_ty(fn_ty);
// Glue updated self_ty back together with its original node_id.
let new_self_info = alt self_info {
- some(s) {
- alt check t_self {
- some(t) {
- some({self_ty: t, node_id: s.node_id})
- }
- // this 'none' case shouldn't happen
- }
+ some(s) => alt check t_self {
+ some(t) => some({self_ty: t, node_id: s.node_id})
+ // this 'none' case shouldn't happen
}
- none { none }
+ none => none
};
return {isr: isr,
self_info: new_self_info,
- fn_ty: alt check ty::get(t_fn).struct { ty::ty_fn(o) {o} }};
+ fn_ty: alt check ty::get(t_fn).struct { ty::ty_fn(o) => o }};
// Takes `isr`, a (possibly empty) mapping from in-scope region
r: ty::region) -> isr_alist {
alt r {
ty::re_free(_, _) | ty::re_static | ty::re_scope(_) |
- ty::re_var(_) {
+ ty::re_var(_) => {
isr
}
- ty::re_bound(br) {
+ ty::re_bound(br) => {
alt isr.find(br) {
- some(_) { isr }
- none { @cons((br, to_r(br)), isr) }
+ some(_) => isr,
+ none => @cons((br, to_r(br)), isr)
}
}
}
// As long as we are not within a fn() type, `&T` is
// mapped to the free region anon_r. But within a fn
// type, it remains bound.
- ty::re_bound(ty::br_anon) if in_fn { r }
+ ty::re_bound(ty::br_anon) if in_fn => r,
- ty::re_bound(br) {
+ ty::re_bound(br) => {
alt isr.find(br) {
// In most cases, all named, bound regions will be
// mapped to some free region.
- some(fr) { fr }
+ some(fr) => fr,
// But in the case of a fn() type, there may be
// named regions within that remain bound:
- none if in_fn { r }
- none {
+ none if in_fn => r,
+ none => {
tcx.sess.bug(
fmt!{"Bound region not found in \
in_scope_regions list: %s",
ty::re_static |
ty::re_scope(_) |
ty::re_free(_, _) |
- ty::re_var(_) { r }
+ ty::re_var(_) => r
}
}
}
fn has_trait_bounds(tps: ~[ty::param_bounds]) -> bool {
vec::any(tps, |bs| {
vec::any(*bs, |b| {
- alt b { ty::bound_trait(_) { true } _ { false } }
+ alt b { ty::bound_trait(_) => true, _ => false }
})
})
}
for substs.tps.each |ty| {
for vec::each(*bounds[i]) |bound| {
alt bound {
- ty::bound_trait(i_ty) {
+ ty::bound_trait(i_ty) => {
let i_ty = ty::subst(tcx, substs, i_ty);
vec::push(result, lookup_vtable(fcx, sp, ty, i_ty,
allow_unsafe));
}
- _ {}
+ _ => ()
}
}
i += 1u;
let t = ty::mk_trait(tcx, id, substs);
let t_f = fixup_ty(fcx, sp, t);
alt check ty::get(t_f).struct {
- ty::ty_trait(_, substs_f) { substs_f }
+ ty::ty_trait(_, substs_f) => substs_f,
}
}
let tcx = fcx.ccx.tcx;
let (trait_id, trait_substs) = alt check ty::get(trait_ty).struct {
- ty::ty_trait(did, substs) { (did, substs) }
+ ty::ty_trait(did, substs) => (did, substs)
};
let ty = fixup_ty(fcx, sp, ty);
alt ty::get(ty).struct {
- ty::ty_param({idx: n, def_id: did}) {
+ ty::ty_param({idx: n, def_id: did}) => {
let mut n_bound = 0u;
for vec::each(*tcx.ty_param_bounds.get(did.node)) |bound| {
alt bound {
ty::bound_send | ty::bound_copy | ty::bound_const |
- ty::bound_owned {
+ ty::bound_owned => {
/* ignore */
}
- ty::bound_trait(ity) {
+ ty::bound_trait(ity) => {
alt check ty::get(ity).struct {
- ty::ty_trait(idid, substs) {
+ ty::ty_trait(idid, substs) => {
if trait_id == idid {
debug!{"(checking vtable) @0 relating ty to trait ty
with did %?", idid};
}
}
- ty::ty_trait(did, substs) if trait_id == did {
+ ty::ty_trait(did, substs) if trait_id == did => {
debug!{"(checking vtable) @1 relating ty to trait ty with did %?",
did};
return vtable_trait(did, substs.tps);
}
- _ {
+ _ => {
let mut found = ~[];
let mut impls_seen = new_def_hash();
alt fcx.ccx.coherence_info.extension_methods.find(trait_id) {
- none {
+ none => {
// Nothing found. Continue.
}
- some(implementations) {
+ some(implementations) => {
for uint::range(0, implementations.len()) |i| {
let im = implementations[i];
for vec::each(ty::impl_traits(tcx, im.did)) |of_ty| {
// it must have the same id as the expected one
alt ty::get(of_ty).struct {
- ty::ty_trait(id, _) if id != trait_id { again; }
- _ { /* ok */ }
+ ty::ty_trait(id, _) if id != trait_id => again,
+ _ => { /* ok */ }
}
// check whether the type unifies with the type
impl_self_ty(fcx, im.did);
let im_bs = ty::lookup_item_type(tcx, im.did).bounds;
alt fcx.mk_subty(ty, for_ty) {
- result::err(_) { again; }
- result::ok(()) { }
+ result::err(_) => again,
+ result::ok(()) => ()
}
// check that desired trait type unifies
}
alt found.len() {
- 0u { /* fallthrough */ }
- 1u { return found[0]; }
- _ {
+ 0u => { /* fallthrough */ }
+ 1u => { return found[0]; }
+ _ => {
fcx.ccx.tcx.sess.span_err(
sp, ~"multiple applicable methods in scope");
return found[0];
fn fixup_ty(fcx: @fn_ctxt, sp: span, ty: ty::t) -> ty::t {
let tcx = fcx.ccx.tcx;
alt resolve_type(fcx.infcx, ty, resolve_all | force_all) {
- result::ok(new_type) { new_type }
- result::err(e) {
+ result::ok(new_type) => new_type,
+ result::err(e) => {
tcx.sess.span_fatal(
sp,
fmt!{"cannot determine a type \
debug!{"(connect trait tps) trait type is %?, impl did is %?",
ty::get(trait_ty).struct, impl_did};
alt check ty::get(trait_ty).struct {
- ty::ty_trait(_, substs) {
+ ty::ty_trait(_, substs) => {
vec::iter2(substs.tps, trait_tys,
|a, b| demand::suptype(fcx, sp, a, b));
}
fn resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, v: visit::vt<@fn_ctxt>) {
let cx = fcx.ccx;
alt ex.node {
- ast::expr_path(*) {
+ ast::expr_path(*) => {
alt fcx.opt_node_ty_substs(ex.id) {
- some(substs) {
+ some(substs) => {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(ex.id));
let item_ty = ty::lookup_item_type(cx.tcx, did);
if has_trait_bounds(*item_ty.bounds) {
false));
}
}
- _ {}
+ _ => ()
}
}
// Must resolve bounds on methods with bounded params
ast::expr_field(*) | ast::expr_binary(*) |
ast::expr_unary(*) | ast::expr_assign_op(*) |
- ast::expr_index(*) {
+ ast::expr_index(*) => {
alt cx.method_map.find(ex.id) {
- some({origin: method_static(did), _}) {
+ some({origin: method_static(did), _}) => {
let bounds = ty::lookup_item_type(cx.tcx, did).bounds;
if has_trait_bounds(*bounds) {
let callee_id = alt ex.node {
- ast::expr_field(_, _, _) { ex.id }
- _ { ex.callee_id }
+ ast::expr_field(_, _, _) => ex.id,
+ _ => ex.callee_id
};
let substs = fcx.node_ty_substs(callee_id);
cx.vtable_map.insert(callee_id, lookup_vtables(fcx,
false));
}
}
- _ {}
+ _ => ()
}
}
- ast::expr_cast(src, _) {
+ ast::expr_cast(src, _) => {
let target_ty = fcx.expr_ty(ex);
alt ty::get(target_ty).struct {
- ty::ty_trait(*) {
+ ty::ty_trait(*) => {
/*
Look up vtables for the type we're casting to,
passing in the source and target type
*/
cx.vtable_map.insert(ex.id, @~[vtable]);
}
- _ {}
+ _ => ()
}
}
- _ {}
+ _ => ()
}
visit::visit_expr(ex, fcx, v);
}
option<ty::t> {
if !ty::type_needs_infer(typ) { return some(typ); }
alt resolve_type(fcx.infcx, typ, resolve_all | force_all) {
- result::ok(new_type) { return some(new_type); }
- result::err(e) {
+ result::ok(new_type) => return some(new_type),
+ result::err(e) => {
if !fcx.ccx.tcx.sess.has_errors() {
fcx.ccx.tcx.sess.span_err(
sp,
let fcx = wbcx.fcx, tcx = fcx.ccx.tcx;
let n_ty = fcx.node_ty(id);
alt resolve_type_vars_in_type(fcx, sp, n_ty) {
- none {
+ none => {
wbcx.success = false;
return none;
}
- some(t) {
+ some(t) => {
debug!{"resolve_type_vars_for_node(id=%d, n_ty=%s, t=%s)",
id, ty_to_str(tcx, n_ty), ty_to_str(tcx, t)};
write_ty_to_tcx(tcx, id, t);
alt fcx.opt_node_ty_substs(id) {
- some(substs) {
+ some(substs) => {
let mut new_tps = ~[];
for substs.tps.each |subst| {
alt resolve_type_vars_in_type(fcx, sp, subst) {
- some(t) { vec::push(new_tps, t); }
- none { wbcx.success = false; return none; }
+ some(t) => vec::push(new_tps, t),
+ none => { wbcx.success = false; return none; }
}
}
write_substs_to_tcx(tcx, id, new_tps);
}
- none {}
+ none => ()
}
return some(t);
}
resolve_type_vars_for_node(wbcx, e.span, e.id);
alt e.node {
ast::expr_fn(_, decl, _, _) |
- ast::expr_fn_block(decl, _, _) {
+ ast::expr_fn_block(decl, _, _) => {
do vec::iter(decl.inputs) |input| {
let r_ty = resolve_type_vars_for_node(wbcx, e.span, input.id);
// Just in case we never constrained the mode to anything,
// constrain it to the default for the type in question.
alt (r_ty, input.mode) {
- (some(t), ast::infer(_)) {
+ (some(t), ast::infer(_)) => {
let tcx = wbcx.fcx.ccx.tcx;
let m_def = ty::default_arg_mode_for_ty(t);
ty::set_default_mode(tcx, input.mode, m_def);
}
- _ {}
+ _ => ()
}
}
}
ast::expr_binary(*) | ast::expr_unary(*) | ast::expr_assign_op(*)
- | ast::expr_index(*) {
+ | ast::expr_index(*) => {
maybe_resolve_type_vars_for_node(wbcx, e.span, e.callee_id);
}
- _ { }
+ _ => ()
}
visit::visit_expr(e, wbcx, v);
}
let var_id = lookup_local(wbcx.fcx, l.span, l.node.id);
let var_ty = ty::mk_var(wbcx.fcx.tcx(), var_id);
alt resolve_type(wbcx.fcx.infcx, var_ty, resolve_all | force_all) {
- result::ok(lty) {
+ result::ok(lty) => {
debug!{"Type for local %s (id %d) resolved to %s",
pat_to_str(l.node.pat), l.node.id,
wbcx.fcx.infcx.ty_to_str(lty)};
write_ty_to_tcx(wbcx.fcx.ccx.tcx, l.node.id, lty);
}
- result::err(e) {
+ result::err(e) => {
wbcx.fcx.ccx.tcx.sess.span_err(
l.span,
fmt!{"cannot determine a type \
alt resolve_type(inference_context,
original_type,
resolve_ivar) {
- ok(resulting_type) if !type_is_var(resulting_type) {
+ ok(resulting_type) if !type_is_var(resulting_type) => {
resolved_type = resulting_type;
}
- _ {
+ _ => {
inference_context.tcx.sess.span_fatal(span,
~"the type of this value \
must be known in order \
ty_box(base_mutability_and_type) |
ty_uniq(base_mutability_and_type) |
ty_ptr(base_mutability_and_type) |
- ty_rptr(_, base_mutability_and_type) {
+ ty_rptr(_, base_mutability_and_type) => {
debug!{"(getting base type) recurring"};
get_base_type(inference_context, span,
base_mutability_and_type.ty)
}
- ty_enum(*) | ty_trait(*) | ty_class(*) {
+ ty_enum(*) | ty_trait(*) | ty_class(*) => {
debug!{"(getting base type) found base type"};
some(resolved_type)
}
ty_estr(*) | ty_evec(*) | ty_rec(*) |
ty_fn(*) | ty_tup(*) | ty_var(*) | ty_var_integral(*) |
ty_param(*) | ty_self | ty_type | ty_opaque_box |
- ty_opaque_closure_ptr(*) | ty_unboxed_vec(*) {
+ ty_opaque_closure_ptr(*) | ty_unboxed_vec(*) => {
debug!{"(getting base type) no base type; found %?",
get(original_type).struct};
none
-> option<def_id> {
alt get_base_type(inference_context, span, original_type) {
- none {
+ none => {
return none;
}
- some(base_type) {
+ some(base_type) => {
alt get(base_type).struct {
ty_enum(def_id, _) |
ty_class(def_id, _) |
- ty_trait(def_id, _) {
+ ty_trait(def_id, _) => {
return some(def_id);
}
- _ {
+ _ => {
fail ~"get_base_type() returned a type that wasn't an \
enum, class, or trait";
}
debug!{"(checking coherence) item '%s'", *item.ident};
alt item.node {
- item_impl(_, associated_traits, _, _) {
+ item_impl(_, associated_traits, _, _) => {
self.check_implementation(item, associated_traits);
}
- item_class(_, associated_traits, _, _, _) {
+ item_class(_, associated_traits, _, _, _) => {
self.check_implementation(item, associated_traits);
}
- _ {
+ _ => {
// Nothing to do.
}
};
alt get_base_type_def_id(self.inference_context,
item.span,
self_type.ty) {
- none {
+ none => {
let session = self.crate_context.tcx.sess;
session.span_err(item.span,
~"no base type found for inherent \
implementation; implement a \
trait instead");
}
- some(_) {
+ some(_) => {
// Nothing to do.
}
}
alt get_base_type_def_id(self.inference_context,
item.span,
self_type.ty) {
- none {
+ none => {
// Nothing to do.
}
- some(base_type_def_id) {
+ some(base_type_def_id) => {
let implementation = self.create_impl_from_item(item);
self.add_inherent_method(base_type_def_id, implementation);
alt self.crate_context.coherence_info.inherent_methods
.find(base_def_id) {
- none {
+ none => {
implementation_list = @dvec();
self.crate_context.coherence_info.inherent_methods
.insert(base_def_id, implementation_list);
}
- some(existing_implementation_list) {
+ some(existing_implementation_list) => {
implementation_list = existing_implementation_list;
}
}
alt self.crate_context.coherence_info.extension_methods
.find(trait_id) {
- none {
+ none => {
implementation_list = @dvec();
self.crate_context.coherence_info.extension_methods
.insert(trait_id, implementation_list);
}
- some(existing_implementation_list) {
+ some(existing_implementation_list) => {
implementation_list = existing_implementation_list;
}
}
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.privileged_types.remove(privileged_type);
}
}
- item_impl(_, associated_traits, _, _) {
+ item_impl(_, associated_traits, _, _) => {
alt self.base_type_def_ids.find(local_def(item.id)) {
- none {
+ none => {
// Nothing to do.
}
- some(base_type_def_id) {
+ some(base_type_def_id) => {
// Check to see whether the implementation is
// in the scope of its base type.
visit_item(item, (), visitor);
}
- _ {
+ _ => {
visit_item(item, (), visitor);
}
}
let results = @dvec();
for items.each |item| {
alt item.node {
- item_class(*) | item_enum(*) | item_trait(*) {
+ item_class(*) | item_enum(*) | item_trait(*) => {
results.push(local_def(item.id));
}
item_const(*) | item_fn(*) | item_mod(*) |
item_foreign_mod(*) | item_ty(*) | item_impl(*) |
- item_mac(*) {
+ item_mac(*) => {
// Nothing to do.
}
}
// Converts an implementation in the AST to an Impl structure.
fn create_impl_from_item(item: @item) -> @Impl {
alt item.node {
- item_impl(ty_params, _, _, ast_methods) {
+ item_impl(ty_params, _, _, ast_methods) => {
let mut methods = ~[];
for ast_methods.each |ast_method| {
push(methods, @{
methods: methods
};
}
- item_class(ty_params, _, class_members, _, _) {
+ item_class(ty_params, _, class_members, _, _) => {
let mut methods = ~[];
for class_members.each |class_member| {
alt class_member.node {
- instance_var(*) {
+ instance_var(*) => {
// Nothing to do.
}
- class_method(ast_method) {
+ class_method(ast_method) => {
push(methods, @{
did: local_def(ast_method.id),
n_tps: ast_method.tps.len(),
methods: methods
};
}
- _ {
+ _ => {
self.crate_context.tcx.sess.span_bug(item.span,
~"can't convert a \
non-impl to an impl");
fn span_of_impl(implementation: @Impl) -> span {
assert implementation.did.crate == local_crate;
alt self.crate_context.tcx.items.find(implementation.did.node) {
- some(node_item(item, _)) {
+ some(node_item(item, _)) => {
return item.span;
}
- _ {
+ _ => {
self.crate_context.tcx.sess.bug(~"span_of_impl() called on \
something that wasn't an \
impl!");
// Make sure we don't visit the same implementation
// multiple times.
alt impls_seen.find(implementation.did) {
- none {
+ none => {
// Good. Continue.
impls_seen.insert(implementation.did, ());
}
- some(_) {
+ some(_) => {
// Skip this one.
again;
}
alt get_base_type_def_id(self.inference_context,
dummy_sp(),
self_type.ty) {
- none {
+ none => {
let session = self.crate_context.tcx.sess;
session.bug(fmt!{"no base type for external impl \
with no trait: %s (type %s)!",
ty_to_str(self.crate_context.tcx,
self_type.ty)});
}
- some(_) {
+ some(_) => {
// Nothing to do.
}
}
// Record all the trait methods.
for associated_traits.each |trait_type| {
alt get(trait_type).struct {
- ty_trait(trait_id, _) {
+ ty_trait(trait_id, _) => {
self.add_trait_method(trait_id, implementation);
}
- _ {
+ _ => {
self.crate_context.tcx.sess.bug(~"trait type \
returned is not a \
trait");
alt get_base_type_def_id(self.inference_context,
dummy_sp(),
self_type.ty) {
- none {
+ none => {
// Nothing to do.
}
- some(base_type_def_id) {
+ some(base_type_def_id) => {
self.add_inherent_method(base_type_def_id,
implementation);
for each_path(crate_store, crate_number) |path_entry| {
let module_def_id;
alt path_entry.def_like {
- dl_def(def_mod(def_id)) {
+ dl_def(def_mod(def_id)) => {
module_def_id = def_id;
}
- dl_def(_) | dl_impl(_) | dl_field {
+ dl_def(_) | dl_impl(_) | dl_field => {
// Skip this.
again;
}
for crate.node.module.items.each |crate_item| {
if *crate_item.ident == ~"intrinsic" {
alt crate_item.node {
- ast::item_mod(m) {
+ ast::item_mod(m) => {
for m.items.each |intrinsic_item| {
let def_id = { crate: ast::local_crate,
node: intrinsic_item.id };
}
}
}
- _ { }
+ _ => { }
}
break;
}
csearch::get_type(self.tcx, id)
} else {
alt self.tcx.items.find(id.node) {
- some(ast_map::node_item(item, _)) {
+ some(ast_map::node_item(item, _)) => {
ty_of_item(self, item)
}
- some(ast_map::node_foreign_item(foreign_item, _, _)) {
+ some(ast_map::node_foreign_item(foreign_item, _, _)) => {
ty_of_foreign_item(self, foreign_item)
}
- x {
+ x => {
self.tcx.sess.bug(fmt!{"unexpected sort of item \
in get_item_ty(): %?", x});
}
let tcx = ccx.tcx;
let rp = tcx.region_paramd_items.contains_key(id);
alt check tcx.items.get(id) {
- ast_map::node_item(@{node: ast::item_trait(_, _, ms), _}, _) {
+ ast_map::node_item(@{node: ast::item_trait(_, _, ms), _}, _) => {
store_methods::<ast::trait_method>(ccx, id, ms, |m| {
alt m {
- required(ty_m) {
+ required(ty_m) => {
ty_of_ty_method(ccx, ty_m, rp)
}
- provided(m) {
+ provided(m) => {
ty_of_method(ccx, m, rp)
}
}
});
}
- ast_map::node_item(@{node: ast::item_class(_,_,its,_,_), _}, _) {
+ ast_map::node_item(@{node: ast::item_class(_,_,its,_,_), _}, _) => {
let (_,ms) = split_class_items(its);
// All methods need to be stored, since lookup_method
// relies on the same method cache for self-calls
}
for vec::each(*ty::trait_methods(tcx, did)) |trait_m| {
alt vec::find(impl_ms, |impl_m| trait_m.ident == impl_m.mty.ident) {
- some({mty: impl_m, id, span}) {
+ some({mty: impl_m, id, span}) => {
if impl_m.purity != trait_m.purity {
ccx.tcx.sess.span_err(
span, fmt!{"method `%s`'s purity does \
ccx.tcx, span, impl_m, vec::len(tps),
trait_m, tpt.substs, selfty);
}
- none {
+ none => {
// If we couldn't find an implementation for trait_m in
// the impl, then see if there was a default
// implementation in the trait itself. If not, raise a
alt tcx.items.get(did.node) {
ast_map::node_item(
- @{node: ast::item_trait(_, _, trait_methods), _}, _) {
+ @{node: ast::item_trait(_, _, trait_methods), _}, _) => {
let (_, provided_methods) =
split_trait_methods(trait_methods);
alt vec::find(provided_methods, |provided_method|
provided_method.ident == trait_m.ident) {
- some(m) {
+ some(m) => {
// If there's a provided method with the name we
// want, then we're fine; nothing else to do.
}
- none {
+ none => {
tcx.sess.span_err(
a_trait_ty.path.span,
fmt!{"missing method `%s`", *trait_m.ident});
}
}
}
- _ {
+ _ => {
tcx.sess.bug(~"check_methods_against_trait(): trait_ref \
didn't refer to a trait");
}
debug!{"convert: item %s with id %d rp %b", *it.ident, it.id, rp};
alt it.node {
// These don't define types.
- ast::item_foreign_mod(_) | ast::item_mod(_) {}
- ast::item_enum(variants, ty_params) {
+ ast::item_foreign_mod(_) | ast::item_mod(_) => {}
+ ast::item_enum(variants, ty_params) => {
let tpt = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, tpt.ty);
get_enum_variant_types(ccx, tpt.ty, variants, ty_params, rp);
}
- ast::item_impl(tps, trait_ref, selfty, ms) {
+ ast::item_impl(tps, trait_ref, selfty, ms) => {
let i_bounds = ty_param_bounds(ccx, tps);
let selfty = ccx.to_ty(type_rscope(rp), selfty);
write_ty_to_tcx(tcx, it.id, selfty);
check_methods_against_trait(ccx, tps, rp, selfty, t, cms);
}
}
- ast::item_trait(tps, _, trait_methods) {
+ ast::item_trait(tps, _, trait_methods) => {
let tpt = ty_of_item(ccx, it);
debug!{"item_trait(it.id=%d, tpt.ty=%s)",
it.id, ty_to_str(tcx, tpt.ty)};
// check_methods_against_trait(ccx, tps, rp, selfty, t, cms);
// }
}
- ast::item_class(tps, trait_refs, members, m_ctor, m_dtor) {
+ ast::item_class(tps, trait_refs, members, m_ctor, m_dtor) => {
// Write the class type
let tpt = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, tpt.ty);
tcx.tcache.insert(local_def(trait_ref.impl_id), tpt);
}
}
- _ {
+ _ => {
// This call populates the type cache with the converted type
// of the item in passing. All we have to do here is to write
// it into the node type table.
// table.
let tpt = ty_of_foreign_item(ccx, i);
alt i.node {
- ast::foreign_item_fn(_, _) {
+ ast::foreign_item_fn(_, _) => {
write_ty_to_tcx(ccx.tcx, i.id, tpt.ty);
ccx.tcx.tcache.insert(local_def(i.id), tpt);
}
let rscope = type_rscope(rp);
alt lookup_def_tcx(ccx.tcx, t.path.span, t.ref_id) {
- ast::def_ty(t_id) {
+ ast::def_ty(t_id) => {
let tpt = astconv::ast_path_to_ty(ccx, rscope, t_id, t.path,
t.ref_id);
alt ty::get(tpt.ty).struct {
- ty::ty_trait(*) {
+ ty::ty_trait(*) => {
(t_id, tpt)
}
- _ { sess.span_fatal(sp, err); }
+ _ => sess.span_fatal(sp, err),
}
}
- _ {
- sess.span_fatal(sp, err);
- }
+ _ => sess.span_fatal(sp, err)
}
}
let def_id = local_def(it.id);
let tcx = ccx.tcx;
alt tcx.tcache.find(def_id) {
- some(tpt) { return tpt; }
- _ {}
+ some(tpt) => return tpt,
+ _ => {}
}
let rp = tcx.region_paramd_items.contains_key(it.id);
alt it.node {
- ast::item_const(t, _) {
+ ast::item_const(t, _) => {
let typ = ccx.to_ty(empty_rscope, t);
let tpt = no_params(typ);
tcx.tcache.insert(local_def(it.id), tpt);
return tpt;
}
- ast::item_fn(decl, tps, _) {
+ ast::item_fn(decl, tps, _) => {
let bounds = ty_param_bounds(ccx, tps);
let tofd = ty_of_fn_decl(ccx, empty_rscope, ast::proto_bare,
decl, none);
ccx.tcx.tcache.insert(local_def(it.id), tpt);
return tpt;
}
- ast::item_ty(t, tps) {
+ ast::item_ty(t, tps) => {
alt tcx.tcache.find(local_def(it.id)) {
- some(tpt) { return tpt; }
- none { }
+ some(tpt) => return tpt,
+ none => { }
}
let rp = tcx.region_paramd_items.contains_key(it.id);
tcx.tcache.insert(local_def(it.id), tpt);
return tpt;
}
- ast::item_enum(_, tps) {
+ ast::item_enum(_, tps) => {
// Create a new generic polytype.
let {bounds, substs} = mk_substs(ccx, tps, rp);
let t = ty::mk_enum(tcx, local_def(it.id), substs);
tcx.tcache.insert(local_def(it.id), tpt);
return tpt;
}
- ast::item_trait(tps, _, ms) {
+ ast::item_trait(tps, _, ms) => {
let {bounds, substs} = mk_substs(ccx, tps, rp);
let t = ty::mk_trait(tcx, local_def(it.id), substs);
let tpt = {bounds: bounds, rp: rp, ty: t};
tcx.tcache.insert(local_def(it.id), tpt);
return tpt;
}
- ast::item_class(tps, _, _, _, _) {
+ ast::item_class(tps, _, _, _, _) => {
let {bounds,substs} = mk_substs(ccx, tps, rp);
let t = ty::mk_class(tcx, local_def(it.id), substs);
let tpt = {bounds: bounds, rp: rp, ty: t};
return tpt;
}
ast::item_impl(*) | ast::item_mod(_) |
- ast::item_foreign_mod(_) { fail; }
- ast::item_mac(*) { fail ~"item macros unimplemented" }
+ ast::item_foreign_mod(_) => fail,
+ ast::item_mac(*) => fail ~"item macros unimplemented"
}
}
fn ty_of_foreign_item(ccx: @crate_ctxt, it: @ast::foreign_item)
-> ty::ty_param_bounds_and_ty {
alt it.node {
- ast::foreign_item_fn(fn_decl, params) {
+ ast::foreign_item_fn(fn_decl, params) => {
return ty_of_foreign_fn_decl(ccx, fn_decl, params,
local_def(it.id));
}
param: ast::ty_param) -> ty::param_bounds {
@do vec::flat_map(*param.bounds) |b| {
alt b {
- ast::bound_send { ~[ty::bound_send] }
- ast::bound_copy { ~[ty::bound_copy] }
- ast::bound_const { ~[ty::bound_const] }
- ast::bound_owned { ~[ty::bound_owned] }
- ast::bound_trait(t) {
+ ast::bound_send => ~[ty::bound_send],
+ ast::bound_copy => ~[ty::bound_copy],
+ ast::bound_const => ~[ty::bound_const],
+ ast::bound_owned => ~[ty::bound_owned],
+ ast::bound_trait(t) => {
let ity = ast_ty_to_ty(ccx, empty_rscope, t);
alt ty::get(ity).struct {
- ty::ty_trait(*) {
+ ty::ty_trait(*) => {
~[ty::bound_trait(ity)]
}
- _ {
+ _ => {
ccx.tcx.sess.span_err(
t.span, ~"type parameter bounds must be \
trait types");
@do params.map |param| {
alt ccx.tcx.ty_param_bounds.find(param.id) {
- some(bs) { bs }
- none {
+ some(bs) => bs,
+ none => {
let bounds = compute_bounds(ccx, param);
ccx.tcx.ty_param_bounds.insert(param.id, bounds);
bounds
-> int_ty_set {
alt get(t).struct {
- ty_int(int_ty) {
- alt int_ty {
- ast::ty_i8 { int_ty_set(INT_TY_SET_i8) }
- ast::ty_i16 { int_ty_set(INT_TY_SET_i16) }
- ast::ty_i32 { int_ty_set(INT_TY_SET_i32) }
- ast::ty_i64 { int_ty_set(INT_TY_SET_i64) }
- ast::ty_i { int_ty_set(INT_TY_SET_i) }
- ast::ty_char { tcx.sess.bug(
- ~"char type passed to convert_integral_ty_to_int_ty_set()"); }
- }
+ ty_int(int_ty) => alt int_ty {
+ ast::ty_i8 => int_ty_set(INT_TY_SET_i8),
+ ast::ty_i16 => int_ty_set(INT_TY_SET_i16),
+ ast::ty_i32 => int_ty_set(INT_TY_SET_i32),
+ ast::ty_i64 => int_ty_set(INT_TY_SET_i64),
+ ast::ty_i => int_ty_set(INT_TY_SET_i),
+ ast::ty_char => tcx.sess.bug(
+ ~"char type passed to convert_integral_ty_to_int_ty_set()")
}
- ty_uint(uint_ty) {
- alt uint_ty {
- ast::ty_u8 { int_ty_set(INT_TY_SET_u8) }
- ast::ty_u16 { int_ty_set(INT_TY_SET_u16) }
- ast::ty_u32 { int_ty_set(INT_TY_SET_u32) }
- ast::ty_u64 { int_ty_set(INT_TY_SET_u64) }
- ast::ty_u { int_ty_set(INT_TY_SET_u) }
- }
+ ty_uint(uint_ty) => alt uint_ty {
+ ast::ty_u8 => int_ty_set(INT_TY_SET_u8),
+ ast::ty_u16 => int_ty_set(INT_TY_SET_u16),
+ ast::ty_u32 => int_ty_set(INT_TY_SET_u32),
+ ast::ty_u64 => int_ty_set(INT_TY_SET_u64),
+ ast::ty_u => int_ty_set(INT_TY_SET_u)
}
- _ { tcx.sess.bug(~"non-integral type passed to \
- convert_integral_ty_to_int_ty_set()"); }
+ _ => tcx.sess.bug(~"non-integral type passed to \
+ convert_integral_ty_to_int_ty_set()")
}
}
fn fixup_err_to_str(f: fixup_err) -> ~str {
alt f {
- unresolved_int_ty(_) { ~"unconstrained integral type" }
- unresolved_ty(_) { ~"unconstrained type" }
- cyclic_ty(_) { ~"cyclic type of infinite size" }
- unresolved_region(_) { ~"unconstrained region" }
- region_var_bound_by_region_var(r1, r2) {
+ unresolved_int_ty(_) => ~"unconstrained integral type",
+ unresolved_ty(_) => ~"unconstrained type",
+ cyclic_ty(_) => ~"cyclic type of infinite size",
+ unresolved_region(_) => ~"unconstrained region",
+ region_var_bound_by_region_var(r1, r2) => {
fmt!{"region var %? bound by another region var %?; this is \
a bug in rustc", r1, r2}
}
impl methods<T:copy> of cres_helpers<T> for cres<T> {
fn to_ures() -> ures {
alt self {
- ok(_v) { ok(()) }
- err(e) { err(e) }
+ ok(_v) => ok(()),
+ err(e) => err(e)
}
}
impl<V:copy to_str> of to_str for bound<V> {
fn to_str(cx: infer_ctxt) -> ~str {
alt self {
- some(v) { v.to_str(cx) }
- none { ~"none" }
+ some(v) => v.to_str(cx),
+ none => ~"none"
}
}
}
impl of to_str for int_ty_set {
fn to_str(_cx: infer_ctxt) -> ~str {
alt self {
- int_ty_set(v) { uint::to_str(v, 10u) }
+ int_ty_set(v) => uint::to_str(v, 10u)
}
}
}
impl<V:copy vid, T:copy to_str> of to_str for var_value<V,T> {
fn to_str(cx: infer_ctxt) -> ~str {
alt self {
- redirect(vid) { fmt!{"redirect(%s)", vid.to_str()} }
- root(pt, rk) { fmt!{"root(%s, %s)", pt.to_str(cx),
- uint::to_str(rk, 10u)} }
+ redirect(vid) => fmt!{"redirect(%s)", vid.to_str()},
+ root(pt, rk) => fmt!{"root(%s, %s)", pt.to_str(cx),
+ uint::to_str(rk, 10u)}
}
}
}
debug!{"try(tvbl=%u, rbl=%u)", tvbl, rbl};
let r <- f();
alt r {
- result::ok(_) { debug!{"try--ok"}; }
- result::err(_) {
+ result::ok(_) => debug!{"try--ok"},
+ result::err(_) => {
debug!{"try--rollback"};
rollback_to(self.tvb, tvbl);
rollback_to(self.rb, rbl);
fn resolve_type_vars_if_possible(typ: ty::t) -> ty::t {
alt resolve_type(self, typ, resolve_all) {
- result::ok(new_type) { return new_type; }
- result::err(_) { return typ; }
+ result::ok(new_type) => return new_type,
+ result::err(_) => return typ
}
}
fn resolve_region_if_possible(oldr: ty::region) -> ty::region {
alt resolve_region(self, oldr, resolve_all) {
- result::ok(newr) { return newr; }
- result::err(_) { return oldr; }
+ result::ok(newr) => return newr,
+ result::err(_) => return oldr
}
}
}
let vid_u = vid.to_uint();
alt vb.vals.find(vid_u) {
- none {
+ none => {
self.tcx.sess.bug(fmt!{"failed lookup of vid `%u`", vid_u});
}
- some(var_val) {
+ some(var_val) => {
alt var_val {
- redirect(vid) {
+ redirect(vid) => {
let nde = self.get(vb, vid);
if nde.root != vid {
// Path compression
}
nde
}
- root(pt, rk) {
+ root(pt, rk) => {
node({root: vid, possible_types: pt, rank: rk})
}
}
let _r = indenter();
alt (a, b) {
- (none, none) {
- ok(none)
- }
- (some(_), none) {
- ok(a)
- }
- (none, some(_)) {
- ok(b)
- }
- (some(v_a), some(v_b)) {
+ (none, none) => ok(none),
+ (some(_), none) => ok(a),
+ (none, some(_)) => ok(b),
+ (some(v_a), some(v_b)) => {
do merge_op(v_a, v_b).chain |v| {
ok(some(v))
}
// If both A's UB and B's LB have already been bound to types,
// see if we can make those types subtypes.
alt (a_bounds.ub, b_bounds.lb) {
- (some(a_ub), some(b_lb)) {
+ (some(a_ub), some(b_lb)) => {
let r = self.try(|| a_ub.sub(self, b_lb));
alt r {
- ok(()) { return result::ok(()); }
- err(_) { /*fallthrough */ }
+ ok(()) => return result::ok(()),
+ err(_) => { /*fallthrough */ }
}
}
- _ { /*fallthrough*/ }
+ _ => { /*fallthrough*/ }
}
// Otherwise, we need to merge A and B so as to guarantee that
alt (a, b) {
(none, none) |
(some(_), none) |
- (none, some(_)) {
+ (none, some(_)) => {
uok()
}
- (some(t_a), some(t_b)) {
+ (some(t_a), some(t_b)) => {
t_a.sub(self, t_b)
}
}
let rty = indent(|| self.resolve_type(typ) );
assert vec::is_empty(self.v_seen);
alt self.err {
- none {
+ none => {
debug!{"Resolved to %s (modes=%x)",
ty_to_str(self.infcx.tcx, rty),
self.modes};
return ok(rty);
}
- some(e) { return err(e); }
+ some(e) => return err(e)
}
}
self.err = none;
let resolved = indent(|| self.resolve_region(orig) );
alt self.err {
- none {ok(resolved)}
- some(e) {err(e)}
+ none => ok(resolved),
+ some(e) => err(e)
}
}
if !ty::type_needs_infer(typ) { return typ; }
alt ty::get(typ).struct {
- ty::ty_var(vid) {
+ ty::ty_var(vid) => {
self.resolve_ty_var(vid)
}
- ty::ty_var_integral(vid) {
+ ty::ty_var_integral(vid) => {
self.resolve_ty_var_integral(vid)
}
- _ {
+ _ => {
if !self.should(resolve_rvar) &&
!self.should(resolve_nested_tvar) {
// shortcircuit for efficiency
fn resolve_region(orig: ty::region) -> ty::region {
debug!{"Resolve_region(%s)", orig.to_str(self.infcx)};
alt orig {
- ty::re_var(rid) { self.resolve_region_var(rid) }
- _ { orig }
+ ty::re_var(rid) => self.resolve_region_var(rid),
+ _ => orig
}
}
let bounds = nde.possible_types;
let t1 = alt bounds {
- { ub:_, lb:some(t) } if !type_is_bot(t) { self.resolve_type(t) }
- { ub:some(t), lb:_ } { self.resolve_type(t) }
- { ub:_, lb:some(t) } { self.resolve_type(t) }
- { ub:none, lb:none } {
+ { ub:_, lb:some(t) } if !type_is_bot(t) => self.resolve_type(t),
+ { ub:some(t), lb:_ } => self.resolve_type(t),
+ { ub:_, lb:some(t) } => self.resolve_type(t),
+ { ub:none, lb:none } => {
if self.should(force_tvar) {
self.err = some(unresolved_ty(vid));
}
// If there's only one type in the set of possible types, then
// that's the answer.
alt single_type_contained_in(self.infcx.tcx, pt) {
- some(t) { t }
- none {
+ some(t) => t,
+ none => {
if self.should(force_ivar) {
// As a last resort, default to int.
let ty = ty::mk_int(self.infcx.tcx);
fn select(fst: option<ty::t>, snd: option<ty::t>) -> option<ty::t> {
alt fst {
- some(t) { some(t) }
- none {
- alt snd {
- some(t) { some(t) }
- none { none }
- }
+ some(t) => some(t),
+ none => alt snd {
+ some(t) => some(t),
+ none => none
}
}
}
let _r = indenter();
alt (ty::get(a).struct, ty::get(b).struct) {
- (ty::ty_bot, _) {
+ (ty::ty_bot, _) => {
uok()
}
- (ty::ty_var(a_id), ty::ty_var(b_id)) {
+ (ty::ty_var(a_id), ty::ty_var(b_id)) => {
let nde_a = self.get(self.tvb, a_id);
let nde_b = self.get(self.tvb, b_id);
let a_bounds = nde_a.possible_types;
self.assign_tys_or_sub(anmnt, a, b, a_bnd, b_bnd)
}
- (ty::ty_var(a_id), _) {
+ (ty::ty_var(a_id), _) => {
let nde_a = self.get(self.tvb, a_id);
let a_bounds = nde_a.possible_types;
self.assign_tys_or_sub(anmnt, a, b, a_bnd, some(b))
}
- (_, ty::ty_var(b_id)) {
+ (_, ty::ty_var(b_id)) => {
let nde_b = self.get(self.tvb, b_id);
let b_bounds = nde_b.possible_types;
self.assign_tys_or_sub(anmnt, a, b, some(a), b_bnd)
}
- (_, _) {
+ (_, _) => {
self.assign_tys_or_sub(anmnt, a, b, some(a), some(b))
}
}
fn is_borrowable(v: ty::vstore) -> bool {
alt v {
- ty::vstore_fixed(_) | ty::vstore_uniq | ty::vstore_box { true }
- ty::vstore_slice(_) { false }
+ ty::vstore_fixed(_) | ty::vstore_uniq | ty::vstore_box => true,
+ ty::vstore_slice(_) => false
}
}
alt (a_bnd, b_bnd) {
- (some(a_bnd), some(b_bnd)) {
+ (some(a_bnd), some(b_bnd)) => {
alt (ty::get(a_bnd).struct, ty::get(b_bnd).struct) {
- (ty::ty_box(mt_a), ty::ty_rptr(r_b, mt_b)) {
+ (ty::ty_box(mt_a), ty::ty_rptr(r_b, mt_b)) => {
let nr_b = ty::mk_box(self.tcx, {ty: mt_b.ty,
mutbl: m_const});
self.crosspollinate(anmnt, a, nr_b, mt_b.mutbl, r_b)
}
- (ty::ty_uniq(mt_a), ty::ty_rptr(r_b, mt_b)) {
+ (ty::ty_uniq(mt_a), ty::ty_rptr(r_b, mt_b)) => {
let nr_b = ty::mk_uniq(self.tcx, {ty: mt_b.ty,
mutbl: m_const});
self.crosspollinate(anmnt, a, nr_b, mt_b.mutbl, r_b)
}
(ty::ty_estr(vs_a),
ty::ty_estr(ty::vstore_slice(r_b)))
- if is_borrowable(vs_a) {
+ if is_borrowable(vs_a) => {
let nr_b = ty::mk_estr(self.tcx, vs_a);
self.crosspollinate(anmnt, a, nr_b, m_imm, r_b)
}
(ty::ty_evec(mt_a, vs_a),
ty::ty_evec(mt_b, ty::vstore_slice(r_b)))
- if is_borrowable(vs_a) {
+ if is_borrowable(vs_a) => {
let nr_b = ty::mk_evec(self.tcx, {ty: mt_b.ty,
mutbl: m_const}, vs_a);
self.crosspollinate(anmnt, a, nr_b, mt_b.mutbl, r_b)
}
- _ {
+ _ => {
self.sub_tys(a, b)
}
}
}
- _ {
+ _ => {
self.sub_tys(a, b)
}
}
a: option<ty::region>,
b: option<ty::region>) -> cres<option<ty::region>> {
alt (a, b) {
- (none, none) {
+ (none, none) => {
ok(none)
}
- (some(a), some(b)) {
+ (some(a), some(b)) => {
do infcx.eq_regions(a, b).then {
ok(some(a))
}
}
- (_, _) {
+ (_, _) => {
// If these two substitutions are for the same type (and
// they should be), then the type should either
// consistently have a region parameter or not have a
// *invariant* (otherwise the type system would be unsound).
alt (a, b) {
- (none, none) {
+ (none, none) => {
ok(none)
}
- (some(a), some(b)) {
+ (some(a), some(b)) => {
self.infcx().eq_tys(a, b).then(|| ok(some(a)) )
}
(none, some(_)) |
- (some(_), none) {
+ (some(_), none) => {
// I think it should never happen that we unify two substs and
// one of them has a self_ty and one doesn't...? I could be
// wrong about this.
a: ty::vstore, b: ty::vstore) -> cres<ty::vstore> {
alt (a, b) {
- (ty::vstore_slice(a_r), ty::vstore_slice(b_r)) {
+ (ty::vstore_slice(a_r), ty::vstore_slice(b_r)) => {
do self.contraregions(a_r, b_r).chain |r| {
ok(ty::vstore_slice(r))
}
}
- _ if a == b {
+ _ if a == b => {
ok(a)
}
- _ {
+ _ => {
err(ty::terr_vstores_differ(vk, b, a))
}
}
(ty::ty_bot, _) |
(_, ty::ty_bot) |
(ty::ty_var(_), _) |
- (_, ty::ty_var(_)) {
+ (_, ty::ty_var(_)) => {
tcx.sess.bug(
fmt!{"%s: bot and var types should have been handled (%s,%s)",
self.tag(),
}
// Have to handle these first
- (ty::ty_var_integral(a_id), ty::ty_var_integral(b_id)) {
+ (ty::ty_var_integral(a_id), ty::ty_var_integral(b_id)) => {
self.infcx().vars_integral(self.infcx().tvib, a_id, b_id)
.then(|| ok(a) )
}
(ty::ty_var_integral(a_id), ty::ty_int(_)) |
- (ty::ty_var_integral(a_id), ty::ty_uint(_)) {
+ (ty::ty_var_integral(a_id), ty::ty_uint(_)) => {
self.infcx().vart_integral(self.infcx().tvib, a_id, b)
.then(|| ok(a) )
}
(ty::ty_int(_), ty::ty_var_integral(b_id)) |
- (ty::ty_uint(_), ty::ty_var_integral(b_id)) {
+ (ty::ty_uint(_), ty::ty_var_integral(b_id)) => {
self.infcx().tvar_integral(self.infcx().tvib, a, b_id)
.then(|| ok(a) )
}
(ty::ty_int(_), _) |
(ty::ty_uint(_), _) |
- (ty::ty_float(_), _) {
+ (ty::ty_float(_), _) => {
let as = ty::get(a).struct;
let bs = ty::get(b).struct;
if as == bs {
}
(ty::ty_nil, _) |
- (ty::ty_bool, _) {
+ (ty::ty_bool, _) => {
let cfg = tcx.sess.targ_cfg;
if ty::mach_sty(cfg, a) == ty::mach_sty(cfg, b) {
ok(a)
}
}
- (ty::ty_param(a_p), ty::ty_param(b_p)) if a_p.idx == b_p.idx {
+ (ty::ty_param(a_p), ty::ty_param(b_p)) if a_p.idx == b_p.idx => {
ok(a)
}
(ty::ty_enum(a_id, a_substs), ty::ty_enum(b_id, b_substs))
- if a_id == b_id {
+ if a_id == b_id => {
do self.substs(a_substs, b_substs).chain |tps| {
ok(ty::mk_enum(tcx, a_id, tps))
}
}
(ty::ty_trait(a_id, a_substs), ty::ty_trait(b_id, b_substs))
- if a_id == b_id {
+ if a_id == b_id => {
do self.substs(a_substs, b_substs).chain |substs| {
ok(ty::mk_trait(tcx, a_id, substs))
}
}
(ty::ty_class(a_id, a_substs), ty::ty_class(b_id, b_substs))
- if a_id == b_id {
+ if a_id == b_id => {
do self.substs(a_substs, b_substs).chain |substs| {
ok(ty::mk_class(tcx, a_id, substs))
}
}
- (ty::ty_box(a_mt), ty::ty_box(b_mt)) {
+ (ty::ty_box(a_mt), ty::ty_box(b_mt)) => {
do self.mts(a_mt, b_mt).chain |mt| {
ok(ty::mk_box(tcx, mt))
}
}
- (ty::ty_uniq(a_mt), ty::ty_uniq(b_mt)) {
+ (ty::ty_uniq(a_mt), ty::ty_uniq(b_mt)) => {
do self.mts(a_mt, b_mt).chain |mt| {
ok(ty::mk_uniq(tcx, mt))
}
}
- (ty::ty_ptr(a_mt), ty::ty_ptr(b_mt)) {
+ (ty::ty_ptr(a_mt), ty::ty_ptr(b_mt)) => {
do self.mts(a_mt, b_mt).chain |mt| {
ok(ty::mk_ptr(tcx, mt))
}
}
- (ty::ty_rptr(a_r, a_mt), ty::ty_rptr(b_r, b_mt)) {
+ (ty::ty_rptr(a_r, a_mt), ty::ty_rptr(b_r, b_mt)) => {
do self.contraregions(a_r, b_r).chain |r| {
do self.mts(a_mt, b_mt).chain |mt| {
ok(ty::mk_rptr(tcx, r, mt))
}
}
- (ty::ty_evec(a_mt, vs_a), ty::ty_evec(b_mt, vs_b)) {
+ (ty::ty_evec(a_mt, vs_a), ty::ty_evec(b_mt, vs_b)) => {
do self.mts(a_mt, b_mt).chain |mt| {
do self.vstores(ty::terr_vec, vs_a, vs_b).chain |vs| {
ok(ty::mk_evec(tcx, mt, vs))
}
}
- (ty::ty_estr(vs_a), ty::ty_estr(vs_b)) {
+ (ty::ty_estr(vs_a), ty::ty_estr(vs_b)) => {
do self.vstores(ty::terr_str, vs_a, vs_b).chain |vs| {
ok(ty::mk_estr(tcx,vs))
}
}
- (ty::ty_rec(as), ty::ty_rec(bs)) {
+ (ty::ty_rec(as), ty::ty_rec(bs)) => {
if vec::same_length(as, bs) {
map_vec2(as, bs, |a,b| {
self.flds(a, b)
}
}
- (ty::ty_tup(as), ty::ty_tup(bs)) {
+ (ty::ty_tup(as), ty::ty_tup(bs)) => {
if vec::same_length(as, bs) {
map_vec2(as, bs, |a, b| self.tys(a, b) )
.chain(|ts| ok(ty::mk_tup(tcx, ts)) )
}
}
- (ty::ty_fn(a_fty), ty::ty_fn(b_fty)) {
+ (ty::ty_fn(a_fty), ty::ty_fn(b_fty)) => {
do self.fns(a_fty, b_fty).chain |fty| {
ok(ty::mk_fn(tcx, fty))
}
}
- _ { err(ty::terr_sorts(b, a)) }
+ _ => err(ty::terr_sorts(b, a))
}
}
b.to_str(self.infcx())};
do indent {
alt (a, b) {
- (ty::re_var(a_id), ty::re_var(b_id)) {
+ (ty::re_var(a_id), ty::re_var(b_id)) => {
do self.infcx().vars(self.rb, a_id, b_id).then {
ok(a)
}
}
- (ty::re_var(a_id), _) {
+ (ty::re_var(a_id), _) => {
do self.infcx().vart(self.rb, a_id, b).then {
ok(a)
}
}
- (_, ty::re_var(b_id)) {
+ (_, ty::re_var(b_id)) => {
do self.infcx().tvar(self.rb, a, b_id).then {
ok(a)
}
}
- _ {
+ _ => {
do self.lub().regions(a, b).compare(b) {
ty::terr_regions_differ(b, a)
}
}
alt b.mutbl {
- m_mutbl {
+ m_mutbl => {
// If supertype is mut, subtype must match exactly
// (i.e., invariant if mut):
self.infcx().eq_tys(a.ty, b.ty).then(|| ok(a) )
}
- m_imm | m_const {
+ m_imm | m_const => {
// Otherwise we can be covariant:
self.tys(a.ty, b.ty).chain(|_t| ok(a) )
}
if a == b { return ok(a); }
do indent {
alt (ty::get(a).struct, ty::get(b).struct) {
- (ty::ty_bot, _) {
+ (ty::ty_bot, _) => {
ok(a)
}
- (ty::ty_var(a_id), ty::ty_var(b_id)) {
+ (ty::ty_var(a_id), ty::ty_var(b_id)) => {
self.infcx().vars(self.tvb, a_id, b_id).then(|| ok(a) )
}
- (ty::ty_var(a_id), _) {
+ (ty::ty_var(a_id), _) => {
self.infcx().vart(self.tvb, a_id, b).then(|| ok(a) )
}
- (_, ty::ty_var(b_id)) {
+ (_, ty::ty_var(b_id)) => {
self.infcx().tvar(self.tvb, a, b_id).then(|| ok(a) )
}
- (_, ty::ty_bot) {
+ (_, ty::ty_bot) => {
err(ty::terr_sorts(b, a))
}
- _ {
+ _ => {
super_tys(self, a, b)
}
}
};
alt m {
- m_imm | m_const {
+ m_imm | m_const => {
self.tys(a.ty, b.ty).chain(|t| ok({ty: t, mutbl: m}) )
}
- m_mutbl {
+ m_mutbl => {
self.infcx().try(|| {
self.infcx().eq_tys(a.ty, b.ty).then(|| {
ok({ty: a.ty, mutbl: m})
fn purities(f1: purity, f2: purity) -> cres<purity> {
alt (f1, f2) {
- (unsafe_fn, _) | (_, unsafe_fn) {ok(unsafe_fn)}
- (impure_fn, _) | (_, impure_fn) {ok(impure_fn)}
- (extern_fn, _) | (_, extern_fn) {ok(extern_fn)}
- (pure_fn, pure_fn) {ok(pure_fn)}
+ (unsafe_fn, _) | (_, unsafe_fn) => ok(unsafe_fn),
+ (impure_fn, _) | (_, impure_fn) => ok(impure_fn),
+ (extern_fn, _) | (_, extern_fn) => ok(extern_fn),
+ (pure_fn, pure_fn) => ok(pure_fn)
}
}
fn ret_styles(r1: ret_style, r2: ret_style) -> cres<ret_style> {
alt (r1, r2) {
(ast::return_val, _) |
- (_, ast::return_val) {
- ok(ast::return_val)
- }
- (ast::noreturn, ast::noreturn) {
- ok(ast::noreturn)
- }
+ (_, ast::return_val) => ok(ast::return_val),
+ (ast::noreturn, ast::noreturn) => ok(ast::noreturn)
}
}
do indent {
alt (a, b) {
- (ty::re_static, _) | (_, ty::re_static) {
+ (ty::re_static, _) | (_, ty::re_static) => {
ok(ty::re_static) // nothing lives longer than static
}
- (ty::re_var(_), _) | (_, ty::re_var(_)) {
+ (ty::re_var(_), _) | (_, ty::re_var(_)) => {
lattice_rvars(self, a, b)
}
(f @ ty::re_free(f_id, _), ty::re_scope(s_id)) |
- (ty::re_scope(s_id), f @ ty::re_free(f_id, _)) {
+ (ty::re_scope(s_id), f @ ty::re_free(f_id, _)) => {
// A "free" region can be interpreted as "some region
// at least as big as the block f_id". So, we can
// reasonably compare free regions and scopes:
// if the free region's scope `f_id` is bigger than
// the scope region `s_id`, then the LUB is the free
// region itself:
- some(r_id) if r_id == f_id { ok(f) }
+ some(r_id) if r_id == f_id => ok(f),
// otherwise, we don't know what the free region is,
// so we must conservatively say the LUB is static:
- _ { ok(ty::re_static) }
+ _ => ok(ty::re_static)
}
}
- (ty::re_scope(a_id), ty::re_scope(b_id)) {
+ (ty::re_scope(a_id), ty::re_scope(b_id)) => {
// The region corresponding to an outer block is a
// subtype of the region corresponding to an inner
// block.
let rm = self.infcx().tcx.region_map;
alt region::nearest_common_ancestor(rm, a_id, b_id) {
- some(r_id) { ok(ty::re_scope(r_id)) }
- _ { ok(ty::re_static) }
+ some(r_id) => ok(ty::re_scope(r_id)),
+ _ => ok(ty::re_static)
}
}
(ty::re_bound(_), ty::re_free(_, _)) |
(ty::re_bound(_), ty::re_scope(_)) |
(ty::re_free(_, _), ty::re_bound(_)) |
- (ty::re_scope(_), ty::re_bound(_)) {
+ (ty::re_scope(_), ty::re_bound(_)) => {
if a == b {
ok(a)
} else {
alt (a.mutbl, b.mutbl) {
// If one side or both is mut, then the GLB must use
// the precise type from the mut side.
- (m_mutbl, m_const) {
+ (m_mutbl, m_const) => {
sub(*self).tys(a.ty, b.ty).chain(|_t| {
ok({ty: a.ty, mutbl: m_mutbl})
})
}
- (m_const, m_mutbl) {
+ (m_const, m_mutbl) => {
sub(*self).tys(b.ty, a.ty).chain(|_t| {
ok({ty: b.ty, mutbl: m_mutbl})
})
}
- (m_mutbl, m_mutbl) {
+ (m_mutbl, m_mutbl) => {
self.infcx().eq_tys(a.ty, b.ty).then(|| {
ok({ty: a.ty, mutbl: m_mutbl})
})
// both sides but mutbl must be `m_imm`.
(m_imm, m_const) |
(m_const, m_imm) |
- (m_imm, m_imm) {
+ (m_imm, m_imm) => {
self.tys(a.ty, b.ty).chain(|t| {
ok({ty: t, mutbl: m_imm})
})
// If both sides are const, then we can use GLB of both
// sides and mutbl of only `m_const`.
- (m_const, m_const) {
+ (m_const, m_const) => {
self.tys(a.ty, b.ty).chain(|t| {
ok({ty: t, mutbl: m_const})
})
// There is no mutual subtype of these combinations.
(m_mutbl, m_imm) |
- (m_imm, m_mutbl) {
+ (m_imm, m_mutbl) => {
err(ty::terr_mutability)
}
}
fn purities(f1: purity, f2: purity) -> cres<purity> {
alt (f1, f2) {
- (pure_fn, _) | (_, pure_fn) {ok(pure_fn)}
- (extern_fn, _) | (_, extern_fn) {ok(extern_fn)}
- (impure_fn, _) | (_, impure_fn) {ok(impure_fn)}
- (unsafe_fn, unsafe_fn) {ok(unsafe_fn)}
+ (pure_fn, _) | (_, pure_fn) => ok(pure_fn),
+ (extern_fn, _) | (_, extern_fn) => ok(extern_fn),
+ (impure_fn, _) | (_, impure_fn) => ok(impure_fn),
+ (unsafe_fn, unsafe_fn) => ok(unsafe_fn)
}
}
fn ret_styles(r1: ret_style, r2: ret_style) -> cres<ret_style> {
alt (r1, r2) {
- (ast::return_val, ast::return_val) {
+ (ast::return_val, ast::return_val) => {
ok(ast::return_val)
}
(ast::noreturn, _) |
- (_, ast::noreturn) {
+ (_, ast::noreturn) => {
ok(ast::noreturn)
}
}
do indent {
alt (a, b) {
- (ty::re_static, r) | (r, ty::re_static) {
+ (ty::re_static, r) | (r, ty::re_static) => {
// static lives longer than everything else
ok(r)
}
- (ty::re_var(_), _) | (_, ty::re_var(_)) {
+ (ty::re_var(_), _) | (_, ty::re_var(_)) => {
lattice_rvars(self, a, b)
}
(ty::re_free(f_id, _), s @ ty::re_scope(s_id)) |
- (s @ ty::re_scope(s_id), ty::re_free(f_id, _)) {
+ (s @ ty::re_scope(s_id), ty::re_free(f_id, _)) => {
// Free region is something "at least as big as
// `f_id`." If we find that the scope `f_id` is bigger
// than the scope `s_id`, then we can say that the GLB
// big the free region is precisely, the GLB is undefined.
let rm = self.infcx().tcx.region_map;
alt region::nearest_common_ancestor(rm, f_id, s_id) {
- some(r_id) if r_id == f_id { ok(s) }
- _ { err(ty::terr_regions_differ(b, a)) }
+ some(r_id) if r_id == f_id => ok(s),
+ _ => err(ty::terr_regions_differ(b, a))
}
}
(ty::re_scope(a_id), ty::re_scope(b_id)) |
- (ty::re_free(a_id, _), ty::re_free(b_id, _)) {
+ (ty::re_free(a_id, _), ty::re_free(b_id, _)) => {
// We want to generate a region that is contained by both of
// these: so, if one of these scopes is a subscope of the
// other, return it. Otherwise fail.
let rm = self.infcx().tcx.region_map;
alt region::nearest_common_ancestor(rm, a_id, b_id) {
- some(r_id) if a_id == r_id { ok(b) }
- some(r_id) if b_id == r_id { ok(a) }
- _ { err(ty::terr_regions_differ(b, a)) }
+ some(r_id) if a_id == r_id => ok(b),
+ some(r_id) if b_id == r_id => ok(a),
+ _ => err(ty::terr_regions_differ(b, a))
}
}
(ty::re_bound(_), ty::re_free(_, _)) |
(ty::re_bound(_), ty::re_scope(_)) |
(ty::re_free(_, _), ty::re_bound(_)) |
- (ty::re_scope(_), ty::re_bound(_)) {
+ (ty::re_scope(_), ty::re_bound(_)) => {
if a == b {
ok(a)
} else {
if a == b { return ok(a); }
do indent {
alt (ty::get(a).struct, ty::get(b).struct) {
- (ty::ty_bot, _) { self.ty_bot(b) }
- (_, ty::ty_bot) { self.ty_bot(a) }
+ (ty::ty_bot, _) => self.ty_bot(b),
+ (_, ty::ty_bot) => self.ty_bot(a),
- (ty::ty_var(a_id), ty::ty_var(b_id)) {
+ (ty::ty_var(a_id), ty::ty_var(b_id)) => {
lattice_vars(self, self.infcx().tvb,
a, a_id, b_id,
|x, y| self.tys(x, y) )
}
- (ty::ty_var(a_id), _) {
+ (ty::ty_var(a_id), _) => {
lattice_var_t(self, self.infcx().tvb, a_id, b,
|x, y| self.tys(x, y) )
}
- (_, ty::ty_var(b_id)) {
+ (_, ty::ty_var(b_id)) => {
lattice_var_t(self, self.infcx().tvb, b_id, a,
|x, y| self.tys(x, y) )
}
- _ {
+ _ => {
super_tys(self, a, b)
}
}
self: L, a: ty::region, b: ty::region) -> cres<ty::region> {
alt (a, b) {
- (ty::re_var(a_id), ty::re_var(b_id)) {
+ (ty::re_var(a_id), ty::re_var(b_id)) => {
lattice_vars(self, self.infcx().rb,
a, a_id, b_id,
|x, y| self.regions(x, y) )
}
- (ty::re_var(v_id), r) | (r, ty::re_var(v_id)) {
+ (ty::re_var(v_id), r) | (r, ty::re_var(v_id)) => {
lattice_var_t(self, self.infcx().rb,
v_id, r,
|x, y| self.regions(x, y) )
}
- _ {
+ _ => {
self.infcx().tcx.sess.bug(
fmt!{"%s: lattice_rvars invoked with a=%s and b=%s, \
neither of which are region variables",
// LUB of those types:
let a_bnd = self.bnd(a_bounds), b_bnd = self.bnd(b_bounds);
alt (a_bnd, b_bnd) {
- (some(a_ty), some(b_ty)) {
+ (some(a_ty), some(b_ty)) => {
alt self.infcx().try(|| c_ts(a_ty, b_ty) ) {
- ok(t) { return ok(t); }
- err(_) { /*fallthrough */ }
+ ok(t) => return ok(t),
+ err(_) => { /*fallthrough */ }
}
}
- _ {/*fallthrough*/}
+ _ => {/*fallthrough*/}
}
// Otherwise, we need to merge A and B into one variable. We can
b.to_str(self.infcx())};
alt self.bnd(a_bounds) {
- some(a_bnd) {
+ some(a_bnd) => {
// If a has an upper bound, return the LUB(a.ub, b)
debug!{"bnd=some(%s)", a_bnd.to_str(self.infcx())};
return c_ts(a_bnd, b);
}
- none {
+ none => {
// If a does not have an upper bound, make b the upper bound of a
// and then return b.
debug!{"bnd=none"};
alt e.node {
// Skip inner loops, since a break in the inner loop isn't a
// break inside the outer loop
- ast::expr_loop(*) | ast::expr_while(*) | ast::expr_loop_body(*) {}
- _ { visit::visit_expr(e, flag, v); }
+ ast::expr_loop(*) | ast::expr_while(*)
+ | ast::expr_loop_body(*) => {}
+ _ => visit::visit_expr(e, flag, v)
}
};
let v = visit::mk_vt(@{visit_expr: visit_expr
}
fn has_nonlocal_exits(b: ast::blk) -> bool {
- do loop_query(b) |e| { alt e {
- ast::expr_break | ast::expr_again { true }
- _ { false }}}
+ do loop_query(b) |e| {
+ alt e {
+ ast::expr_break | ast::expr_again => true,
+ _ => false
+ }
+ }
}
fn may_break(b: ast::blk) -> bool {
- do loop_query(b) |e| { alt e {
- ast::expr_break { true }
- _ { false }}}
+ do loop_query(b) |e| {
+ alt e {
+ ast::expr_break => true,
+ _ => false
+ }
+ }
}
fn local_rhs_span(l: @ast::local, def: span) -> span {
- alt l.node.init { some(i) { return i.expr.span; } _ { return def; } }
+ alt l.node.init {
+ some(i) => return i.expr.span,
+ _ => return def
+ }
}
fn is_main_name(path: syntax::ast_map::path) -> bool {
fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str {
alt cx.items.find(node_id) {
- some(ast_map::node_block(blk)) {
+ some(ast_map::node_block(blk)) => {
fmt!{"<block at %s>",
codemap::span_to_str(blk.span, cx.sess.codemap)}
}
- some(ast_map::node_expr(expr)) {
+ some(ast_map::node_expr(expr)) => {
alt expr.node {
- ast::expr_call(*) {
+ ast::expr_call(*) => {
fmt!{"<call at %s>",
codemap::span_to_str(expr.span, cx.sess.codemap)}
}
- ast::expr_alt(*) {
+ ast::expr_alt(*) => {
fmt!{"<alt at %s>",
codemap::span_to_str(expr.span, cx.sess.codemap)}
}
ast::expr_field(*) |
ast::expr_unary(*) |
ast::expr_binary(*) |
- ast::expr_index(*) {
+ ast::expr_index(*) => {
fmt!{"<method at %s>",
codemap::span_to_str(expr.span, cx.sess.codemap)}
}
- _ {
+ _ => {
fmt!{"<expression at %s>",
codemap::span_to_str(expr.span, cx.sess.codemap)}
}
}
}
- none {
+ none => {
fmt!{"<unknown-%d>", node_id}
}
- _ { cx.sess.bug(
+ _ => { cx.sess.bug(
fmt!{"re_scope refers to %s",
ast_map::node_id_to_str(cx.items, node_id)}) }
}
fn region_to_str(cx: ctxt, region: region) -> ~str {
alt region {
- re_scope(node_id) {
+ re_scope(node_id) => {
if cx.sess.ppregions() {
fmt!{"&%s", re_scope_id_to_str(cx, node_id)}
} else {
~"&"
}
}
- re_bound(br) {
+ re_bound(br) => {
bound_region_to_str(cx, br)
}
- re_free(id, br) {
+ re_free(id, br) => {
if cx.sess.ppregions() {
// For debugging, this version is sometimes helpful:
fmt!{"{%d} %s", id, bound_region_to_str(cx, br)}
}
// These two should not be seen by end-users (very often, anyhow):
- re_var(id) { fmt!{"&%s", id.to_str()} }
- re_static { ~"&static" }
+ re_var(id) => fmt!{"&%s", id.to_str()},
+ re_static => ~"&static"
}
}
fn mt_to_str(cx: ctxt, m: mt) -> ~str {
let mstr = alt m.mutbl {
- ast::m_mutbl { ~"mut " }
- ast::m_imm { ~"" }
- ast::m_const { ~"const " }
+ ast::m_mutbl => ~"mut ",
+ ast::m_imm => ~"",
+ ast::m_const => ~"const "
};
return mstr + ty_to_str(cx, m.ty);
}
fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str {
alt vs {
- ty::vstore_fixed(n) { fmt!{"%u", n} }
- ty::vstore_uniq { ~"~" }
- ty::vstore_box { ~"@" }
- ty::vstore_slice(r) { region_to_str(cx, r) }
+ ty::vstore_fixed(n) => fmt!{"%u", n},
+ ty::vstore_uniq => ~"~",
+ ty::vstore_box => ~"@",
+ ty::vstore_slice(r) => region_to_str(cx, r)
}
}
fn vstore_ty_to_str(cx: ctxt, ty: ~str, vs: ty::vstore) -> ~str {
alt vs {
- ty::vstore_fixed(_) {
+ ty::vstore_fixed(_) => {
fmt!{"%s/%s", ty, vstore_to_str(cx, vs)}
}
- _ { fmt!{"%s%s", vstore_to_str(cx, vs), ty} }
+ _ => fmt!{"%s%s", vstore_to_str(cx, vs), ty}
}
}
~str {
let {mode, ty} = input;
let modestr = alt canon_mode(cx, mode) {
- ast::infer(_) { ~"" }
- ast::expl(m) {
+ ast::infer(_) => ~"",
+ ast::expl(m) => {
if !ty::type_needs_infer(ty) &&
m == ty::default_arg_mode_for_ty(ty) {
~""
let mut s;
s = alt purity {
- ast::impure_fn {~""}
- _ {purity_to_str(purity) + ~" "}
+ ast::impure_fn => ~"",
+ _ => purity_to_str(purity) + ~" "
};
s += proto_to_str(proto);
- alt ident { some(i) { s += ~" "; s += *i; } _ { } }
+ alt ident {
+ some(i) => { s += ~" "; s += *i; }
+ _ => { }
+ }
s += ~"(";
let mut strs = ~[];
for inputs.each |a| { vec::push(strs, fn_input_to_str(cx, a)); }
if ty::get(output).struct != ty_nil {
s += ~" -> ";
alt cf {
- ast::noreturn { s += ~"!"; }
- ast::return_val { s += ty_to_str(cx, output); }
+ ast::noreturn => { s += ~"!"; }
+ ast::return_val => { s += ty_to_str(cx, output); }
}
}
return s;
// pretty print the structural type representation:
return alt ty::get(typ).struct {
- ty_nil { ~"()" }
- ty_bot { ~"_|_" }
- ty_bool { ~"bool" }
- ty_int(ast::ty_i) { ~"int" }
- ty_int(ast::ty_char) { ~"char" }
- ty_int(t) { ast_util::int_ty_to_str(t) }
- ty_uint(ast::ty_u) { ~"uint" }
- ty_uint(t) { ast_util::uint_ty_to_str(t) }
- ty_float(ast::ty_f) { ~"float" }
- ty_float(t) { ast_util::float_ty_to_str(t) }
- ty_box(tm) { ~"@" + mt_to_str(cx, tm) }
- ty_uniq(tm) { ~"~" + mt_to_str(cx, tm) }
- ty_ptr(tm) { ~"*" + mt_to_str(cx, tm) }
- ty_rptr(r, tm) {
+ ty_nil => ~"()",
+ ty_bot => ~"_|_",
+ ty_bool => ~"bool",
+ ty_int(ast::ty_i) => ~"int",
+ ty_int(ast::ty_char) => ~"char",
+ ty_int(t) => ast_util::int_ty_to_str(t),
+ ty_uint(ast::ty_u) => ~"uint",
+ ty_uint(t) => ast_util::uint_ty_to_str(t),
+ ty_float(ast::ty_f) => ~"float",
+ ty_float(t) => ast_util::float_ty_to_str(t),
+ ty_box(tm) => ~"@" + mt_to_str(cx, tm),
+ ty_uniq(tm) => ~"~" + mt_to_str(cx, tm),
+ ty_ptr(tm) => ~"*" + mt_to_str(cx, tm),
+ ty_rptr(r, tm) => {
let rs = region_to_str(cx, r);
if rs == ~"&" {
rs + mt_to_str(cx, tm)
rs + ~"/" + mt_to_str(cx, tm)
}
}
- ty_unboxed_vec(tm) { ~"unboxed_vec<" + mt_to_str(cx, tm) + ~">" }
- ty_type { ~"type" }
- ty_rec(elems) {
+ ty_unboxed_vec(tm) => { ~"unboxed_vec<" + mt_to_str(cx, tm) + ~">" }
+ ty_type => ~"type",
+ ty_rec(elems) => {
let mut strs: ~[~str] = ~[];
for elems.each |fld| { vec::push(strs, field_to_str(cx, fld)); }
~"{" + str::connect(strs, ~",") + ~"}"
}
- ty_tup(elems) {
+ ty_tup(elems) => {
let mut strs = ~[];
for elems.each |elem| { vec::push(strs, ty_to_str(cx, elem)); }
~"(" + str::connect(strs, ~",") + ~")"
}
- ty_fn(f) {
+ ty_fn(f) => {
fn_to_str(cx, f.purity, f.proto, none, f.inputs,
f.output, f.ret_style)
}
- ty_var(v) { v.to_str() }
- ty_var_integral(v) { v.to_str() }
- ty_param({idx: id, _}) {
+ ty_var(v) => v.to_str(),
+ ty_var_integral(v) => v.to_str(),
+ ty_param({idx: id, _}) => {
~"'" + str::from_bytes(~[('a' as u8) + (id as u8)])
}
- ty_self { ~"self" }
- ty_enum(did, substs) | ty_class(did, substs) {
+ ty_self => ~"self",
+ ty_enum(did, substs) | ty_class(did, substs) => {
let path = ty::item_path(cx, did);
let base = ast_map::path_to_str(path);
parameterized(cx, base, substs.self_r, substs.tps)
}
- ty_trait(did, substs) {
+ ty_trait(did, substs) => {
let path = ty::item_path(cx, did);
let base = ast_map::path_to_str(path);
parameterized(cx, base, substs.self_r, substs.tps)
}
- ty_evec(mt, vs) {
+ ty_evec(mt, vs) => {
vstore_ty_to_str(cx, fmt!{"[%s]", mt_to_str(cx, mt)}, vs)
}
- ty_estr(vs) { vstore_ty_to_str(cx, ~"str", vs) }
- ty_opaque_box { ~"@?" }
- ty_opaque_closure_ptr(ck_block) { ~"closure&" }
- ty_opaque_closure_ptr(ck_box) { ~"closure@" }
- ty_opaque_closure_ptr(ck_uniq) { ~"closure~" }
+ ty_estr(vs) => vstore_ty_to_str(cx, ~"str", vs),
+ ty_opaque_box => ~"@?",
+ ty_opaque_closure_ptr(ck_block) => ~"closure&",
+ ty_opaque_closure_ptr(ck_box) => ~"closure@",
+ ty_opaque_closure_ptr(ck_uniq) => ~"closure~"
}
}
tps: ~[ty::t]) -> ~str {
let r_str = alt self_r {
- none { ~"" }
- some(r) {
+ none => ~"",
+ some(r) => {
fmt!{"/%s", region_to_str(cx, r)}
}
};
let mut keep_going = true;
while keep_going {
alt comm::recv(po) {
- handle_request(f) {
+ handle_request(f) => {
f(ctxt);
}
- exit {
+ exit => {
keep_going = false;
}
}
fn parse_desc(attrs: ~[ast::attribute]) -> option<~str> {
alt doc_meta(attrs) {
- some(meta) {
+ some(meta) => {
attr::get_meta_item_value_str(meta).map(|x| *x )
}
- none { none }
+ none => none
}
}
fn parse_hidden(attrs: ~[ast::attribute]) -> bool {
alt doc_meta(attrs) {
- some(meta) {
+ some(meta) => {
alt attr::get_meta_item_list(meta) {
- some(metas) {
+ some(metas) => {
let hiddens = attr::find_meta_items_by_name(metas, ~"hidden");
vec::is_not_empty(hiddens)
}
- none { false }
+ none => false
}
}
- none { false }
+ none => false
}
}
+parse_attrs: fn~(~[ast::attribute]) -> T) -> T {
do astsrv::exec(srv) |ctxt| {
let attrs = alt ctxt.ast_map.get(id) {
- ast_map::node_item(item, _) { item.attrs }
- ast_map::node_foreign_item(item, _, _) { item.attrs }
- _ {
- fail ~"parse_item_attrs: not an item";
- }
+ ast_map::node_item(item, _) => item.attrs,
+ ast_map::node_foreign_item(item, _, _) => item.attrs,
+ _ => fail ~"parse_item_attrs: not an item"
};
parse_attrs(attrs)
}
alt check ctxt.ast_map.get(doc_id) {
ast_map::node_item(@{
node: ast::item_enum(ast_variants, _), _
- }, _) {
+ }, _) => {
let ast_variant = option::get(
vec::find(ast_variants, |v| {
*v.node.name == variant.name
alt ctxt.ast_map.get(item_id) {
ast_map::node_item(@{
node: ast::item_trait(_, _, methods), _
- }, _) {
+ }, _) => {
vec::map(methods, |method| {
alt method {
- ast::required(ty_m) {
+ ast::required(ty_m) => {
(*ty_m.ident, attr_parser::parse_desc(ty_m.attrs))
}
- ast::provided(m) {
+ ast::provided(m) => {
(*m.ident, attr_parser::parse_desc(m.attrs))
}
}
}
ast_map::node_item(@{
node: ast::item_impl(_, _, _, methods), _
- }, _) {
+ }, _) => {
vec::map(methods, |method| {
(*method.ident, attr_parser::parse_desc(method.attrs))
})
}
- _ { fail ~"unexpected item" }
+ _ => fail ~"unexpected item"
}
};
let args = vec::tail(args);
let opts = vec::unzip(opts()).first();
alt getopts::getopts(args, opts) {
- result::ok(matches) {
+ result::ok(matches) => {
if vec::len(matches.free) == 1u {
let input_crate = vec::head(matches.free);
config_from_opts(input_crate, matches, program_output)
result::err(~"multiple crates specified")
}
}
- result::err(f) {
+ result::err(f) => {
result::err(getopts::fail_str(f))
}
}
fn parse_output_format(output_format: ~str) -> result<output_format, ~str> {
alt output_format {
- ~"markdown" { result::ok(markdown) }
- ~"html" { result::ok(pandoc_html) }
- _ { result::err(fmt!{"unknown output format '%s'", output_format}) }
+ ~"markdown" => result::ok(markdown),
+ ~"html" => result::ok(pandoc_html),
+ _ => result::err(fmt!{"unknown output format '%s'", output_format})
}
}
fn parse_output_style(output_style: ~str) -> result<output_style, ~str> {
alt output_style {
- ~"doc-per-crate" { result::ok(doc_per_crate) }
- ~"doc-per-mod" { result::ok(doc_per_mod) }
- _ { result::err(fmt!{"unknown output style '%s'", output_style}) }
+ ~"doc-per-crate" => result::ok(doc_per_crate),
+ ~"doc-per-mod" => result::ok(doc_per_mod),
+ _ => result::err(fmt!{"unknown output style '%s'", output_style})
}
}
}
let possible_pandocs = alt maybe_pandoc_cmd {
- some(pandoc_cmd) { ~[pandoc_cmd] }
- none {
+ some(pandoc_cmd) => ~[pandoc_cmd],
+ none => {
~[~"pandoc"] + alt os::homedir() {
- some(dir) {
+ some(dir) => {
~[path::connect(dir, ~".cabal/bin/pandoc")]
}
- none { ~[] }
+ none => ~[]
}
}
};
const max_brief_len: uint = 120u;
alt first_sentence(desc) {
- some(first_sentence) {
+ some(first_sentence) => {
if str::len(first_sentence) <= max_brief_len {
some(first_sentence)
} else {
none
}
}
- none { none }
+ none => none
}
}
}
};
alt idx {
- some(idx) if idx > 2u {
+ some(idx) if idx > 2u => {
str::slice(s, 0u, idx - 1u)
}
- _ {
+ _ => {
if str::ends_with(s, ~".") {
str::slice(s, 0u, str::len(s))
} else {
fn cratedoc() -> cratedoc {
option::get(vec::foldl(none, self.pages, |_m, page| {
alt page {
- doc::cratepage(doc) { some(doc) }
- _ { none }
+ doc::cratepage(doc) => some(doc),
+ _ => none
}
}))
}
fn mods() -> ~[moddoc] {
do vec::filter_map(self.items) |itemtag| {
alt itemtag {
- modtag(moddoc) { some(moddoc) }
- _ { none }
+ modtag(moddoc) => some(moddoc),
+ _ => none
}
}
}
fn nmods() -> ~[nmoddoc] {
do vec::filter_map(self.items) |itemtag| {
alt itemtag {
- nmodtag(nmoddoc) { some(nmoddoc) }
- _ { none }
+ nmodtag(nmoddoc) => some(nmoddoc),
+ _ => none
}
}
}
fn fns() -> ~[fndoc] {
do vec::filter_map(self.items) |itemtag| {
alt itemtag {
- fntag(fndoc) { some(fndoc) }
- _ { none }
+ fntag(fndoc) => some(fndoc),
+ _ => none
}
}
}
fn consts() -> ~[constdoc] {
do vec::filter_map(self.items) |itemtag| {
alt itemtag {
- consttag(constdoc) { some(constdoc) }
- _ { none }
+ consttag(constdoc) => some(constdoc),
+ _ => none
}
}
}
fn enums() -> ~[enumdoc] {
do vec::filter_map(self.items) |itemtag| {
alt itemtag {
- enumtag(enumdoc) { some(enumdoc) }
- _ { none }
+ enumtag(enumdoc) => some(enumdoc),
+ _ => none
}
}
}
fn traits() -> ~[traitdoc] {
do vec::filter_map(self.items) |itemtag| {
alt itemtag {
- traittag(traitdoc) { some(traitdoc) }
- _ { none }
+ traittag(traitdoc) => some(traitdoc),
+ _ => none
}
}
}
fn impls() -> ~[impldoc] {
do vec::filter_map(self.items) |itemtag| {
alt itemtag {
- impltag(impldoc) { some(impldoc) }
- _ { none }
+ impltag(impldoc) => some(impldoc),
+ _ => none
}
}
}
fn types() -> ~[tydoc] {
do vec::filter_map(self.items) |itemtag| {
alt itemtag {
- tytag(tydoc) { some(tydoc) }
- _ { none }
+ tytag(tydoc) => some(tydoc),
+ _ => none
}
}
}
fn mods() -> ~[moddoc] {
do vec::filter_map(self) |page| {
alt page {
- itempage(modtag(moddoc)) { some(moddoc) }
- _ { none }
+ itempage(modtag(moddoc)) => some(moddoc),
+ _ => none
}
}
}
fn nmods() -> ~[nmoddoc] {
do vec::filter_map(self) |page| {
alt page {
- itempage(nmodtag(nmoddoc)) { some(nmoddoc) }
- _ { none }
+ itempage(nmodtag(nmoddoc)) => some(nmoddoc),
+ _ => none
}
}
}
fn fns() -> ~[fndoc] {
do vec::filter_map(self) |page| {
alt page {
- itempage(fntag(fndoc)) { some(fndoc) }
- _ { none }
+ itempage(fntag(fndoc)) => some(fndoc),
+ _ => none
}
}
}
fn consts() -> ~[constdoc] {
do vec::filter_map(self) |page| {
alt page {
- itempage(consttag(constdoc)) { some(constdoc) }
- _ { none }
+ itempage(consttag(constdoc)) => some(constdoc),
+ _ => none
}
}
}
fn enums() -> ~[enumdoc] {
do vec::filter_map(self) |page| {
alt page {
- itempage(enumtag(enumdoc)) { some(enumdoc) }
- _ { none }
+ itempage(enumtag(enumdoc)) => some(enumdoc),
+ _ => none
}
}
}
fn traits() -> ~[traitdoc] {
do vec::filter_map(self) |page| {
alt page {
- itempage(traittag(traitdoc)) { some(traitdoc) }
- _ { none }
+ itempage(traittag(traitdoc)) => some(traitdoc),
+ _ => none
}
}
}
fn impls() -> ~[impldoc] {
do vec::filter_map(self) |page| {
alt page {
- itempage(impltag(impldoc)) { some(impldoc) }
- _ { none }
+ itempage(impltag(impldoc)) => some(impldoc),
+ _ => none
}
}
}
fn types() -> ~[tydoc] {
do vec::filter_map(self) |page| {
alt page {
- itempage(tytag(tydoc)) { some(tydoc) }
- _ { none }
+ itempage(tytag(tydoc)) => some(tydoc),
+ _ => none
}
}
}
impl of item for itemtag {
pure fn item() -> itemdoc {
alt self {
- doc::modtag(doc) { doc.item }
- doc::nmodtag(doc) { doc.item }
- doc::fntag(doc) { doc.item }
- doc::consttag(doc) { doc.item }
- doc::enumtag(doc) { doc.item }
- doc::traittag(doc) { doc.item }
- doc::impltag(doc) { doc.item }
- doc::tytag(doc) { doc.item }
+ doc::modtag(doc) => doc.item,
+ doc::nmodtag(doc) => doc.item,
+ doc::fntag(doc) => doc.item,
+ doc::consttag(doc) => doc.item,
+ doc::enumtag(doc) => doc.item,
+ doc::traittag(doc) => doc.item,
+ doc::impltag(doc) => doc.item,
+ doc::tytag(doc) => doc.item
}
}
}
items: do vec::filter_map(module_.items) |item| {
let itemdoc = mk_itemdoc(item.id, item.ident);
alt item.node {
- ast::item_mod(m) {
+ ast::item_mod(m) => {
some(doc::modtag(
moddoc_from_mod(itemdoc, m)
))
}
- ast::item_foreign_mod(nm) {
+ ast::item_foreign_mod(nm) => {
some(doc::nmodtag(
nmoddoc_from_mod(itemdoc, nm)
))
}
- ast::item_fn(_, _, _) {
+ ast::item_fn(_, _, _) => {
some(doc::fntag(
fndoc_from_fn(itemdoc)
))
}
- ast::item_const(_, _) {
+ ast::item_const(_, _) => {
some(doc::consttag(
constdoc_from_const(itemdoc)
))
}
- ast::item_enum(variants, _) {
+ ast::item_enum(variants, _) => {
some(doc::enumtag(
enumdoc_from_enum(itemdoc, variants)
))
}
- ast::item_trait(_, _, methods) {
+ ast::item_trait(_, _, methods) => {
some(doc::traittag(
traitdoc_from_trait(itemdoc, methods)
))
}
- ast::item_impl(_, _, _, methods) {
+ ast::item_impl(_, _, _, methods) => {
some(doc::impltag(
impldoc_from_impl(itemdoc, methods)
))
}
- ast::item_ty(_, _) {
+ ast::item_ty(_, _) => {
some(doc::tytag(
tydoc_from_ty(itemdoc)
))
}
- _ {
- none
- }
+ _ => none
}
},
index: none
fns: do vec::map(module_.items) |item| {
let itemdoc = mk_itemdoc(item.id, item.ident);
alt item.node {
- ast::foreign_item_fn(_, _) {
+ ast::foreign_item_fn(_, _) => {
fndoc_from_fn(itemdoc)
}
}
item: itemdoc,
methods: do vec::map(methods) |method| {
alt method {
- ast::required(ty_m) {
+ ast::required(ty_m) => {
{
name: *ty_m.ident,
brief: none,
implementation: doc::required,
}
}
- ast::provided(m) {
+ ast::provided(m) => {
{
name: *m.ident,
brief: none,
doc::doc_({
pages: do vec::map(doc.pages) |page| {
alt page {
- doc::cratepage(doc) {
+ doc::cratepage(doc) => {
doc::cratepage(fold.fold_crate(fold, doc))
}
- doc::itempage(doc) {
+ doc::itempage(doc) => {
doc::itempage(fold_itemtag(fold, doc))
}
}
fn fold_itemtag<T>(fold: fold<T>, doc: doc::itemtag) -> doc::itemtag {
alt doc {
- doc::modtag(moddoc) {
+ doc::modtag(moddoc) => {
doc::modtag(fold.fold_mod(fold, moddoc))
}
- doc::nmodtag(nmoddoc) {
+ doc::nmodtag(nmoddoc) => {
doc::nmodtag(fold.fold_nmod(fold, nmoddoc))
}
- doc::fntag(fndoc) {
+ doc::fntag(fndoc) => {
doc::fntag(fold.fold_fn(fold, fndoc))
}
- doc::consttag(constdoc) {
+ doc::consttag(constdoc) => {
doc::consttag(fold.fold_const(fold, constdoc))
}
- doc::enumtag(enumdoc) {
+ doc::enumtag(enumdoc) => {
doc::enumtag(fold.fold_enum(fold, enumdoc))
}
- doc::traittag(traitdoc) {
+ doc::traittag(traitdoc) => {
doc::traittag(fold.fold_trait(fold, traitdoc))
}
- doc::impltag(impldoc) {
+ doc::impltag(impldoc) => {
doc::impltag(fold.fold_impl(fold, impldoc))
}
- doc::tytag(tydoc) {
+ doc::tytag(tydoc) => {
doc::tytag(fold.fold_type(fold, tydoc))
}
}
) -> doc::index_entry {
let link = alt doc {
doc::modtag(_) | doc::nmodtag(_)
- if config.output_style == config::doc_per_mod {
+ if config.output_style == config::doc_per_mod => {
markdown_writer::make_filename(config, doc::itempage(doc))
}
- _ {
+ _ => {
~"#" + pandoc_header_id(markdown_pass::header_text(doc))
}
};
pure fn mods_last(item1: &doc::itemtag, item2: &doc::itemtag) -> bool {
pure fn is_mod(item: &doc::itemtag) -> bool {
alt *item {
- doc::modtag(_) { true }
- _ { false }
+ doc::modtag(_) => true,
+ _ => false
}
}
fn write_page(ctxt: ctxt, page: doc::page) {
write_title(ctxt, page);
alt page {
- doc::cratepage(doc) {
+ doc::cratepage(doc) => {
write_crate(ctxt, doc);
}
- doc::itempage(doc) {
+ doc::itempage(doc) => {
// We don't write a header for item's pages because their
// header in the html output is created by the page title
write_item_no_header(ctxt, doc);
fn make_title(page: doc::page) -> ~str {
let item = alt page {
- doc::cratepage(cratedoc) {
+ doc::cratepage(cratedoc) => {
doc::modtag(cratedoc.topmod)
}
- doc::itempage(itemtag) {
+ doc::itempage(itemtag) => {
itemtag
}
};
for iter::repeat(2u) {
let (page, markdown) = comm::recv(po);
alt page {
- doc::cratepage(_) {
+ doc::cratepage(_) => {
assert str::contains(markdown, ~"% Crate core");
}
- doc::itempage(_) {
+ doc::itempage(_) => {
assert str::contains(markdown, ~"% Module a");
}
}
fn header_kind(doc: doc::itemtag) -> ~str {
alt doc {
- doc::modtag(_) {
+ doc::modtag(_) => {
if doc.id() == syntax::ast::crate_node_id {
~"Crate"
} else {
~"Module"
}
}
- doc::nmodtag(_) {
+ doc::nmodtag(_) => {
~"Foreign module"
}
- doc::fntag(_) {
+ doc::fntag(_) => {
~"Function"
}
- doc::consttag(_) {
+ doc::consttag(_) => {
~"Const"
}
- doc::enumtag(_) {
+ doc::enumtag(_) => {
~"Enum"
}
- doc::traittag(_) {
+ doc::traittag(_) => {
~"Interface"
}
- doc::impltag(doc) {
+ doc::impltag(doc) => {
~"Implementation"
}
- doc::tytag(_) {
+ doc::tytag(_) => {
~"Type"
}
}
fn header_name(doc: doc::itemtag) -> ~str {
let fullpath = str::connect(doc.path() + ~[doc.name()], ~"::");
alt doc {
- doc::modtag(_) if doc.id() != syntax::ast::crate_node_id {
+ doc::modtag(_) if doc.id() != syntax::ast::crate_node_id => {
fullpath
}
- doc::nmodtag(_) {
+ doc::nmodtag(_) => {
fullpath
}
- doc::impltag(doc) {
+ doc::impltag(doc) => {
assert option::is_some(doc.self_ty);
let self_ty = option::get(doc.self_ty);
let mut trait_part = ~"";
}
fmt!{"%s%s for %s", doc.name(), trait_part, self_ty}
}
- _ {
+ _ => {
doc.name()
}
}
desc: option<~str>
) {
alt desc {
- some(desc) {
+ some(desc) => {
ctxt.w.write_line(desc);
ctxt.w.write_line(~"");
}
- none { }
+ none => ()
}
}
}
alt doc {
- doc::modtag(moddoc) { write_mod(ctxt, moddoc) }
- doc::nmodtag(nmoddoc) { write_nmod(ctxt, nmoddoc) }
- doc::fntag(fndoc) { write_fn(ctxt, fndoc) }
- doc::consttag(constdoc) { write_const(ctxt, constdoc) }
- doc::enumtag(enumdoc) { write_enum(ctxt, enumdoc) }
- doc::traittag(traitdoc) { write_trait(ctxt, traitdoc) }
- doc::impltag(impldoc) { write_impl(ctxt, impldoc) }
- doc::tytag(tydoc) { write_type(ctxt, tydoc) }
+ doc::modtag(moddoc) => write_mod(ctxt, moddoc),
+ doc::nmodtag(nmoddoc) => write_nmod(ctxt, nmoddoc),
+ doc::fntag(fndoc) => write_fn(ctxt, fndoc),
+ doc::consttag(constdoc) => write_const(ctxt, constdoc),
+ doc::enumtag(enumdoc) => write_enum(ctxt, enumdoc),
+ doc::traittag(traitdoc) => write_trait(ctxt, traitdoc),
+ doc::impltag(impldoc) => write_impl(ctxt, impldoc),
+ doc::tytag(tydoc) => write_type(ctxt, tydoc)
}
}
fn item_header_lvl(doc: doc::itemtag) -> hlvl {
alt doc {
- doc::modtag(_) | doc::nmodtag(_) { h1 }
- _ { h2 }
+ doc::modtag(_) | doc::nmodtag(_) => h1,
+ _ => h2
}
}
fn write_sig(ctxt: ctxt, sig: option<~str>) {
alt sig {
- some(sig) {
+ some(sig) => {
ctxt.w.write_line(code_block_indent(sig));
ctxt.w.write_line(~"");
}
- none { fail ~"unimplemented" }
+ none => fail ~"unimplemented"
}
}
assert option::is_some(doc.sig);
let sig = option::get(doc.sig);
alt doc.desc {
- some(desc) {
+ some(desc) => {
ctxt.w.write_line(fmt!{"* `%s` - %s", sig, desc});
}
- none {
+ none => {
ctxt.w.write_line(fmt!{"* `%s`", sig});
}
}
fn make_writer_factory(config: config::config) -> writer_factory {
alt config.output_format {
- config::markdown {
+ config::markdown => {
markdown_writer_factory(config)
}
- config::pandoc_html {
+ config::pandoc_html => {
pandoc_writer_factory(config)
}
}
let mut keep_going = true;
while keep_going {
alt comm::recv(po) {
- write(s) { markdown += s; }
- done { keep_going = false; }
+ write(s) => markdown += s,
+ done => keep_going = false
}
}
process(markdown);
) -> ~str {
let filename = {
alt page {
- doc::cratepage(doc) {
+ doc::cratepage(doc) => {
if config.output_format == config::pandoc_html &&
config.output_style == config::doc_per_mod {
~"index"
doc.topmod.name()
}
}
- doc::itempage(doc) {
+ doc::itempage(doc) => {
str::connect(doc.path() + ~[doc.name()], ~"_")
}
}
};
let ext = alt config.output_format {
- config::markdown { ~"md" }
- config::pandoc_html { ~"html" }
+ config::markdown => ~"md",
+ config::pandoc_html => ~"html"
};
filename + ~"." + ext
import io::writer_util;
alt io::file_writer(path, ~[io::create, io::truncate]) {
- result::ok(writer) {
+ result::ok(writer) => {
writer.write_str(s);
}
- result::err(e) { fail e }
+ result::err(e) => fail e
}
}
let mut res = ~"";
loop {
alt comm::recv(port) {
- write(s) { res += s }
- done { break; }
+ write(s) => res += s,
+ done => break
}
}
res
doc::moddoc_({
items: do vec::filter(doc.items) |item| {
alt item {
- doc::modtag(_) { false }
- doc::nmodtag(_) { false }
- _ { true }
+ doc::modtag(_) => false,
+ doc::nmodtag(_) => false,
+ _ => true
}
}
with *doc
let id = doc.id;
do astsrv::exec(srv) |ctxt| {
let attrs = alt ctxt.ast_map.get(id) {
- ast_map::node_item(item, _) { item.attrs }
- _ { ~[] }
+ ast_map::node_item(item, _) => item.attrs,
+ _ => ~[]
};
attr_parser::parse_hidden(attrs)
}
}
let config = alt config::parse_config(args) {
- result::ok(config) { config }
- result::err(err) {
+ result::ok(config) => config,
+ result::err(err) => {
io::println(fmt!{"error: %s", err});
return;
}
for lines.each |line| {
alt parse_header(line) {
- some(header) {
+ some(header) => {
if option::is_some(current_section) {
sections += ~[option::get(current_section)];
}
body: ~""
});
}
- none {
+ none => {
alt copy current_section {
- some(section) {
+ some(section) => {
current_section = some({
body: section.body + ~"\n" + line
with section
});
}
- none {
+ none => {
new_desc = alt new_desc {
- some(desc) {
+ some(desc) => {
some(desc + ~"\n" + line)
}
- none {
+ none => {
some(line)
}
};
pure fn by_score(item1: &doc::itemtag, item2: &doc::itemtag) -> bool {
pure fn score(item: &doc::itemtag) -> int {
alt *item {
- doc::consttag(_) { 0 }
- doc::tytag(_) { 1 }
- doc::enumtag(_) { 2 }
- doc::traittag(_) { 3 }
- doc::impltag(_) { 4 }
- doc::fntag(_) { 5 }
- doc::modtag(_) { 6 }
- doc::nmodtag(_) { 7 }
+ doc::consttag(_) => 0,
+ doc::tytag(_) => 1,
+ doc::enumtag(_) => 2,
+ doc::traittag(_) => 3,
+ doc::impltag(_) => 4,
+ doc::fntag(_) => 5,
+ doc::modtag(_) => 6,
+ doc::nmodtag(_) => 7
}
}
ast_map::node_foreign_item(@{
ident: ident,
node: ast::foreign_item_fn(decl, tys), _
- }, _, _) {
+ }, _, _) => {
some(pprust::fun_to_str(decl, ident, tys))
}
}
alt check ctxt.ast_map.get(doc.id()) {
ast_map::node_item(@{
node: ast::item_const(ty, _), _
- }, _) {
+ }, _) => {
pprust::ty_to_str(ty)
}
}
alt check ctxt.ast_map.get(doc_id) {
ast_map::node_item(@{
node: ast::item_enum(ast_variants, _), _
- }, _) {
+ }, _) => {
let ast_variant = option::get(
do vec::find(ast_variants) |v| {
*v.node.name == variant.name
alt check ctxt.ast_map.get(item_id) {
ast_map::node_item(@{
node: ast::item_trait(_, _, methods), _
- }, _) {
+ }, _) => {
alt check vec::find(methods, |method| {
alt method {
- ast::required(ty_m) { *ty_m.ident == method_name }
- ast::provided(m) { *m.ident == method_name }
+ ast::required(ty_m) => *ty_m.ident == method_name,
+ ast::provided(m) => *m.ident == method_name,
}
}) {
- some(method) {
+ some(method) => {
alt method {
- ast::required(ty_m) {
+ ast::required(ty_m) => {
some(pprust::fun_to_str(
ty_m.decl,
ty_m.ident,
ty_m.tps
))
}
- ast::provided(m) {
+ ast::provided(m) => {
some(pprust::fun_to_str(
m.decl,
m.ident,
}
ast_map::node_item(@{
node: ast::item_impl(_, _, _, methods), _
- }, _) {
+ }, _) => {
alt check vec::find(methods, |method| {
*method.ident == method_name
}) {
- some(method) {
+ some(method) => {
some(pprust::fun_to_str(
method.decl,
method.ident,
alt ctxt.ast_map.get(doc.id()) {
ast_map::node_item(@{
node: ast::item_impl(_, trait_types, self_ty, _), _
- }, _) {
+ }, _) => {
let trait_types = vec::map(trait_types, |p| {
pprust::path_to_str(p.path)
});
(trait_types, some(pprust::ty_to_str(self_ty)))
}
- _ { fail ~"expected impl" }
+ _ => fail ~"expected impl"
}
};
ast_map::node_item(@{
ident: ident,
node: ast::item_ty(ty, params), _
- }, _) {
+ }, _) => {
some(fmt!{
"type %s%s = %s",
*ident,
pprust::ty_to_str(ty)
})
}
- _ { fail ~"expected type" }
+ _ => fail ~"expected type"
}
}
with doc
let mut found = 0;
for int::range(0, 1000) |_i| {
alt s.find(r.gen_str(10)) {
- some(_) { found += 1; }
- none { }
+ some(_) => { found += 1; }
+ none => { }
}
}
}
fn is_gray(c: color) -> bool {
alt c {
- gray(_) { true }
- _ { false }
+ gray(_) => { true }
+ _ => { false }
}
}
colors = do colors.mapi() |i, c| {
let c : color = c;
alt c {
- white {
+ white => {
let i = i as node_id;
let neighbors = graph[i];
color
}
- gray(parent) { black(parent) }
- black(parent) { black(parent) }
+ gray(parent) => { black(parent) }
+ black(parent) => { black(parent) }
}
}
}
// Convert the results.
do vec::map(colors) |c| {
alt c {
- white { -1i64 }
- black(parent) { parent }
- _ { fail ~"Found remaining gray nodes in BFS" }
+ white => { -1i64 }
+ black(parent) => { parent }
+ _ => { fail ~"Found remaining gray nodes in BFS" }
}
}
}
#[inline(always)]
fn is_gray(c: color) -> bool {
alt c {
- gray(_) { true }
- _ { false }
+ gray(_) => { true }
+ _ => { false }
}
}
let colors = arc::get(&colors);
let graph = arc::get(&graph);
alt c {
- white {
+ white => {
let i = i as node_id;
let neighbors = graph[i];
};
color
}
- gray(parent) { black(parent) }
- black(parent) { black(parent) }
+ gray(parent) => { black(parent) }
+ black(parent) => { black(parent) }
}
}
};
// Convert the results.
do par::map(colors) |c| {
alt c {
- white { -1i64 }
- black(parent) { parent }
- _ { fail ~"Found remaining gray nodes in BFS" }
+ white => { -1i64 }
+ black(parent) => { parent }
+ _ => { fail ~"Found remaining gray nodes in BFS" }
}
}
}
let mut done = false;
while !done {
alt requests.try_recv() {
- some(get_count) { responses.send(copy count); }
- some(bytes(b)) {
+ some(get_count) => { responses.send(copy count); }
+ some(bytes(b)) => {
//error!{"server: received %? bytes", b};
count += b;
}
- none { done = true; }
- _ { }
+ none => { done = true; }
+ _ => { }
}
}
responses.send(count);
let mut done = false;
while !done {
alt requests.try_recv() {
- some(get_count) { responses.send(copy count); }
- some(bytes(b)) {
+ some(get_count) => { responses.send(copy count); }
+ some(bytes(b)) => {
//error!{"server: received %? bytes", b};
count += b;
}
- none { done = true; }
- _ { }
+ none => { done = true; }
+ _ => { }
}
}
responses.send(count);
num_chan = some(ring::client::num(option::unwrap(num_chan2), i * j));
let port = option::unwrap(num_port2);
alt recv(port) {
- ring::num(_n, p) {
+ ring::num(_n, p) => {
//log(error, _n);
num_port = some(move_out!{p});
}
let mut done = false;
while !done {
alt comm::recv(requests) {
- get_count { comm::send(responses, copy count); }
- bytes(b) { count += b; }
- stop { done = true; }
+ get_count => { comm::send(responses, copy count); }
+ bytes(b) => { count += b; }
+ stop => { done = true; }
}
}
comm::send(responses, count);
fn item_check(t: &tree) -> int {
alt *t {
- nil { return 0; }
- node(left, right, item) {
+ nil => { return 0; }
+ node(left, right, item) => {
return item + item_check(left) - item_check(right);
}
}
fn show_color(cc: color) -> ~str {
alt (cc) {
- Red {~"red"}
- Yellow {~"yellow"}
- Blue {~"blue"}
+ Red => {~"red"}
+ Yellow => {~"yellow"}
+ Blue => {~"blue"}
}
}
fn show_digit(nn: uint) -> ~str {
alt (nn) {
- 0 {~"zero"}
- 1 {~"one"}
- 2 {~"two"}
- 3 {~"three"}
- 4 {~"four"}
- 5 {~"five"}
- 6 {~"six"}
- 7 {~"seven"}
- 8 {~"eight"}
- 9 {~"nine"}
- _ {fail ~"expected digits from 0 to 9..."}
+ 0 => {~"zero"}
+ 1 => {~"one"}
+ 2 => {~"two"}
+ 3 => {~"three"}
+ 4 => {~"four"}
+ 5 => {~"five"}
+ 6 => {~"six"}
+ 7 => {~"seven"}
+ 8 => {~"eight"}
+ 9 => {~"nine"}
+ _ => {fail ~"expected digits from 0 to 9..."}
}
}
fn transform(aa: color, bb: color) -> color {
alt (aa, bb) {
- (Red, Red ) { Red }
- (Red, Yellow) { Blue }
- (Red, Blue ) { Yellow }
- (Yellow, Red ) { Blue }
- (Yellow, Yellow) { Yellow }
- (Yellow, Blue ) { Red }
- (Blue, Red ) { Yellow }
- (Blue, Yellow) { Red }
- (Blue, Blue ) { Blue }
+ (Red, Red ) => { Red }
+ (Red, Yellow) => { Blue }
+ (Red, Blue ) => { Yellow }
+ (Yellow, Red ) => { Blue }
+ (Yellow, Yellow) => { Yellow }
+ (Yellow, Blue ) => { Red }
+ (Blue, Red ) => { Yellow }
+ (Blue, Yellow) => { Red }
+ (Blue, Blue ) => { Blue }
}
}
// log and change, or print and quit
alt resp {
- option::some(other_creature) {
+ option::some(other_creature) => {
color = transform(color, other_creature.color);
// track some statistics
evil_clones_met += 1;
}
}
- option::none {
+ option::none => {
// log creatures met and evil clones of self
let report = fmt!{"%u", creatures_met} + ~" " +
show_number(evil_clones_met);
// given a map, search for the frequency of a pattern
fn find(mm: hashmap<~[u8], uint>, key: ~str) -> uint {
alt mm.find(str::bytes(str::to_lower(key))) {
- option::none { return 0u; }
- option::some(num) { return num; }
+ option::none => { return 0u; }
+ option::some(num) => { return num; }
}
}
fn update_freq(mm: hashmap<~[u8], uint>, key: &[u8]) {
let key = vec::slice(key, 0, key.len());
alt mm.find(key) {
- option::none { mm.insert(key, 1u ); }
- option::some(val) { mm.insert(key, 1u + val); }
+ option::none => { mm.insert(key, 1u ); }
+ option::some(val) => { mm.insert(key, 1u + val); }
}
}
}
let buffer = alt sz {
- 1u { sort_and_fmt(freqs, total) }
- 2u { sort_and_fmt(freqs, total) }
- 3u { fmt!{"%u\t%s", find(freqs, ~"GGT"), ~"GGT"} }
- 4u { fmt!{"%u\t%s", find(freqs, ~"GGTA"), ~"GGTA"} }
- 6u { fmt!{"%u\t%s", find(freqs, ~"GGTATT"), ~"GGTATT"} }
- 12u { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATT"), ~"GGTATTTTAATT"} }
- 18u { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATTTATAGT"), ~"GGTATTTTAATTTATAGT"} }
- _ { ~"" }
+ 1u => { sort_and_fmt(freqs, total) }
+ 2u => { sort_and_fmt(freqs, total) }
+ 3u => { fmt!{"%u\t%s", find(freqs, ~"GGT"), ~"GGT"} }
+ 4u => { fmt!{"%u\t%s", find(freqs, ~"GGTA"), ~"GGTA"} }
+ 6u => { fmt!{"%u\t%s", find(freqs, ~"GGTATT"), ~"GGTATT"} }
+ 12u => { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATT"), ~"GGTATTTTAATT"} }
+ 18u => { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATTTATAGT"), ~"GGTATTTTAATTTATAGT"} }
+ _ => { ~"" }
};
//comm::send(to_parent, fmt!{"yay{%u}", sz});
alt (line[0], proc_mode) {
// start processing if this is the one
- ('>' as u8, false) {
+ ('>' as u8, false) => {
alt str::find_str_from(line, ~"THREE", 1u) {
- option::some(_) { proc_mode = true; }
- option::none { }
+ option::some(_) => { proc_mode = true; }
+ option::none => { }
}
}
// break our processing
- ('>' as u8, true) { break; }
+ ('>' as u8, true) => { break; }
// process the sequence for k-mers
- (_, true) {
+ (_, true) => {
let line_bytes = str::bytes(line);
for sizes.eachi |ii, _sz| {
}
// whatever
- _ { }
+ _ => { }
}
}
// given a map, search for the frequency of a pattern
fn find(mm: hashmap<~[u8], uint>, key: ~str) -> uint {
alt mm.find(str::bytes(str::to_lower(key))) {
- option::none { return 0u; }
- option::some(num) { return num; }
+ option::none => { return 0u; }
+ option::some(num) => { return num; }
}
}
fn update_freq(mm: hashmap<~[u8], uint>, key: &[u8]) {
let key = vec::slice(key, 0, key.len());
alt mm.find(key) {
- option::none { mm.insert(key, 1u ); }
- option::some(val) { mm.insert(key, 1u + val); }
+ option::none => { mm.insert(key, 1u ); }
+ option::some(val) => { mm.insert(key, 1u + val); }
}
}
}
let buffer = alt sz {
- 1u { sort_and_fmt(freqs, total) }
- 2u { sort_and_fmt(freqs, total) }
- 3u { fmt!{"%u\t%s", find(freqs, ~"GGT"), ~"GGT"} }
- 4u { fmt!{"%u\t%s", find(freqs, ~"GGTA"), ~"GGTA"} }
- 6u { fmt!{"%u\t%s", find(freqs, ~"GGTATT"), ~"GGTATT"} }
- 12u { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATT"), ~"GGTATTTTAATT"} }
- 18u { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATTTATAGT"), ~"GGTATTTTAATTTATAGT"} }
- _ { ~"" }
+ 1u => { sort_and_fmt(freqs, total) }
+ 2u => { sort_and_fmt(freqs, total) }
+ 3u => { fmt!{"%u\t%s", find(freqs, ~"GGT"), ~"GGT"} }
+ 4u => { fmt!{"%u\t%s", find(freqs, ~"GGTA"), ~"GGTA"} }
+ 6u => { fmt!{"%u\t%s", find(freqs, ~"GGTATT"), ~"GGTATT"} }
+ 12u => { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATT"), ~"GGTATTTTAATT"} }
+ 18u => { fmt!{"%u\t%s", find(freqs, ~"GGTATTTTAATTTATAGT"), ~"GGTATTTTAATTTATAGT"} }
+ _ => { ~"" }
};
//comm::send(to_parent, fmt!{"yay{%u}", sz});
alt (line[0], proc_mode) {
// start processing if this is the one
- ('>' as u8, false) {
+ ('>' as u8, false) => {
alt str::find_str_from(line, ~"THREE", 1u) {
- option::some(_) { proc_mode = true; }
- option::none { }
+ option::some(_) => proc_mode = true,
+ option::none => ()
}
}
// break our processing
- ('>' as u8, true) { break; }
+ ('>' as u8, true) => { break; }
// process the sequence for k-mers
- (_, true) {
+ (_, true) => {
let line_bytes = str::bytes(line);
for sizes.eachi |ii, _sz| {
}
// whatever
- _ { }
+ _ => { }
}
}
let ch = comm::chan(p);
comm::send(writech, ch);
let cout: io::writer = alt path {
- ~"" {
+ ~"" => {
{dn: 0} as io::writer
}
- ~"-" {
+ ~"-" => {
io::stdout()
}
- _ {
+ _ => {
result::get(
io::file_writer(path,
~[io::create, io::truncate]))
fn roundtrip(id: int, p: comm::port<int>, ch: comm::chan<int>) {
while (true) {
alt comm::recv(p) {
- 1 {
+ 1 => {
io::println(fmt!{"%d\n", id});
return;
}
- token {
+ token => {
debug!{"%d %d", id, token};
comm::send(ch, token - 1);
if token <= n_threads {
let depth = depth - 1;
let st = alt st {
- none {
+ none => {
st_({
box: @nil,
unique: ~nil,
res: r(@nil)
})
}
- some(st) {
+ some(st) => {
let fn_box = st.fn_box;
let fn_unique = st.fn_unique;
for iter::repeat (children) {
alt check comm::recv(port) {
- ready(child_ch) {
+ ready(child_ch) => {
vec::push(child_chs, child_ch);
}
}
comm::send(parent_ch, ready(chan));
alt check comm::recv(port) {
- start {
+ start => {
do vec::iter (child_chs) |child_ch| {
comm::send(child_ch, start);
}
for iter::repeat (children) {
alt check comm::recv(port) {
- done(child_sum) { sum += child_sum; }
+ done(child_sum) => { sum += child_sum; }
}
}
calc(children, chan);
};
alt check comm::recv(port) {
- ready(chan) {
+ ready(chan) => {
comm::send(chan, start);
}
}
let sum = alt check comm::recv(port) {
- done(sum) { sum }
+ done(sum) => { sum }
};
error!{"How many tasks? %d tasks.", sum};
}
fn file_word_reader(filename: ~str) -> word_reader {
alt io::file_reader(filename) {
- result::ok(f) { f as word_reader }
- result::err(e) { fail fmt!{"%?", e} }
+ result::ok(f) => { f as word_reader }
+ result::err(e) => { fail fmt!{"%?", e} }
}
}
let f = f();
loop {
alt f.read_word() {
- some(w) { emit(w, 1); }
- none { break; }
+ some(w) => { emit(w, 1); }
+ none => { break; }
}
}
}
fn reduce(&&word: ~str, get: map_reduce::getter<int>) {
let mut count = 0;
- loop { alt get() { some(_) { count += 1; } none { break; } } }
+ loop { alt get() { some(_) => { count += 1; } none => { break; } } }
io::println(fmt!{"%s\t%?", word, count});
}
do map(input) |key, val| {
let mut c = none;
alt intermediates.find(key) {
- some(_c) { c = some(_c); }
- none {
+ some(_c) => { c = some(_c); }
+ none => {
do ctrl.swap |ctrl| {
let ctrl = ctrl_proto::client::find_reducer(ctrl, key);
alt pipes::recv(ctrl) {
- ctrl_proto::reducer(c_, ctrl) {
+ ctrl_proto::reducer(c_, ctrl) => {
c = some(c_);
move_out!{ctrl}
}
-> option<V> {
while !is_done || ref_count > 0 {
alt recv(p) {
- emit_val(v) {
+ emit_val(v) => {
// error!{"received %d", v};
return some(v);
}
- done {
+ done => {
// error!{"all done"};
is_done = true;
}
- addref { ref_count += 1; }
- release { ref_count -= 1; }
+ addref => { ref_count += 1; }
+ release => { ref_count -= 1; }
}
}
return none;
while num_mappers > 0 {
let (_ready, message, ctrls) = pipes::select(ctrl);
alt option::unwrap(message) {
- ctrl_proto::mapper_done {
+ ctrl_proto::mapper_done => {
// error!{"received mapper terminated."};
num_mappers -= 1;
ctrl = ctrls;
}
- ctrl_proto::find_reducer(k, cc) {
+ ctrl_proto::find_reducer(k, cc) => {
let c;
// log(error, "finding reducer for " + k);
alt reducers.find(k) {
- some(_c) {
+ some(_c) => {
// log(error,
// "reusing existing reducer for " + k);
c = _c;
}
- none {
+ none => {
// log(error, "creating new reducer for " + k);
let p = port();
let ch = chan(p);
fn my_fail() -> ! { fail; }
fn main() {
- alt true { false { my_fail(); } true { } }
+ alt true { false => { my_fail(); } true => { } }
log(debug, x); //~ ERROR unresolved name: x
let x: int;
fn foo(c: color) {
alt c {
- rgb(_, _, _) { }
- cmyk(_, _, _, _) { }
- no_color(_) { }
+ rgb(_, _, _) => { }
+ cmyk(_, _, _, _) => { }
+ no_color(_) => { }
//~^ ERROR this pattern has 1 field, but the corresponding variant has no fields
}
}
fn foo(c: color) {
alt c {
- rgb(_, _) { }
+ rgb(_, _) => { }
//~^ ERROR this pattern has 2 fields, but the corresponding variant has 3 fields
- cmyk(_, _, _, _) { }
- no_color { }
+ cmyk(_, _, _, _) => { }
+ no_color => { }
}
}
}
fn main() {
alt check 5u {
- 1u to 10u { }
- 5u to 6u { }
+ 1u to 10u => { }
+ 5u to 6u => { }
};
alt check 5u {
- 3u to 6u { }
- 4u to 6u { }
+ 3u to 6u => { }
+ 4u to 6u => { }
};
alt check 5u {
- 4u to 6u { }
- 4u to 6u { }
+ 4u to 6u => { }
+ 4u to 6u => { }
};
alt check 'c' {
- 'A' to 'z' {}
- 'a' to 'z' {}
+ 'A' to 'z' => {}
+ 'a' to 'z' => {}
};
alt check 1.0 {
- 0.01 to 6.5 {}
- 0.02 {}
+ 0.01 to 6.5 => {}
+ 0.02 => {}
};
}
\ No newline at end of file
fn main() {
alt 5u {
- 6u to 1u { }
- _ { }
+ 6u to 1u => { }
+ _ => { }
};
alt "wow" {
- "bar" to "foo" { }
+ "bar" to "foo" => { }
};
alt 5u {
- 'c' to 100u { }
- _ { }
+ 'c' to 100u => { }
+ _ => { }
};
}
enum a { A, }
enum b { B, }
-fn main() { let x: a = A; alt x { B { } } }
+fn main() { let x: a = A; alt x { B => { } } }
enum a { A(int), }
enum b { B(int), }
-fn main() { let x: a = A(0); alt x { B(y) { } } }
+fn main() { let x: a = A(0); alt x { B(y) => { } } }
// error-pattern:did not expect a record with a field `q`
-fn main() { alt {x: 1, y: 2} { {x: x, q: q} { } } }
+fn main() { alt {x: 1, y: 2} { {x: x, q: q} => { } } }
// error-pattern:expected a record with 2 fields, found one with 1
-fn main() { alt {x: 1, y: 2} { {x: x} { } } }
+fn main() { alt {x: 1, y: 2} { {x: x} => { } } }
fn main() {
let red: color = rgb(255, 0, 0);
alt red {
- rgb(r, g, b) { debug!{"rgb"}; }
- hsl(h, s, l) { debug!{"hsl"}; }
+ rgb(r, g, b) => { debug!{"rgb"}; }
+ hsl(h, s, l) => { debug!{"hsl"}; }
}
}
fn main() {
let x = some(~1);
alt x { //~ NOTE loan of immutable local variable granted here
- some(y) {
+ some(y) => {
let _a <- x; //~ ERROR moving out of immutable local variable prohibited due to outstanding loan
}
- _ {}
+ _ => {}
}
}
fn main() {
let x = some(~1);
alt x {
- some(y) {
+ some(y) => {
let _b <- y; //~ ERROR moving out of pattern binding
}
- _ {}
+ _ => {}
}
}
let x = ~node({mut a: ~empty});
// Create a cycle!
alt check *x { //~ NOTE loan of immutable local variable granted here
- node(y) {
+ node(y) => {
y.a <- x; //~ ERROR moving out of immutable local variable prohibited due to outstanding loan
}
};
fn match_imm_box(v: &const @option<int>) -> int {
alt *v {
- @some(i) {i}
- @none {0}
+ @some(i) => {i}
+ @none => {0}
}
}
fn match_const_box(v: &const @const option<int>) -> int {
alt *v {
- @some(i) { i } // ok because this is pure
- @none {0}
+ @some(i) => { i } // ok because this is pure
+ @none => {0}
}
}
fn match_const_box_and_do_pure_things(v: &const @const option<int>) {
alt *v {
- @some(i) {
+ @some(i) => {
pure_process(i)
}
- @none {}
+ @none => {}
}
}
fn match_const_box_and_do_bad_things(v: &const @const option<int>) {
alt *v {
- @some(i) { //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
+ @some(i) => { //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
process(i) //~ NOTE impure due to access to impure function
}
- @none {}
+ @none => {}
}
}
fn match_ref(&&v: option<int>) -> int {
alt v {
- some(i) {
+ some(i) => {
i
}
- none {0}
+ none => {0}
}
}
fn match_ref_unused(&&v: option<int>) {
alt v {
- some(_) {}
- none {}
+ some(_) => {}
+ none => {}
}
}
fn match_const_reg(v: &const option<int>) -> int {
alt *v {
- some(i) {i} // OK because this is pure
- none {0}
+ some(i) => {i} // OK because this is pure
+ none => {0}
}
}
fn match_const_reg_unused(v: &const option<int>) {
alt *v {
- some(_) {impure(0)} // OK because nothing is captured
- none {}
+ some(_) => {impure(0)} // OK because nothing is captured
+ none => {}
}
}
fn match_const_reg_impure(v: &const option<int>) {
alt *v {
- some(i) {impure(i)} //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
+ some(i) => {impure(i)} //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
//~^ NOTE impure due to access to impure function
- none {}
+ none => {}
}
}
fn match_imm_reg(v: &option<int>) {
alt *v {
- some(i) {impure(i)} // OK because immutable
- none {}
+ some(i) => {impure(i)} // OK because immutable
+ none => {}
}
}
fn main() {
let mut x: option<int> = none;
alt x { //~ NOTE loan of mutable local variable granted here
- none {}
- some(i) {
+ none => {}
+ some(i) => {
// Not ok: i is an outstanding ptr into x.
x = some(i+1); //~ ERROR assigning to mutable local variable prohibited due to outstanding loan
}
fn main() {
let mut x = none;
alt x { //~ NOTE loan of mutable local variable granted here
- none {
+ none => {
// It is ok to reassign x here, because there is in
// fact no outstanding loan of x!
x = some(0);
}
- some(i) {
+ some(i) => {
x = some(1); //~ ERROR assigning to mutable local variable prohibited due to outstanding loan
}
}
// check that unchecked alone does not override borrowck:
fn foo(v: &const option<int>) {
alt *v {
- some(i) {
+ some(i) => {
//~^ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
unchecked {
impure(i); //~ NOTE impure due to access to impure function
}
}
- none {
+ none => {
}
}
}
fn bar(v: &const option<int>) {
alt *v {
- some(i) {
+ some(i) => {
unsafe {
impure(i);
}
}
- none {
+ none => {
}
}
}
// error-pattern:cannot be dereferenced
fn main() {
alt *1 {
- _ { fail; }
+ _ => { fail; }
}
}
\ No newline at end of file
fn bar(v: t) -> bool {
alt v {
- a { return true; }
- b { return false; }
+ a => { return true; }
+ b => { return false; }
}
}
}
fn foo(a: option<uint>, b: option<uint>) {
alt (a,b) { //~ ERROR: non-exhaustive patterns: none not covered
- (some(a), some(b)) if a == b { }
+ (some(a), some(b)) if a == b => { }
(some(_), none) |
- (none, some(_)) { }
+ (none, some(_)) => { }
}
}
fn main() {
import bar::{alpha, charlie};
alt alpha {
- alpha | beta {} //~ ERROR: inconsistent number of bindings
- charlie {}
+ alpha | beta => {} //~ ERROR: inconsistent number of bindings
+ charlie => {}
}
}
fn main() {
alt alpha {
- alpha | beta(i) {} //~ ERROR inconsistent number of bindings
+ alpha | beta(i) => {} //~ ERROR inconsistent number of bindings
}
}
{
let _z = alt g(1, 2) {
- g(x, x) { log(debug, x + x); }
+ g(x, x) => { log(debug, x + x); }
//~^ ERROR Identifier x is bound more than once in the same pattern
};
let _z = alt i(l(1, 2), m(3, 4)) {
i(l(x, _), m(_, x)) //~ ERROR Identifier x is bound more than once in the same pattern
- { log(error, x + x); }
+ => { log(error, x + x); }
};
let _z = alt (1, 2) {
- (x, x) { x } //~ ERROR Identifier x is bound more than once in the same pattern
+ (x, x) => { x } //~ ERROR Identifier x is bound more than once in the same pattern
};
}
fn f() -> int {
// Make sure typestate doesn't interpreturn this alt expression
// as the function result
- alt check true { true { } };
+ alt check true { true => { } };
}
fn main() { }
fn f4() {
alt some(3) {
- some(i) {
+ some(i) => {
}
- none {}
+ none => {}
}
}
fn main() {
let x = a(c);
alt x {
- a(d) { fail ~"hello"; }
- b { fail ~"goodbye"; }
+ a(d) => { fail ~"hello"; }
+ b => { fail ~"goodbye"; }
}
}
fn main() {
let x = a;
- alt x { b { } } //~ ERROR non-exhaustive patterns
+ alt x { b => { } } //~ ERROR non-exhaustive patterns
alt true { //~ ERROR non-exhaustive patterns
- true {}
+ true => {}
}
alt @some(10) { //~ ERROR non-exhaustive patterns
- @none {}
+ @none => {}
}
alt (2, 3, 4) { //~ ERROR non-exhaustive patterns
- (_, _, 4) {}
+ (_, _, 4) => {}
}
alt (a, a) { //~ ERROR non-exhaustive patterns
- (a, b) {}
- (b, a) {}
+ (a, b) => {}
+ (b, a) => {}
}
alt a { //~ ERROR b not covered
- a {}
+ a => {}
}
// This is exhaustive, though the algorithm got it wrong at one point
alt (a, b) {
- (a, _) {}
- (_, a) {}
- (b, b) {}
+ (a, _) => {}
+ (_, a) => {}
+ (b, b) => {}
}
}
// error-pattern:mismatched types
// From Issue #778
enum clam<T> { a(T), }
-fn main() { let c; c = a(c); alt c { a::<int>(_) { } } }
+fn main() { let c; c = a(c); alt c { a::<int>(_) => { } } }
enum blah { a(int, int, uint), b(int, int), }
-fn main() { alt a(1, 1, 2u) { a(_, x, y) | b(x, y) { } } }
+fn main() { alt a(1, 1, 2u) { a(_, x, y) | b(x, y) => { } } }
enum bar { t1((), option<~[int]>), t2, }
-fn foo(t: bar) -> int { alt t { t1(_, some(x)) { return x * 3; } _ { fail; } } }
+fn foo(t: bar) -> int { alt t { t1(_, some(x)) => { return x * 3; } _ => { fail; } } }
fn main() { }
fn foo(t: bar) {
alt t {
- t1(_, some::<int>(x)) {
+ t1(_, some::<int>(x)) => {
log(debug, x);
}
- _ { fail; }
+ _ => { fail; }
}
}
fn compute(x: &ast) -> uint {
alt *x {
- num(x) { x }
- add(x, y) { compute(x) + compute(y) }
+ num(x) => { x }
+ add(x, y) => { compute(x) + compute(y) }
}
}
fn map_nums(x: &ast, f: fn(uint) -> uint) -> &ast {
alt *x {
- num(x) {
+ num(x) => {
return &num(f(x)); //~ ERROR illegal borrow
}
- add(x, y) {
+ add(x, y) => {
let m_x = map_nums(x, f);
let m_y = map_nums(y, f);
return &add(m_x, m_y); //~ ERROR illegal borrow
enum foo { a(@foo, int), b(uint), }
-fn main() { alt b(1u) { b(_) | a(@_, 1) { } a(_, 1) { } } }
+fn main() { alt b(1u) { b(_) | a(@_, 1) => { } a(_, 1) => { } } }
fn test3() {
let regs = @{mut eax: 0};
- alt check true { true { } }
+ alt check true { true => { } }
(*regs).eax = 1;
}
fn test7() -> uint {
let regs = @0;
- alt check true { true { } }
+ alt check true { true => { } }
(*regs < 2) as uint
}
fn test8() -> int {
let val = @0;
alt check true {
- true { }
+ true => { }
}
if *val < 1 {
0
}
}
-fn test9() { let regs = @mut 0; alt check true { true { } } *regs += 1; }
+fn test9() { let regs = @mut 0; alt check true { true => { } } *regs += 1; }
fn test10() -> int {
let regs = @mut ~[0];
- alt check true { true { } }
+ alt check true { true => { } }
(*regs)[0]
}
fn if_nosemi() -> int { (if true { 0 } else { 0 }) - 1 }
-fn alt_semi() -> int { alt check true { true { f() } }; -1 }
+fn alt_semi() -> int { alt check true { true => { f() } }; -1 }
-fn alt_no_semi() -> int { (alt check true { true { 0 } }) - 1 }
+fn alt_no_semi() -> int { (alt check true { true => { 0 } }) - 1 }
fn stmt() { { f() }; -1; }
fn main() {
let i =
- alt some::<int>(3) { none::<int> { fail } some::<int>(_) { fail } };
+ alt some::<int>(3) { none::<int> => { fail } some::<int>(_) => { fail } };
foo(i);
}
// error-pattern:quux
fn f() -> ! { fail ~"quux" }
-fn g() -> int { alt f() { true { 1 } false { 0 } } }
+fn g() -> int { alt f() { true => { 1 } false => { 0 } } }
fn main() { g(); }
// error-pattern:squirrelcupcake
fn cmp() -> int {
alt check (option::some('a'), option::none::<char>) {
- (option::some(_), _) { fail ~"squirrelcupcake"; }
- (_, option::some(_)) { fail; }
+ (option::some(_), _) => { fail ~"squirrelcupcake"; }
+ (_, option::some(_)) => { fail; }
}
}
// error-pattern:explicit failure
fn f() -> ! { fail }
-fn g() -> int { let x = alt true { true { f() } false { 10 } }; return x; }
+fn g() -> int { let x = alt true { true => { f() } false => { 10 } }; return x; }
fn main() { g(); }
// error-pattern:explicit failure
-fn main() { let x = alt true { false { 0 } true { fail } }; }
+fn main() { let x = alt true { false => { 0 } true => { fail } }; }
fn main() {
do io::with_str_reader(~"") |rdr| {
- alt rdr.read_char() { '=' { } _ { fail } }
+ alt rdr.read_char() { '=' => { } _ => { fail } }
}
}
@0;
}
fn test_str() {
- let res = alt check false { true { ~"happy" } };
+ let res = alt check false { true => { ~"happy" } };
assert res == ~"happy";
}
fn main() {
// n.b. This was only ever failing with optimization disabled.
-fn a() -> int { alt check return 1 { 2 { 3 } } }
+fn a() -> int { alt check return 1 { 2 => 3 } }
fn main() { a(); }
fn main() {
let i: int =
- alt some::<int>(3) { none::<int> { fail } some::<int>(_) { 5 } };
+ alt some::<int>(3) { none::<int> => { fail } some::<int>(_) => { 5 } };
log(debug, i);
}
fn main() {
let x = ~{mut a: ~10, b: ~20};
alt x {
- ~{a, b} { assert *a == 10; (*x).a = ~30; assert *a == 30; }
+ ~{a, b} => { assert *a == 10; (*x).a = ~30; assert *a == 30; }
}
}
fn main() {
let x = @{mut a: @10, b: @20};
alt x {
- @{a, b} { assert *a == 10; (*x).a = @30; assert *a == 30; }
+ @{a, b} => { assert *a == 10; (*x).a = @30; assert *a == 30; }
}
}
entire if expression */
if true {
- } else { alt y { none::<T> { x = 17; } _ { x = 42; } } rs += ~[x]; }
+ } else {
+ alt y {
+ none::<T> => x = 17,
+ _ => x = 42
+ }
+ rs += ~[x];
+ }
return;
}
enum foo { foo1, foo2, }
}
-fn bar(x: m1::foo) { alt x { m1::foo1 { } m1::foo2 { } } }
+fn bar(x: m1::foo) { alt x { m1::foo1 => { } m1::foo2 => { } } }
fn main() { }
let x: t = make_t(s); // ref up
alt x {
- make_t(y) {
+ make_t(y) => {
log(debug, y); // ref up then down
}
- _ { debug!{"?"}; fail; }
+ _ => { debug!{"?"}; fail; }
}
log(debug, sys::refcount(s));
assert (sys::refcount(s) == count + 1u);
fn altlit(f: int) -> int {
alt check f {
- 10 { debug!{"case 10"}; return 20; }
- 11 { debug!{"case 11"}; return 22; }
+ 10 => { debug!{"case 10"}; return 20; }
+ 11 => { debug!{"case 11"}; return 22; }
}
}
enum maybe<T> { nothing, just(T), }
fn foo(x: maybe<int>) {
- alt x { nothing { error!{"A"}; } just(a) { error!{"B"}; } }
+ alt x { nothing => { error!{"A"}; } just(a) => { error!{"B"}; } }
}
fn main() { }
-fn altsimple(f: int) { alt f { x { } } }
+fn altsimple(f: int) { alt f { x => () } }
fn main() { }
fn main() {
let mut x = true;
alt a {
- a { x = true; foo(|_i| { } ) }
- b { x = false; }
- c { x = false; }
+ a => { x = true; foo(|_i| { } ) }
+ b => { x = false; }
+ c => { x = false; }
}
}
fn main() {
alt 5u {
- 1u to 5u {}
- _ { fail ~"should match range"; }
+ 1u to 5u => {}
+ _ => fail ~"should match range",
}
alt 5u {
- 6u to 7u { fail ~"shouldn't match range"; }
- _ {}
+ 6u to 7u => fail ~"shouldn't match range",
+ _ => {}
}
alt check 5u {
- 1u { fail ~"should match non-first range"; }
- 2u to 6u {}
+ 1u => fail ~"should match non-first range",
+ 2u to 6u => {}
}
alt 'c' {
- 'a' to 'z' {}
- _ { fail ~"should suppport char ranges"; }
+ 'a' to 'z' => {}
+ _ => fail ~"should suppport char ranges"
}
alt -3 {
- -7 to 5 {}
- _ { fail ~"should match signed range"; }
+ -7 to 5 => {}
+ _ => fail ~"should match signed range"
}
alt 3.0 {
- 1.0 to 5.0 {}
- _ { fail ~"should match float range"; }
+ 1.0 to 5.0 => {}
+ _ => fail ~"should match float range"
}
alt -1.5 {
- -3.6 to 3.6 {}
- _ { fail ~"should match negative float range"; }
+ -3.6 to 3.6 => {}
+ _ => fail ~"should match negative float range"
}
}
// Issue #53
fn main() {
- alt check ~"test" { ~"not-test" { fail; } ~"test" { } _ { fail; } }
+ alt check ~"test" { ~"not-test" => fail, ~"test" => (), _ => fail }
enum t { tag1(~str), tag2, }
alt tag1(~"test") {
- tag2 { fail; }
- tag1(~"not-test") { fail; }
- tag1(~"test") { }
- _ { fail; }
+ tag2 => fail,
+ tag1(~"not-test") => fail,
+ tag1(~"test") => (),
+ _ => fail
}
- let x = alt check ~"a" { ~"a" { 1 } ~"b" { 2 } };
+ let x = alt check ~"a" { ~"a" => 1, ~"b" => 2 };
assert (x == 1);
- alt check ~"a" { ~"a" { } ~"b" { } }
+ alt check ~"a" { ~"a" => { } ~"b" => { } }
}
fn process(c: color) -> int {
let mut x: int;
alt c {
- rgb(r, _, _) { debug!{"rgb"}; log(debug, r); x = r; }
- rgba(_, _, _, a) { debug!{"rgba"}; log(debug, a); x = a; }
- hsl(_, s, _) { debug!{"hsl"}; log(debug, s); x = s; }
+ rgb(r, _, _) => { debug!{"rgb"}; log(debug, r); x = r; }
+ rgba(_, _, _, a) => { debug!{"rgba"}; log(debug, a); x = a; }
+ hsl(_, s, _) => { debug!{"hsl"}; log(debug, s); x = s; }
}
return x;
}
fn main() {
alt ~100 {
- ~x {
+ ~x => {
debug!{"%?", x};
assert x == 100;
}
// the right type for f, as we unified
// bot and u32 here
let f = alt uint::from_str(~"1234") {
- none { return () }
- some(num) { num as u32 }
+ none => return (),
+ some(num) => num as u32
};
assert f == 1234u32;
log(error, f)
// Check that issue #954 stays fixed
fn main() {
- alt check -1 { -1 {} }
+ alt check -1 { -1 => {} }
assert 1-1 == 0;
}
assert false;
}
alt do vec::all(v) |e| { float::is_negative(e) } {
- true { fail ~"incorrect answer."; }
- false { }
+ true => { fail ~"incorrect answer."; }
+ false => { }
}
alt 3 {
- _ if do vec::any(v) |e| { float::is_negative(e) } {
+ _ if do vec::any(v) |e| { float::is_negative(e) } => {
}
- _ {
+ _ => {
fail ~"wrong answer.";
}
}
fn main() {
let mut x = none;
alt x {
- none {
+ none => {
// It is ok to reassign x here, because there is in
// fact no outstanding loan of x!
x = some(0);
}
- some(_) { }
+ some(_) => { }
}
}
fn main() {
let x: @mut @option<~int> = @mut @none;
alt x {
- @@some(y) {
+ @@some(y) => {
// here, the refcount of `*x` is bumped so
// `y` remains valid even if `*x` is modified.
*x = @none;
}
- @@none {
+ @@none => {
// here, no bump of the ref count of `*x` is needed, but in
// fact a bump occurs anyway because of how pattern marching
// works.
fn main() {
let mut x = @{f: ~3};
alt *x {
- {f: b_x} {
+ {f: b_x} => {
assert *b_x == 3;
assert ptr::addr_of(*x.f) == ptr::addr_of(*b_x);
fn main() {
let mut x = @mut @{f: ~3};
alt x {
- @@{f: b_x} {
+ @@{f: b_x} => {
assert *b_x == 3;
assert ptr::addr_of(x.f) == ptr::addr_of(b_x);
fn switcher(x: option<@int>) {
let mut x = x;
alt x {
- some(@y) { copy y; x = none; }
- none { }
+ some(@y) => { copy y; x = none; }
+ none => { }
}
}
let x = @mut 5;
let y = @mut newtype(3);
let z = alt *y {
- newtype(b) {
+ newtype(b) => {
*x += 1;
*x * b
}
fn main() {
assert (alt u(@{a: 10, b: 40u}) {
- u(@{a: a, b: b}) { a + (b as int) }
- _ { 66 }
+ u(@{a: a, b: b}) => { a + (b as int) }
+ _ => { 66 }
} == 50);
}
fn contains_key_ref(k: &int) -> bool { self.contains_key(*k) }
fn get(+k:int) -> T { alt self.find(k) {
- some(v) { v }
- none { fail ~"epic fail"; }
+ some(v) => { v }
+ none => { fail ~"epic fail"; }
}
}
fn [](&&k:int) -> T { self.get(k) }
fn remove(+k:int) -> option<T> {
alt self.find(k) {
- some(x) {
+ some(x) => {
self.meows -= k; some(x)
}
- none { none }
+ none => { none }
}
}
enum t { foo(@int), }
-fn main() { let tt = foo(@10); alt tt { foo(z) { } } }
+fn main() { let tt = foo(@10); alt tt { foo(z) => { } } }
// Tests for alt as expressions resulting in boxed types
fn test_box() {
- let res = alt check true { true { @100 } };
+ let res = alt check true { true => { @100 } };
assert (*res == 100);
}
fn test_str() {
- let res = alt check true { true { ~"happy" } };
+ let res = alt check true { true => { ~"happy" } };
assert (res == ~"happy");
}
fn main() {
let x =
alt true {
- true { 10 }
- false { alt true { true { fail } false { fail } } }
+ true => { 10 }
+ false => { alt true { true => { fail } false => { fail } } }
};
}
fn test_simple() {
- let r = alt true { true { true } false { fail } };
+ let r = alt true { true => { true } false => { fail } };
assert (r == true);
}
fn test_box() {
- let r = alt true { true { ~[10] } false { fail } };
+ let r = alt true { true => { ~[10] } false => { fail } };
assert (r[0] == 10);
}
type compare<T> = fn@(@T, @T) -> bool;
fn test_generic<T>(expected: @T, eq: compare<T>) {
- let actual: @T = alt check true { true { expected } };
+ let actual: @T = alt check true { true => { expected } };
assert (eq(expected, actual));
}
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T: copy>(expected: T, eq: compare<T>) {
- let actual: T = alt check true { true { expected } };
+ let actual: T = alt check true { true => { expected } };
assert (eq(expected, actual));
}
type compare<T> = fn@(~T, ~T) -> bool;
fn test_generic<T: copy>(expected: ~T, eq: compare<T>) {
- let actual: ~T = alt check true { true { expected } };
+ let actual: ~T = alt check true { true => { expected } };
assert (eq(expected, actual));
}
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T: copy>(expected: T, eq: compare<T>) {
- let actual: T = alt check true { true { expected } };
+ let actual: T = alt check true { true => { expected } };
assert (eq(expected, actual));
}
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T: copy>(expected: T, eq: compare<T>) {
- let actual: T = alt check true { true { expected } };
+ let actual: T = alt check true { true => { expected } };
assert (eq(expected, actual));
}
// Tests for alt as expressions resulting in structural types
fn test_rec() {
- let rs = alt check true { true { {i: 100} } };
+ let rs = alt check true { true => { {i: 100} } };
assert (rs == {i: 100});
}
fn test_tag() {
enum mood { happy, sad, }
- let rs = alt true { true { happy } false { sad } };
+ let rs = alt true { true => { happy } false => { sad } };
assert (rs == happy);
}
// Tests for alt as expressions resulting in boxed types
fn test_box() {
- let res = alt check true { true { ~100 } };
+ let res = alt check true { true => { ~100 } };
assert (*res == 100);
}
// Tests for using alt as an expression
fn test_basic() {
- let mut rs: bool = alt true { true { true } false { false } };
+ let mut rs: bool = alt true { true => { true } false => { false } };
assert (rs);
- rs = alt false { true { false } false { true } };
+ rs = alt false { true => { false } false => { true } };
assert (rs);
}
fn test_inferrence() {
- let mut rs = alt true { true { true } false { false } };
+ let mut rs = alt true { true => { true } false => { false } };
assert (rs);
}
// Yeah, this is kind of confusing ...
let rs =
- alt alt false { true { true } false { false } } {
- true { false }
- false { true }
+ alt alt false { true => { true } false => { false } } {
+ true => { false }
+ false => { true }
};
assert (rs);
}
fn test_alt_as_block_result() {
let rs =
alt false {
- true { false }
- false { alt true { true { true } false { false } } }
+ true => { false }
+ false => { alt true { true => { true } false => { false } } }
};
assert (rs);
}
// Issue #521
-fn f() { let x = alt true { true { 10 } false { return } }; }
+fn f() { let x = alt true { true => { 10 } false => { return } }; }
fn main() { }
}
fn test_alt() {
- fn f() -> int { alt true { false { 10 } true { 20 } } }
+ fn f() -> int { alt true { false => { 10 } true => { 20 } } }
assert (f() == 20);
}
fn altfoo<T>(f: foo<T>) {
let mut hit = false;
- alt f { arm::<T>(x) { debug!{"in arm"}; hit = true; } }
+ alt f { arm::<T>(x) => { debug!{"in arm"}; hit = true; } }
assert (hit);
}
fn main() {
let nop: noption<int> = some::<int>(5);
- alt nop { some::<int>(n) { log(debug, n); assert (n == 5); } }
+ alt nop { some::<int>(n) => { log(debug, n); assert (n == 5); } }
let nop2: noption<{x: int, y: int}> = some({x: 17, y: 42});
alt nop2 {
- some(t) {
+ some(t) => {
log(debug, t.x);
log(debug, t.y);
assert (t.x == 17);
fn main() {
let a =
- alt 10 { x if x < 7 { 1 } x if x < 11 { 2 } 10 { 3 } _ { 4 } };
+ alt 10 { x if x < 7 => { 1 } x if x < 11 => { 2 } 10 => { 3 } _ => { 4 } };
assert (a == 2);
let b =
alt {x: 10, y: 20} {
- x if x.x < 5 && x.y < 5 { 1 }
- {x: x, y: y} if x == 10 && y == 20 { 2 }
- {x: x, y: y} { 3 }
+ x if x.x < 5 && x.y < 5 => { 1 }
+ {x: x, y: y} if x == 10 && y == 20 => { 2 }
+ {x: x, y: y} => { 3 }
};
assert (b == 2);
}
val: ~str) {
let mut c;
alt im.find(key) {
- some(_c) { c = _c }
- none {
+ some(_c) => { c = _c }
+ none => {
let p = port();
error!{"sending find_reducer"};
send(ctrl, find_reducer(str::bytes(key), chan(p)));
while num_mappers > 0 {
alt recv(ctrl) {
- mapper_done { num_mappers -= 1; }
- find_reducer(k, cc) {
+ mapper_done => { num_mappers -= 1; }
+ find_reducer(k, cc) => {
let mut c;
alt reducers.find(str::from_bytes(k)) {
- some(_c) { c = _c; }
- none { c = 0; }
+ some(_c) => { c = _c; }
+ none => { c = 0; }
}
send(cc, c);
}
fn main() {
let x = 2;
let x_message = alt x {
- 0 to 1 { ~"not many" }
- _ { ~"lots" }
+ 0 to 1 => { ~"not many" }
+ _ => { ~"lots" }
};
assert x_message == ~"lots";
let y = 2i;
let y_message = alt y {
- 0 to 1 { ~"not many" }
- _ { ~"lots" }
+ 0 to 1 => { ~"not many" }
+ _ => { ~"lots" }
};
assert y_message == ~"lots";
let z = 1u64;
let z_message = alt z {
- 0 to 1 { ~"not many" }
- _ { ~"lots" }
+ 0 to 1 => { ~"not many" }
+ _ => { ~"lots" }
};
assert z_message == ~"not many";
}
fn noise(a: animal) -> option<~str> {
alt a {
- cat(*) { some(~"meow") }
- dog(*) { some(~"woof") }
- rabbit(*) { none }
- tiger(*) { some(~"roar") }
+ cat(*) => { some(~"meow") }
+ dog(*) => { some(~"woof") }
+ rabbit(*) => { none }
+ tiger(*) => { some(~"roar") }
}
}
(*p).payload <- some(payload);
let old_state = swap_state_rel((*p).state, full);
alt old_state {
- empty {
+ empty => {
// Yay, fastpath.
// The receiver will eventually clean this up.
unsafe { forget(p); }
}
- full { fail ~"duplicate send" }
- blocked {
+ full => { fail ~"duplicate send" }
+ blocked => {
// The receiver will eventually clean this up.
unsafe { forget(p); }
}
- terminated {
+ terminated => {
// The receiver will never receive this. Rely on drop_glue
// to clean everything up.
}
let old_state = swap_state_acq((*p).state,
blocked);
alt old_state {
- empty | blocked { task::yield(); }
- full {
+ empty | blocked => { task::yield(); }
+ full => {
let mut payload = none;
payload <-> (*p).payload;
return some(option::unwrap(payload))
}
- terminated {
+ terminated => {
assert old_state == terminated;
return none;
}
fn sender_terminate<T: send>(p: *packet<T>) {
let p = unsafe { uniquify(p) };
alt swap_state_rel((*p).state, terminated) {
- empty | blocked {
+ empty | blocked => {
// The receiver will eventually clean up.
unsafe { forget(p) }
}
- full {
+ full => {
// This is impossible
fail ~"you dun goofed"
}
- terminated {
+ terminated => {
// I have to clean up, use drop_glue
}
}
fn receiver_terminate<T: send>(p: *packet<T>) {
let p = unsafe { uniquify(p) };
alt swap_state_rel((*p).state, terminated) {
- empty {
+ empty => {
// the sender will clean up
unsafe { forget(p) }
}
- blocked {
+ blocked => {
// this shouldn't happen.
fail ~"terminating a blocked packet"
}
- terminated | full {
+ terminated | full => {
// I have to clean up, use drop_glue
}
}
fn liberate_ping(-p: ping) -> pipes::send_packet<pong> unsafe {
let addr : *pipes::send_packet<pong> = alt p {
- ping(x) { unsafe::reinterpret_cast(ptr::addr_of(x)) }
+ ping(x) => { unsafe::reinterpret_cast(ptr::addr_of(x)) }
};
let liberated_value <- *addr;
unsafe::forget(p);
fn liberate_pong(-p: pong) -> pipes::send_packet<ping> unsafe {
let addr : *pipes::send_packet<ping> = alt p {
- pong(x) { unsafe::reinterpret_cast(ptr::addr_of(x)) }
+ pong(x) => { unsafe::reinterpret_cast(ptr::addr_of(x)) }
};
let liberated_value <- *addr;
unsafe::forget(p);
{
alt table.find(key)
{
- option::some(std::json::string(s))
+ option::some(std::json::string(s)) =>
{
*s
}
- option::some(value)
+ option::some(value) =>
{
error!{"%s was expected to be a string but is a %?", key, value};
default
}
- option::none
+ option::none =>
{
default
}
{
alt data
{
- std::json::dict(interface)
+ std::json::dict(interface) =>
{
let name = lookup(interface, ~"ifDescr", ~"");
let label = fmt!{"%s-%s", managed_ip, name};
(label, bool_value(false))
}
- _
+ _ =>
{
error!{"Expected dict for %s interfaces but found %?", managed_ip, data};
(~"gnos:missing-interface", bool_value(true))
{
alt device[~"interfaces"]
{
- std::json::list(interfaces)
+ std::json::list(interfaces) =>
{
do vec::map(*interfaces) |interface| {
add_interface(store, managed_ip, interface)
}
}
- _
+ _ =>
{
error!{"Expected list for %s interfaces but found %?", managed_ip, device[~"interfaces"]};
~[]
impl of to_str::to_str for square {
fn to_str() -> ~str {
alt self {
- bot { ~"R" }
- wall { ~"#" }
- rock { ~"*" }
- lambda { ~"\\" }
- closed_lift { ~"L" }
- open_lift { ~"O" }
- earth { ~"." }
- empty { ~" " }
+ bot => { ~"R" }
+ wall => { ~"#" }
+ rock => { ~"*" }
+ lambda => { ~"\\" }
+ closed_lift => { ~"L" }
+ open_lift => { ~"O" }
+ earth => { ~"." }
+ empty => { ~" " }
}
}
}
fn square_from_char(c: char) -> square {
alt c {
- 'R' { bot }
- '#' { wall }
- '*' { rock }
- '\\' { lambda }
- 'L' { closed_lift }
- 'O' { open_lift }
- '.' { earth }
- ' ' { empty }
- _ {
+ 'R' => { bot }
+ '#' => { wall }
+ '*' => { rock }
+ '\\' => { lambda }
+ 'L' => { closed_lift }
+ 'O' => { open_lift }
+ '.' => { earth }
+ ' ' => { empty }
+ _ => {
#error("invalid square: %?", c);
fail
}
loop {
let msg = recv(p);
alt msg {
- closed { debug!{"Got close message"}; break; }
- received(data) {
+ closed => { debug!{"Got close message"}; break; }
+ received(data) => {
debug!{"Got data. Length is:"};
log(debug, vec::len::<u8>(data));
}
fn bar() -> int {
match 0 {
- _ { 0 }
+ _ => { 0 }
}
}
\ No newline at end of file
let p = test_comm::port();
alt none::<int> {
- none {}
- some(_) {
+ none => {}
+ some(_) =>{
if test_comm::recv(p) == 0 {
error!{"floop"};
}
{
fn $fnname($arg: $ty) -> option<$ty> $body
alt $fnname($val) {
- some($pat) {
+ some($pat) => {
$res
}
- _ { fail; }
+ _ => { fail; }
}
}
fn animal() -> ~str { ~"cat" }
fn talk(c: cat) -> ~str {
alt c {
- howlycat { ~"howl" }
- meowlycat { ~"meow" }
+ howlycat => { ~"howl" }
+ meowlycat => { ~"meow" }
}
}
impl monad<A> of option_monad<A> for option<A> {
fn bind<B>(f: fn(A) -> option<B>) -> option<B> {
alt self {
- some(a) { f(a) }
- none { none }
+ some(a) => { f(a) }
+ none => { none }
}
}
}
fn main() {
alt -5 {
- -5 {}
- _ { fail }
+ -5 => {}
+ _ => { fail }
}
}
\ No newline at end of file
fn foo() {
alt some::<int>(5) {
- some::<int>(x) {
+ some::<int>(x) => {
let mut bar;
- alt none::<int> { none::<int> { bar = 5; } _ { baz(); } }
+ alt none::<int> { none::<int> => { bar = 5; } _ => { baz(); } }
log(debug, bar);
}
- none::<int> { debug!{"hello"}; }
+ none::<int> => { debug!{"hello"}; }
}
}
fn main() {
alt @{foo: true, bar: some(10), baz: 20} {
- @{foo: true, bar: some(_), _} {}
- @{foo: false, bar: none, _} {}
- @{foo: true, bar: none, _} {}
- @{foo: false, bar: some(_), _} {}
+ @{foo: true, bar: some(_), _} => {}
+ @{foo: false, bar: none, _} => {}
+ @{foo: true, bar: none, _} => {}
+ @{foo: false, bar: some(_), _} => {}
}
}
fn nested(o: t) {
alt o {
- bar(i, some::<int>(_)) { error!{"wrong pattern matched"}; fail; }
- _ { error!{"succeeded"}; }
+ bar(i, some::<int>(_)) => { error!{"wrong pattern matched"}; fail; }
+ _ => { error!{"succeeded"}; }
}
}
fn main() {
alt {a: 10, b: @20} {
- x@{a, b: @20} { assert x.a == 10; assert a == 10; }
- {b, _} { fail; }
+ x@{a, b: @20} => { assert x.a == 10; assert a == 10; }
+ {b, _} => { fail; }
}
let x@{b, _} = {a: 10, b: {mut c: 20}};
x.b.c = 30;
-fn main() { let x = (); alt x { () { } } }
+fn main() { let x = (); alt x { () => { } } }
import std::list::*;
pure fn pure_length_go<T: copy>(ls: @list<T>, acc: uint) -> uint {
- alt *ls { nil { acc } cons(_, tl) { pure_length_go(tl, acc + 1u) } }
+ alt *ls { nil => { acc } cons(_, tl) => { pure_length_go(tl, acc + 1u) } }
}
pure fn pure_length<T: copy>(ls: @list<T>) -> uint { pure_length_go(ls, 0u) }
enum blah { a, b, }
fn or_alt(q: blah) -> int {
- alt q { a | b { 42 } }
+ alt q { a | b => { 42 } }
}
fn main() {
enum blah { a(int, int, uint), b(int, int), c, }
fn or_alt(q: blah) -> int {
- alt q { a(x, y, _) | b(x, y) { return x + y; } c { return 0; } }
+ alt q { a(x, y, _) | b(x, y) => { return x + y; } c => { return 0; } }
}
fn main() {
fn main() {
let x = true;
if x { let mut i = 10; while i > 0 { i -= 1; } }
- alt x { true { debug!{"right"}; } false { debug!{"wrong"}; } }
+ alt x { true => { debug!{"right"}; } false => { debug!{"wrong"}; } }
}
fn foo(src: uint) {
alt some(src) {
- some(src_id) {
+ some(src_id) => {
for uint::range(0u, 10u) |i| {
let yyy = src_id;
assert (yyy == 0u);
}
}
- _ { }
+ _ => { }
}
}
let bank = client::login(bank, ~"theincredibleholk", ~"1234");
let bank = alt try_recv(bank) {
- some(ok(connected)) {
+ some(ok(connected)) => {
move_it!{connected}
}
- some(invalid(_)) { fail ~"login unsuccessful" }
- none { fail ~"bank closed the connection" }
+ some(invalid(_)) => { fail ~"login unsuccessful" }
+ none => { fail ~"bank closed the connection" }
};
let bank = client::deposit(bank, 100.00);
let bank = client::withdrawal(bank, 50.00);
alt try_recv(bank) {
- some(money(m, _)) {
+ some(money(m, _)) => {
io::println(~"Yay! I got money!");
}
- some(insufficient_funds(_)) {
+ some(insufficient_funds(_)) => {
fail ~"someone stole my money"
}
- none {
+ none => {
fail ~"bank closed the connection"
}
}
pipes::spawn_service(oneshot::init, |p| {
alt try_recv(p) {
- some(*) { fail }
- none { }
+ some(*) => { fail }
+ none => { }
}
});
stream::client::send(ac, 42);
alt pipes::select2(ap, bp) {
- either::left(*) { }
- either::right(*) { fail }
+ either::left(*) => { }
+ either::right(*) => { fail }
}
stream::client::send(bc, ~"abc");
stream::client::send(bc, ~"abc");
alt pipes::select2(ap, bp) {
- either::left(*) { fail }
- either::right(*) { }
+ either::left(*) => { fail }
+ either::right(*) => { }
}
stream::client::send(ac, 42);
fn m(in: t3) -> int {
alt in {
- c({x: a(m), _}, _) { return m; }
- c({x: b(m), y: y}, z) { return ((m + z) as int) + y; }
+ c({x: a(m), _}, _) => { return m; }
+ c({x: b(m), y: y}, z) => { return ((m + z) as int) + y; }
}
}
// naively borrowed &x for the lifetime
// of the variable x, as we once did
alt i {
- i {
+ i => {
let y = &x;
assert i < *y;
}
let y = int_wrapper_ctor(&x);
let mut z : ∫
alt y {
- int_wrapper_ctor(zz) { z = zz; }
+ int_wrapper_ctor(zz) => { z = zz; }
}
log(debug, *z);
}
alt none::<int> {
- some::<int>(_) {
+ some::<int>(_) => {
for c.each |i| {
log(debug, a);
let a = 17;
b += ~[a];
}
}
- _ { }
+ _ => { }
}
}
fn main() {
let x = none::<int>;
- alt x { none::<int> { debug!{"hello world"}; } }
+ alt x { none::<int> => { debug!{"hello world"}; } }
}
enum clam<T> { a(T), }
-fn main() { let c = a(2); alt c { a::<int>(_) { } } }
+fn main() { let c = a(2); alt c { a::<int>(_) => { } } }
fn uhoh<T>(v: ~[clam<T>]) {
alt v[1] {
- a::<T>(t, u) { debug!{"incorrect"}; log(debug, u); fail; }
- b::<T> { debug!{"correct"}; }
+ a::<T>(t, u) => { debug!{"incorrect"}; log(debug, u); fail; }
+ b::<T> => { debug!{"correct"}; }
}
}
fn get_color_alt(color: color) -> ~str {
alt color {
- red {~"red"}
- green {~"green"}
- blue {~"blue"}
- black {~"black"}
- white {~"white"}
- imaginary {~"imaginary"}
- purple {~"purple"}
- orange {~"orange"}
+ red => {~"red"}
+ green => {~"green"}
+ blue => {~"blue"}
+ black => {~"black"}
+ white => {~"white"}
+ imaginary => {~"imaginary"}
+ purple => {~"purple"}
+ orange => {~"orange"}
}
}
impl <T: to_str> of to_str for option<T> {
fn to_str() -> ~str {
alt self {
- none { ~"none" }
- some(t) { ~"some(" + t.to_str() + ~")" }
+ none => { ~"none" }
+ some(t) => { ~"some(" + t.to_str() + ~")" }
}
}
}
fn f() {
let x = 10; let mut y = 11;
- if true { alt x { _ { y = x; } } } else { }
+ if true { alt x { _ => { y = x; } } } else { }
}
fn main() {
fn altsimple() {
alt ~true {
- _ { }
+ _ => { }
}
}
fn main() { }
\ No newline at end of file
let x = u(~10);
assert alt x {
- u(a) {
+ u(a) => {
log(error, a);
*a
}
- _ { 66 }
+ _ => { 66 }
} == 10;
}
fn main() {
assert (alt u(~{a: 10, b: 40u}) {
- u(~{a: a, b: b}) { a + (b as int) }
- _ { 66 }
+ u(~{a: a, b: b}) => { a + (b as int) }
+ _ => { 66 }
} == 50);
}
fn main() {
assert alt u(~10) {
- u(a) {
+ u(a) => {
log(error, a);
*a
}
- _ { 66 }
+ _ => { 66 }
} == 10;
}
fn simple() {
alt ~true {
- ~true { }
- _ { fail; }
+ ~true => { }
+ _ => { fail; }
}
}
fn ret_guard() {
alt 2 {
- x if (return) { x; }
- _ {}
+ x if (return) => { x; }
+ _ => {}
}
}
fn foo<T>(o: myoption<T>) -> int {
let mut x: int = 5;
- alt o { none::<T> { } some::<T>(t) { x += 1; } }
+ alt o { none::<T> => { } some::<T>(t) => { x += 1; } }
return x;
}
fn foo<T>(o: myoption<T>) -> int {
let mut x: int;
- alt o { none::<T> { fail; } some::<T>(t) { x = 5; } }
+ alt o { none::<T> => { fail; } some::<T>(t) => { x = 5; } }
return x;
}
while (return) {
if (return) {
alt (return) {
- 1 {
+ 1 => {
if (return) {
return
} else {
return
}
}
- _ { return }
+ _ => { return }
};
} else if (return) {
return;
fn angrydome() {
loop { if break { } }
let mut i = 0;
- loop { i += 1; if i == 1 { alt check again { 1 { } } } break; }
+ loop { i += 1; if i == 1 { alt check again { 1 => { } } } break; }
}
fn evil_lincoln() { let evil <- debug!{"lincoln"}; }