Camel case the option type
This commit is contained in:
parent
d9a6a63653
commit
8337fa1a54
330 changed files with 4929 additions and 4926 deletions
|
|
@ -20,7 +20,7 @@ type package = {
|
|||
url: ~str,
|
||||
method: ~str,
|
||||
description: ~str,
|
||||
reference: option<~str>,
|
||||
reference: Option<~str>,
|
||||
tags: ~[~str],
|
||||
versions: ~[(~str, ~str)]
|
||||
};
|
||||
|
|
@ -36,8 +36,8 @@ type source = @{
|
|||
name: ~str,
|
||||
mut url: ~str,
|
||||
mut method: ~str,
|
||||
mut key: option<~str>,
|
||||
mut keyfp: option<~str>,
|
||||
mut key: Option<~str>,
|
||||
mut keyfp: Option<~str>,
|
||||
mut packages: ~[mut package]
|
||||
};
|
||||
|
||||
|
|
@ -59,9 +59,9 @@ type crate = {
|
|||
name: ~str,
|
||||
vers: ~str,
|
||||
uuid: ~str,
|
||||
desc: option<~str>,
|
||||
sigs: option<~str>,
|
||||
crate_type: option<~str>,
|
||||
desc: Option<~str>,
|
||||
sigs: Option<~str>,
|
||||
crate_type: Option<~str>,
|
||||
deps: ~[~str]
|
||||
};
|
||||
|
||||
|
|
@ -193,7 +193,7 @@ fn is_archive_url(u: ~str) -> bool {
|
|||
// url parsing, we wouldn't need it
|
||||
|
||||
match str::find_str(u, ~"://") {
|
||||
option::some(_) => has_archive_extension(u),
|
||||
option::Some(_) => has_archive_extension(u),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
|
@ -216,19 +216,19 @@ fn assume_source_method(url: ~str) -> ~str {
|
|||
~"curl"
|
||||
}
|
||||
|
||||
fn load_link(mis: ~[@ast::meta_item]) -> (option<~str>,
|
||||
option<~str>,
|
||||
option<~str>) {
|
||||
let mut name = none;
|
||||
let mut vers = none;
|
||||
let mut uuid = none;
|
||||
fn load_link(mis: ~[@ast::meta_item]) -> (Option<~str>,
|
||||
Option<~str>,
|
||||
Option<~str>) {
|
||||
let mut name = None;
|
||||
let mut vers = None;
|
||||
let mut uuid = None;
|
||||
for mis.each |a| {
|
||||
match a.node {
|
||||
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => {
|
||||
match 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),
|
||||
_ => { }
|
||||
}
|
||||
}
|
||||
|
|
@ -238,24 +238,24 @@ fn load_link(mis: ~[@ast::meta_item]) -> (option<~str>,
|
|||
(name, vers, uuid)
|
||||
}
|
||||
|
||||
fn load_crate(filename: &Path) -> option<crate> {
|
||||
let sess = parse::new_parse_sess(none);
|
||||
fn load_crate(filename: &Path) -> Option<crate> {
|
||||
let sess = parse::new_parse_sess(None);
|
||||
let c = parse::parse_crate_from_crate_file(filename, ~[], sess);
|
||||
|
||||
let mut name = none;
|
||||
let mut vers = none;
|
||||
let mut uuid = none;
|
||||
let mut desc = none;
|
||||
let mut sigs = none;
|
||||
let mut crate_type = none;
|
||||
let mut name = None;
|
||||
let mut vers = None;
|
||||
let mut uuid = None;
|
||||
let mut desc = None;
|
||||
let mut sigs = None;
|
||||
let mut crate_type = None;
|
||||
|
||||
for c.node.attrs.each |a| {
|
||||
match a.node.value.node {
|
||||
ast::meta_name_value(v, {node: ast::lit_str(_), span: _}) => {
|
||||
match 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),
|
||||
_ => { }
|
||||
}
|
||||
}
|
||||
|
|
@ -296,7 +296,7 @@ fn load_crate(filename: &Path) -> option<crate> {
|
|||
|
||||
for m.each |item| {
|
||||
match attr::get_meta_item_value_str(item) {
|
||||
some(value) => {
|
||||
Some(value) => {
|
||||
let name = attr::get_meta_item_name(item);
|
||||
|
||||
match name {
|
||||
|
|
@ -305,7 +305,7 @@ fn load_crate(filename: &Path) -> option<crate> {
|
|||
_ => ()
|
||||
}
|
||||
}
|
||||
none => ()
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -342,8 +342,8 @@ fn load_crate(filename: &Path) -> option<crate> {
|
|||
let deps = copy e.deps;
|
||||
|
||||
match (name, vers, uuid) {
|
||||
(some(name0), some(vers0), some(uuid0)) => {
|
||||
some({
|
||||
(Some(name0), Some(vers0), Some(uuid0)) => {
|
||||
Some({
|
||||
name: name0,
|
||||
vers: vers0,
|
||||
uuid: uuid0,
|
||||
|
|
@ -352,7 +352,7 @@ fn load_crate(filename: &Path) -> option<crate> {
|
|||
crate_type: crate_type,
|
||||
deps: deps })
|
||||
}
|
||||
_ => return none
|
||||
_ => return None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -395,20 +395,20 @@ fn parse_source(name: ~str, j: json::json) -> source {
|
|||
match j {
|
||||
json::dict(j) => {
|
||||
let mut url = match j.find(~"url") {
|
||||
some(json::string(u)) => *u,
|
||||
Some(json::string(u)) => *u,
|
||||
_ => fail ~"needed 'url' field in source"
|
||||
};
|
||||
let method = match j.find(~"method") {
|
||||
some(json::string(u)) => *u,
|
||||
Some(json::string(u)) => *u,
|
||||
_ => assume_source_method(url)
|
||||
};
|
||||
let key = match j.find(~"key") {
|
||||
some(json::string(u)) => some(*u),
|
||||
_ => none
|
||||
Some(json::string(u)) => Some(*u),
|
||||
_ => None
|
||||
};
|
||||
let keyfp = match j.find(~"keyfp") {
|
||||
some(json::string(u)) => some(*u),
|
||||
_ => none
|
||||
Some(json::string(u)) => Some(*u),
|
||||
_ => None
|
||||
};
|
||||
if method == ~"file" {
|
||||
url = os::make_absolute(&Path(url)).to_str();
|
||||
|
|
@ -442,7 +442,7 @@ fn try_parse_sources(filename: &Path, sources: map::hashmap<~str, source>) {
|
|||
|
||||
fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
|
||||
let name = match p.find(~"name") {
|
||||
some(json::string(n)) => {
|
||||
Some(json::string(n)) => {
|
||||
if !valid_pkg_name(*n) {
|
||||
warn(~"malformed source json: "
|
||||
+ src.name + ~", '" + *n + ~"'"+
|
||||
|
|
@ -459,7 +459,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
|
|||
};
|
||||
|
||||
let uuid = match p.find(~"uuid") {
|
||||
some(json::string(n)) => {
|
||||
Some(json::string(n)) => {
|
||||
if !is_uuid(*n) {
|
||||
warn(~"malformed source json: "
|
||||
+ src.name + ~", '" + *n + ~"'"+
|
||||
|
|
@ -475,7 +475,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
|
|||
};
|
||||
|
||||
let url = match p.find(~"url") {
|
||||
some(json::string(n)) => *n,
|
||||
Some(json::string(n)) => *n,
|
||||
_ => {
|
||||
warn(~"malformed source json: " + src.name + ~" (missing url)");
|
||||
return;
|
||||
|
|
@ -483,7 +483,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
|
|||
};
|
||||
|
||||
let method = match p.find(~"method") {
|
||||
some(json::string(n)) => *n,
|
||||
Some(json::string(n)) => *n,
|
||||
_ => {
|
||||
warn(~"malformed source json: "
|
||||
+ src.name + ~" (missing method)");
|
||||
|
|
@ -492,13 +492,13 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
|
|||
};
|
||||
|
||||
let reference = match p.find(~"ref") {
|
||||
some(json::string(n)) => some(*n),
|
||||
_ => none
|
||||
Some(json::string(n)) => Some(*n),
|
||||
_ => None
|
||||
};
|
||||
|
||||
let mut tags = ~[];
|
||||
match p.find(~"tags") {
|
||||
some(json::list(js)) => {
|
||||
Some(json::list(js)) => {
|
||||
for (*js).each |j| {
|
||||
match j {
|
||||
json::string(j) => vec::grow(tags, 1u, *j),
|
||||
|
|
@ -510,7 +510,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
|
|||
}
|
||||
|
||||
let description = match p.find(~"description") {
|
||||
some(json::string(n)) => *n,
|
||||
Some(json::string(n)) => *n,
|
||||
_ => {
|
||||
warn(~"malformed source json: " + src.name
|
||||
+ ~" (missing description)");
|
||||
|
|
@ -530,11 +530,11 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
|
|||
};
|
||||
|
||||
match 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -704,7 +704,7 @@ fn run_programs(buildpath: &Path) {
|
|||
// Runs rustc in <path + subdir> with the given flags
|
||||
// and returns <patho + subdir>
|
||||
fn run_in_buildpath(what: &str, path: &Path, subdir: &Path, cf: &Path,
|
||||
extra_flags: ~[~str]) -> option<Path> {
|
||||
extra_flags: ~[~str]) -> Option<Path> {
|
||||
let buildpath = path.push_rel(subdir);
|
||||
need_dir(&buildpath);
|
||||
debug!("%s: %s -> %s", what, cf.to_str(), buildpath.to_str());
|
||||
|
|
@ -714,9 +714,9 @@ fn run_in_buildpath(what: &str, path: &Path, subdir: &Path, cf: &Path,
|
|||
cf.to_str()] + extra_flags);
|
||||
if p.status != 0 {
|
||||
error(fmt!("rustc failed: %d\n%s\n%s", p.status, p.err, p.out));
|
||||
return none;
|
||||
return None;
|
||||
}
|
||||
some(buildpath)
|
||||
Some(buildpath)
|
||||
}
|
||||
|
||||
fn test_one_crate(_c: cargo, path: &Path, cf: &Path) {
|
||||
|
|
@ -724,8 +724,8 @@ fn test_one_crate(_c: cargo, path: &Path, cf: &Path) {
|
|||
&Path("test"),
|
||||
cf,
|
||||
~[ ~"--test"]) {
|
||||
none => return,
|
||||
some(bp) => bp
|
||||
None => return,
|
||||
Some(bp) => bp
|
||||
};
|
||||
run_programs(&buildpath);
|
||||
}
|
||||
|
|
@ -734,8 +734,8 @@ fn install_one_crate(c: cargo, path: &Path, cf: &Path) {
|
|||
let buildpath = match run_in_buildpath(~"installing", path,
|
||||
&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();
|
||||
|
|
@ -762,12 +762,12 @@ fn install_one_crate(c: cargo, path: &Path, cf: &Path) {
|
|||
|
||||
fn rustc_sysroot() -> ~str {
|
||||
match os::self_exe_path() {
|
||||
some(path) => {
|
||||
Some(path) => {
|
||||
let rustc = path.push_many([~"..", ~"bin", ~"rustc"]);
|
||||
debug!(" rustc: %s", rustc.to_str());
|
||||
rustc.to_str()
|
||||
}
|
||||
none => ~"rustc"
|
||||
None => ~"rustc"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -777,7 +777,7 @@ fn install_source(c: cargo, path: &Path) {
|
|||
|
||||
let mut cratefiles = ~[];
|
||||
for os::walk_dir(&Path(".")) |p| {
|
||||
if p.filetype() == some(~"rc") {
|
||||
if p.filetype() == Some(~"rc") {
|
||||
vec::push(cratefiles, *p);
|
||||
}
|
||||
}
|
||||
|
|
@ -788,8 +788,8 @@ fn install_source(c: cargo, path: &Path) {
|
|||
|
||||
for cratefiles.each |cf| {
|
||||
match 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
|
||||
|
|
@ -810,7 +810,7 @@ fn install_source(c: cargo, path: &Path) {
|
|||
}
|
||||
}
|
||||
|
||||
fn install_git(c: cargo, wd: &Path, url: ~str, reference: option<~str>) {
|
||||
fn install_git(c: cargo, wd: &Path, url: ~str, reference: Option<~str>) {
|
||||
run::program_output(~"git", ~[~"clone", url, wd.to_str()]);
|
||||
if option::is_some(reference) {
|
||||
let r = option::get(reference);
|
||||
|
|
@ -919,7 +919,7 @@ fn install_named(c: cargo, wd: &Path, name: ~str) {
|
|||
|
||||
fn install_uuid_specific(c: cargo, wd: &Path, src: ~str, uuid: ~str) {
|
||||
match c.sources.find(src) {
|
||||
some(s) => {
|
||||
Some(s) => {
|
||||
let packages = copy s.packages;
|
||||
if vec::any(packages, |p| {
|
||||
if p.uuid == uuid {
|
||||
|
|
@ -935,7 +935,7 @@ fn install_uuid_specific(c: cargo, wd: &Path, src: ~str, uuid: ~str) {
|
|||
|
||||
fn install_named_specific(c: cargo, wd: &Path, src: ~str, name: ~str) {
|
||||
match c.sources.find(src) {
|
||||
some(s) => {
|
||||
Some(s) => {
|
||||
let packages = copy s.packages;
|
||||
if vec::any(packages, |p| {
|
||||
if p.name == name {
|
||||
|
|
@ -978,22 +978,22 @@ fn cmd_uninstall(c: cargo) {
|
|||
if is_uuid(target) {
|
||||
for os::list_dir(lib).each |file| {
|
||||
match str::find_str(file, ~"-" + target + ~"-") {
|
||||
some(_) => if !try_uninstall(&lib.push(file)) { return },
|
||||
none => ()
|
||||
Some(_) => if !try_uninstall(&lib.push(file)) { return },
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
error(~"can't find package with uuid: " + target);
|
||||
} else {
|
||||
for os::list_dir(lib).each |file| {
|
||||
match str::find_str(file, ~"lib" + target + ~"-") {
|
||||
some(_) => if !try_uninstall(&lib.push(file)) { return },
|
||||
none => ()
|
||||
Some(_) => if !try_uninstall(&lib.push(file)) { return },
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
for os::list_dir(bin).each |file| {
|
||||
match str::find_str(file, target) {
|
||||
some(_) => if !try_uninstall(&lib.push(file)) { return },
|
||||
none => ()
|
||||
Some(_) => if !try_uninstall(&lib.push(file)) { return },
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1003,12 +1003,12 @@ fn cmd_uninstall(c: cargo) {
|
|||
|
||||
fn install_query(c: cargo, wd: &Path, target: ~str) {
|
||||
match c.dep_cache.find(target) {
|
||||
some(inst) => {
|
||||
Some(inst) => {
|
||||
if inst {
|
||||
return;
|
||||
}
|
||||
}
|
||||
none => ()
|
||||
None => ()
|
||||
}
|
||||
|
||||
c.dep_cache.insert(target, true);
|
||||
|
|
@ -1018,9 +1018,9 @@ fn install_query(c: cargo, wd: &Path, target: ~str) {
|
|||
return;
|
||||
} else if is_git_url(target) {
|
||||
let reference = if c.opts.free.len() >= 4u {
|
||||
some(c.opts.free[3u])
|
||||
Some(c.opts.free[3u])
|
||||
} else {
|
||||
none
|
||||
None
|
||||
};
|
||||
install_git(c, wd, target, reference);
|
||||
} else if !valid_pkg_name(target) && has_archive_extension(target) {
|
||||
|
|
@ -1030,7 +1030,7 @@ fn install_query(c: cargo, wd: &Path, target: ~str) {
|
|||
let mut ps = copy target;
|
||||
|
||||
match 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) {
|
||||
|
|
@ -1039,7 +1039,7 @@ fn install_query(c: cargo, wd: &Path, target: ~str) {
|
|||
install_named_specific(c, wd, source, ps);
|
||||
}
|
||||
}
|
||||
option::none => {
|
||||
option::None => {
|
||||
if is_uuid(ps) {
|
||||
install_uuid(c, wd, ps);
|
||||
} else {
|
||||
|
|
@ -1063,8 +1063,8 @@ fn install_query(c: cargo, wd: &Path, target: ~str) {
|
|||
|
||||
fn get_temp_workdir(c: cargo) -> Path {
|
||||
match tempfile::mkdtemp(&c.workdir, "cargo") {
|
||||
some(wd) => wd,
|
||||
none => fail fmt!("needed temp dir: %s",
|
||||
Some(wd) => wd,
|
||||
None => fail fmt!("needed temp dir: %s",
|
||||
c.workdir.to_str())
|
||||
}
|
||||
}
|
||||
|
|
@ -1127,7 +1127,7 @@ fn sync_one_file(c: cargo, dir: &Path, src: source) -> bool {
|
|||
os::copy_file(&url.push("packages.json.sig"), &sigfile);
|
||||
|
||||
match copy src.key {
|
||||
some(u) => {
|
||||
Some(u) => {
|
||||
let p = run::program_output(~"curl",
|
||||
~[~"-f", ~"-s",
|
||||
~"-o", keyfile.to_str(), u]);
|
||||
|
|
@ -1140,7 +1140,7 @@ fn sync_one_file(c: cargo, dir: &Path, src: source) -> bool {
|
|||
_ => ()
|
||||
}
|
||||
match (src.key, src.keyfp) {
|
||||
(some(_), some(f)) => {
|
||||
(Some(_), Some(f)) => {
|
||||
let r = pgp::verify(&c.root, &pkgfile, &sigfile, f);
|
||||
|
||||
if !r {
|
||||
|
|
@ -1237,7 +1237,7 @@ fn sync_one_git(c: cargo, dir: &Path, src: source) -> bool {
|
|||
let has_src_file = os::path_exists(&srcfile);
|
||||
|
||||
match copy src.key {
|
||||
some(u) => {
|
||||
Some(u) => {
|
||||
let p = run::program_output(~"curl",
|
||||
~[~"-f", ~"-s",
|
||||
~"-o", keyfile.to_str(), u]);
|
||||
|
|
@ -1251,7 +1251,7 @@ fn sync_one_git(c: cargo, dir: &Path, src: source) -> bool {
|
|||
_ => ()
|
||||
}
|
||||
match (src.key, src.keyfp) {
|
||||
(some(_), some(f)) => {
|
||||
(Some(_), Some(f)) => {
|
||||
let r = pgp::verify(&c.root, &pkgfile, &sigfile, f);
|
||||
|
||||
if !r {
|
||||
|
|
@ -1320,7 +1320,7 @@ fn sync_one_curl(c: cargo, dir: &Path, src: source) -> bool {
|
|||
}
|
||||
|
||||
match copy src.key {
|
||||
some(u) => {
|
||||
Some(u) => {
|
||||
let p = run::program_output(~"curl",
|
||||
~[~"-f", ~"-s",
|
||||
~"-o", keyfile.to_str(), u]);
|
||||
|
|
@ -1333,7 +1333,7 @@ fn sync_one_curl(c: cargo, dir: &Path, src: source) -> bool {
|
|||
_ => ()
|
||||
}
|
||||
match (src.key, src.keyfp) {
|
||||
(some(_), some(f)) => {
|
||||
(Some(_), Some(f)) => {
|
||||
if smart {
|
||||
url = src.url + ~"/packages.json.sig";
|
||||
}
|
||||
|
|
@ -1498,10 +1498,10 @@ fn cmd_list(c: cargo) {
|
|||
error(fmt!("'%s' is an invalid source name", name));
|
||||
} else {
|
||||
match c.sources.find(name) {
|
||||
some(source) => {
|
||||
Some(source) => {
|
||||
print_source(source);
|
||||
}
|
||||
none => {
|
||||
None => {
|
||||
error(fmt!("no such source: %s", name));
|
||||
}
|
||||
}
|
||||
|
|
@ -1583,13 +1583,13 @@ fn dump_sources(c: cargo) {
|
|||
chash.insert(~"method", json::string(@v.method));
|
||||
|
||||
match copy v.key {
|
||||
some(key) => {
|
||||
Some(key) => {
|
||||
chash.insert(~"key", json::string(@key));
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
match copy v.keyfp {
|
||||
some(keyfp) => {
|
||||
Some(keyfp) => {
|
||||
chash.insert(~"keyfp", json::string(@keyfp));
|
||||
}
|
||||
_ => ()
|
||||
|
|
@ -1653,8 +1653,8 @@ fn cmd_sources(c: cargo) {
|
|||
name: name,
|
||||
mut url: url,
|
||||
mut method: assume_source_method(url),
|
||||
mut key: none,
|
||||
mut keyfp: none,
|
||||
mut key: None,
|
||||
mut keyfp: None,
|
||||
mut packages: ~[mut]
|
||||
});
|
||||
info(fmt!("added source: %s", name));
|
||||
|
|
@ -1695,7 +1695,7 @@ fn cmd_sources(c: cargo) {
|
|||
}
|
||||
|
||||
match c.sources.find(name) {
|
||||
some(source) => {
|
||||
Some(source) => {
|
||||
let old = copy source.url;
|
||||
let method = assume_source_method(url);
|
||||
|
||||
|
|
@ -1706,7 +1706,7 @@ fn cmd_sources(c: cargo) {
|
|||
|
||||
info(fmt!("changed source url: '%s' to '%s'", old, url));
|
||||
}
|
||||
none => {
|
||||
None => {
|
||||
error(fmt!("no such source: %s", name));
|
||||
}
|
||||
}
|
||||
|
|
@ -1726,7 +1726,7 @@ fn cmd_sources(c: cargo) {
|
|||
}
|
||||
|
||||
match c.sources.find(name) {
|
||||
some(source) => {
|
||||
Some(source) => {
|
||||
let old = copy source.method;
|
||||
|
||||
source.method = match method {
|
||||
|
|
@ -1740,7 +1740,7 @@ fn cmd_sources(c: cargo) {
|
|||
info(fmt!("changed source method: '%s' to '%s'", old,
|
||||
method));
|
||||
}
|
||||
none => {
|
||||
None => {
|
||||
error(fmt!("no such source: %s", name));
|
||||
}
|
||||
}
|
||||
|
|
@ -1764,12 +1764,12 @@ fn cmd_sources(c: cargo) {
|
|||
}
|
||||
|
||||
match 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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,17 +31,17 @@ type config = {
|
|||
run_ignored: bool,
|
||||
|
||||
// Only run tests that match this filter
|
||||
filter: option<~str>,
|
||||
filter: Option<~str>,
|
||||
|
||||
// Write out a parseable log of tests that were run
|
||||
logfile: option<Path>,
|
||||
logfile: Option<Path>,
|
||||
|
||||
// A command line to prefix program execution with,
|
||||
// for running under valgrind
|
||||
runtool: option<~str>,
|
||||
runtool: Option<~str>,
|
||||
|
||||
// Flags to pass to the compiler
|
||||
rustcflags: option<~str>,
|
||||
rustcflags: Option<~str>,
|
||||
|
||||
// Explain what's going on
|
||||
verbose: bool};
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ fn parse_config(args: ~[~str]) -> config {
|
|||
run_ignored: getopts::opt_present(matches, ~"ignored"),
|
||||
filter:
|
||||
if vec::len(matches.free) > 0u {
|
||||
option::some(matches.free[0])
|
||||
} else { option::none },
|
||||
option::Some(matches.free[0])
|
||||
} else { option::None },
|
||||
logfile: option::map(getopts::opt_maybe_str(matches,
|
||||
~"logfile"),
|
||||
|s| Path(s)),
|
||||
|
|
@ -85,12 +85,12 @@ fn log_config(config: config) {
|
|||
logv(c, fmt!("\n"));
|
||||
}
|
||||
|
||||
fn opt_str(maybestr: option<~str>) -> ~str {
|
||||
match maybestr { option::some(s) => s, option::none => ~"(none)" }
|
||||
fn opt_str(maybestr: Option<~str>) -> ~str {
|
||||
match maybestr { option::Some(s) => s, option::None => ~"(none)" }
|
||||
}
|
||||
|
||||
fn str_opt(maybestr: ~str) -> option<~str> {
|
||||
if maybestr != ~"(none)" { option::some(maybestr) } else { option::none }
|
||||
fn str_opt(maybestr: ~str) -> Option<~str> {
|
||||
if maybestr != ~"(none)" { option::Some(maybestr) } else { option::None }
|
||||
}
|
||||
|
||||
fn str_mode(s: ~str) -> mode {
|
||||
|
|
@ -122,14 +122,14 @@ fn run_tests(config: config) {
|
|||
fn test_opts(config: config) -> test::test_opts {
|
||||
{filter:
|
||||
match 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:
|
||||
match config.logfile {
|
||||
option::some(s) => option::some(s.to_str()),
|
||||
option::none => option::none
|
||||
option::Some(s) => option::Some(s.to_str()),
|
||||
option::None => option::None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ fn parse_expected(line_num: uint, line: ~str) -> ~[expected_error] unsafe {
|
|||
let error_tag = ~"//~";
|
||||
let mut idx;
|
||||
match 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
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ type test_props = {
|
|||
// Lines that should be expected, in order, on standard out
|
||||
error_patterns: ~[~str],
|
||||
// Extra flags to pass to the compiler
|
||||
compile_flags: option<~str>,
|
||||
compile_flags: Option<~str>,
|
||||
// If present, the name of a file that this test should match when
|
||||
// pretty-printed
|
||||
pp_exact: option<Path>,
|
||||
pp_exact: Option<Path>,
|
||||
// Modules from aux directory that should be compiled
|
||||
aux_builds: ~[~str],
|
||||
// Environment settings to use during execution
|
||||
|
|
@ -27,12 +27,12 @@ fn load_props(testfile: &Path) -> test_props {
|
|||
let mut error_patterns = ~[];
|
||||
let mut aux_builds = ~[];
|
||||
let mut exec_env = ~[];
|
||||
let mut compile_flags = option::none;
|
||||
let mut pp_exact = option::none;
|
||||
let mut compile_flags = option::None;
|
||||
let mut pp_exact = option::None;
|
||||
for iter_header(testfile) |ln| {
|
||||
match 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) {
|
||||
|
|
@ -91,19 +91,19 @@ fn iter_header(testfile: &Path, it: fn(~str) -> bool) -> bool {
|
|||
return true;
|
||||
}
|
||||
|
||||
fn parse_error_pattern(line: ~str) -> option<~str> {
|
||||
fn parse_error_pattern(line: ~str) -> Option<~str> {
|
||||
parse_name_value_directive(line, ~"error-pattern")
|
||||
}
|
||||
|
||||
fn parse_aux_build(line: ~str) -> option<~str> {
|
||||
fn parse_aux_build(line: ~str) -> Option<~str> {
|
||||
parse_name_value_directive(line, ~"aux-build")
|
||||
}
|
||||
|
||||
fn parse_compile_flags(line: ~str) -> option<~str> {
|
||||
fn parse_compile_flags(line: ~str) -> Option<~str> {
|
||||
parse_name_value_directive(line, ~"compile-flags")
|
||||
}
|
||||
|
||||
fn parse_exec_env(line: ~str) -> option<(~str, ~str)> {
|
||||
fn parse_exec_env(line: ~str) -> Option<(~str, ~str)> {
|
||||
do parse_name_value_directive(line, ~"exec-env").map |nv| {
|
||||
// nv is either FOO or FOO=BAR
|
||||
let strs = str::splitn_char(nv, '=', 1u);
|
||||
|
|
@ -115,14 +115,14 @@ fn parse_exec_env(line: ~str) -> option<(~str, ~str)> {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_pp_exact(line: ~str, testfile: &Path) -> option<Path> {
|
||||
fn parse_pp_exact(line: ~str, testfile: &Path) -> Option<Path> {
|
||||
match parse_name_value_directive(line, ~"pp-exact") {
|
||||
option::some(s) => option::some(Path(s)),
|
||||
option::none => {
|
||||
option::Some(s) => option::Some(Path(s)),
|
||||
option::None => {
|
||||
if parse_name_directive(line, ~"pp-exact") {
|
||||
option::some(testfile.file_path())
|
||||
option::Some(testfile.file_path())
|
||||
} else {
|
||||
option::none
|
||||
option::None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -133,15 +133,15 @@ fn parse_name_directive(line: ~str, directive: ~str) -> bool {
|
|||
}
|
||||
|
||||
fn parse_name_value_directive(line: ~str,
|
||||
directive: ~str) -> option<~str> unsafe {
|
||||
directive: ~str) -> Option<~str> unsafe {
|
||||
let keycolon = directive + ~":";
|
||||
match 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::Some(value)
|
||||
}
|
||||
option::none => option::none
|
||||
option::None => option::None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,14 +38,14 @@ fn run(lib_path: ~str,
|
|||
prog: ~str,
|
||||
args: ~[~str],
|
||||
env: ~[(~str, ~str)],
|
||||
input: option<~str>) -> {status: int, out: ~str, err: ~str} {
|
||||
input: Option<~str>) -> {status: int, out: ~str, err: ~str} {
|
||||
|
||||
let pipe_in = os::pipe();
|
||||
let pipe_out = os::pipe();
|
||||
let pipe_err = os::pipe();
|
||||
let pid = spawn_process(prog, args,
|
||||
&some(env + target_env(lib_path, prog)),
|
||||
&none, pipe_in.in, pipe_out.out, pipe_err.out);
|
||||
&Some(env + target_env(lib_path, prog)),
|
||||
&None, pipe_in.in, pipe_out.out, pipe_err.out);
|
||||
|
||||
os::close(pipe_in.in);
|
||||
os::close(pipe_out.out);
|
||||
|
|
@ -89,7 +89,7 @@ fn run(lib_path: ~str,
|
|||
return {status: status, out: outs, err: errs};
|
||||
}
|
||||
|
||||
fn writeclose(fd: c_int, s: option<~str>) {
|
||||
fn writeclose(fd: c_int, s: Option<~str>) {
|
||||
if option::is_some(s) {
|
||||
let writer = io::fd_writer(fd, false);
|
||||
writer.write_str(option::get(s));
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: &Path) {
|
|||
} else { logv(config, ~"testing for converging pretty-printing"); }
|
||||
|
||||
let rounds =
|
||||
match props.pp_exact { option::some(_) => 1, option::none => 2 };
|
||||
match props.pp_exact { option::Some(_) => 1, option::None => 2 };
|
||||
|
||||
let mut srcs = ~[result::get(io::read_whole_file_str(testfile))];
|
||||
|
||||
|
|
@ -111,11 +111,11 @@ fn run_pretty_test(config: config, props: test_props, testfile: &Path) {
|
|||
|
||||
let mut expected =
|
||||
match props.pp_exact {
|
||||
option::some(file) => {
|
||||
option::Some(file) => {
|
||||
let filepath = testfile.dir_path().push_rel(&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];
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: &Path) {
|
|||
|
||||
fn print_source(config: config, testfile: &Path, src: ~str) -> procres {
|
||||
compose_and_run(config, testfile, make_pp_args(config, testfile),
|
||||
~[], config.compile_lib_path, option::some(src))
|
||||
~[], config.compile_lib_path, option::Some(src))
|
||||
}
|
||||
|
||||
fn make_pp_args(config: config, _testfile: &Path) -> procargs {
|
||||
|
|
@ -173,7 +173,7 @@ actual:\n\
|
|||
compose_and_run_compiler(
|
||||
config, props, testfile,
|
||||
make_typecheck_args(config, testfile),
|
||||
option::some(src))
|
||||
option::Some(src))
|
||||
}
|
||||
|
||||
fn make_typecheck_args(config: config, testfile: &Path) -> procargs {
|
||||
|
|
@ -300,7 +300,7 @@ fn compile_test(config: config, props: test_props,
|
|||
config, props, testfile,
|
||||
make_compile_args(config, props, link_args,
|
||||
make_exe_name, testfile),
|
||||
none)
|
||||
None)
|
||||
}
|
||||
|
||||
fn exec_compiled_test(config: config, props: test_props,
|
||||
|
|
@ -308,7 +308,7 @@ fn exec_compiled_test(config: config, props: test_props,
|
|||
compose_and_run(config, testfile,
|
||||
make_run_args(config, props, testfile),
|
||||
props.exec_env,
|
||||
config.run_lib_path, option::none)
|
||||
config.run_lib_path, option::None)
|
||||
}
|
||||
|
||||
fn compose_and_run_compiler(
|
||||
|
|
@ -316,7 +316,7 @@ fn compose_and_run_compiler(
|
|||
props: test_props,
|
||||
testfile: &Path,
|
||||
args: procargs,
|
||||
input: option<~str>) -> procres {
|
||||
input: Option<~str>) -> procres {
|
||||
|
||||
if props.aux_builds.is_not_empty() {
|
||||
ensure_dir(&aux_output_dir_name(config, testfile));
|
||||
|
|
@ -331,7 +331,7 @@ fn compose_and_run_compiler(
|
|||
make_compile_args(config, props, ~[~"--lib"] + extra_link_args,
|
||||
|a,b| make_lib_name(a, b, testfile), &abs_ab);
|
||||
let auxres = compose_and_run(config, &abs_ab, aux_args, ~[],
|
||||
config.compile_lib_path, option::none);
|
||||
config.compile_lib_path, option::None);
|
||||
if auxres.status != 0 {
|
||||
fatal_procres(
|
||||
fmt!("auxiliary build of %s failed to compile: ",
|
||||
|
|
@ -355,7 +355,7 @@ fn compose_and_run(config: config, testfile: &Path,
|
|||
procargs: procargs,
|
||||
procenv: ~[(~str, ~str)],
|
||||
lib_path: ~str,
|
||||
input: option<~str>) -> procres {
|
||||
input: Option<~str>) -> procres {
|
||||
return program_output(config, testfile, lib_path,
|
||||
procargs.prog, procargs.args, procenv, input);
|
||||
}
|
||||
|
|
@ -391,8 +391,8 @@ fn make_run_args(config: config, _props: test_props, testfile: &Path) ->
|
|||
// then split apart its command
|
||||
let runtool =
|
||||
match 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)
|
||||
};
|
||||
|
|
@ -401,23 +401,23 @@ fn make_run_args(config: config, _props: test_props, testfile: &Path) ->
|
|||
return {prog: args[0], args: vec::slice(args, 1u, vec::len(args))};
|
||||
}
|
||||
|
||||
fn split_maybe_args(argstr: option<~str>) -> ~[~str] {
|
||||
fn split_maybe_args(argstr: Option<~str>) -> ~[~str] {
|
||||
fn rm_whitespace(v: ~[~str]) -> ~[~str] {
|
||||
fn flt(&&s: ~str) -> option<~str> {
|
||||
if !str::is_whitespace(s) { option::some(s) } else { option::none }
|
||||
fn flt(&&s: ~str) -> Option<~str> {
|
||||
if !str::is_whitespace(s) { option::Some(s) } else { option::None }
|
||||
}
|
||||
vec::filter_map(v, flt)
|
||||
}
|
||||
|
||||
match argstr {
|
||||
option::some(s) => rm_whitespace(str::split_char(s, ' ')),
|
||||
option::none => ~[]
|
||||
option::Some(s) => rm_whitespace(str::split_char(s, ' ')),
|
||||
option::None => ~[]
|
||||
}
|
||||
}
|
||||
|
||||
fn program_output(config: config, testfile: &Path, lib_path: ~str, prog: ~str,
|
||||
args: ~[~str], env: ~[(~str, ~str)],
|
||||
input: option<~str>) -> procres {
|
||||
input: Option<~str>) -> procres {
|
||||
let cmdline =
|
||||
{
|
||||
let cmdline = make_cmdline(lib_path, prog, args);
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ fn make_new_path(path: ~str) -> ~str {
|
|||
// Windows just uses PATH as the library search path, so we have to
|
||||
// maintain the current value while adding our own
|
||||
match 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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ fn contains(haystack: ~str, needle: ~str) -> bool {
|
|||
}
|
||||
|
||||
fn find_rust_files(files: &mut ~[Path], path: &Path) {
|
||||
if path.filetype() == some(~"rs") && !contains(path.to_str(), ~"utf8") {
|
||||
if path.filetype() == Some(~"rs") && !contains(path.to_str(), ~"utf8") {
|
||||
// ignoring "utf8" tests because something is broken
|
||||
vec::push(*files, *path);
|
||||
} else if os::path_is_dir(path)
|
||||
|
|
@ -41,12 +41,12 @@ fn common_exprs() -> ~[ast::expr] {
|
|||
{ node: l, span: ast_util::dummy_sp() }
|
||||
}
|
||||
|
||||
~[dse(ast::expr_break(option::none)),
|
||||
dse(ast::expr_again(option::none)),
|
||||
dse(ast::expr_fail(option::none)),
|
||||
dse(ast::expr_fail(option::some(
|
||||
~[dse(ast::expr_break(option::None)),
|
||||
dse(ast::expr_again(option::None)),
|
||||
dse(ast::expr_fail(option::None)),
|
||||
dse(ast::expr_fail(option::Some(
|
||||
@dse(ast::expr_lit(@dsl(ast::lit_str(@~"boo"))))))),
|
||||
dse(ast::expr_ret(option::none)),
|
||||
dse(ast::expr_ret(option::None)),
|
||||
dse(ast::expr_lit(@dsl(ast::lit_nil))),
|
||||
dse(ast::expr_lit(@dsl(ast::lit_bool(false)))),
|
||||
dse(ast::expr_lit(@dsl(ast::lit_bool(true)))),
|
||||
|
|
@ -76,11 +76,11 @@ pure fn safe_to_use_expr(e: ast::expr, tm: test_mode) -> bool {
|
|||
ast::expr_binary(*) | ast::expr_assign(*) |
|
||||
ast::expr_assign_op(*) => { false }
|
||||
|
||||
ast::expr_fail(option::none) |
|
||||
ast::expr_ret(option::none) => { false }
|
||||
ast::expr_fail(option::None) |
|
||||
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 }
|
||||
|
|
@ -259,7 +259,7 @@ fn check_variants_T<T: copy>(
|
|||
let crate2 = @replacer(crate, i, things[j], cx.mode);
|
||||
// It would be best to test the *crate* for stability, but
|
||||
// testing the string for stability is easier and ok for now.
|
||||
let handler = diagnostic::mk_handler(none);
|
||||
let handler = diagnostic::mk_handler(None);
|
||||
let str3 = do io::with_str_reader("") |rdr| {
|
||||
@as_str(|a|pprust::print_crate(
|
||||
codemap,
|
||||
|
|
@ -418,7 +418,7 @@ fn check_compiling(filename: &Path) -> happiness {
|
|||
|
||||
fn parse_and_print(code: @~str) -> ~str {
|
||||
let filename = Path("tmp.rs");
|
||||
let sess = parse::new_parse_sess(option::none);
|
||||
let sess = parse::new_parse_sess(option::None);
|
||||
write_file(&filename, *code);
|
||||
let crate = parse::parse_crate_from_source_str(
|
||||
filename.to_str(), code, ~[], sess);
|
||||
|
|
@ -570,7 +570,7 @@ fn check_variants(files: &[Path], cx: context) {
|
|||
}
|
||||
|
||||
log(error, ~"check_variants: " + file.to_str());
|
||||
let sess = parse::new_parse_sess(option::none);
|
||||
let sess = parse::new_parse_sess(option::None);
|
||||
let crate =
|
||||
parse::parse_crate_from_source_str(
|
||||
file.to_str(),
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ pure fn build<A>(builder: fn(push: pure fn(+A))) -> @[A] {
|
|||
* onto the vector being constructed.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn build_sized_opt<A>(size: option<uint>,
|
||||
pure fn build_sized_opt<A>(size: Option<uint>,
|
||||
builder: fn(push: pure fn(+A))) -> @[A] {
|
||||
build_sized(size.get_default(4), builder)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,13 +42,13 @@ pure fn is_true(v: bool) -> bool { v }
|
|||
pure fn is_false(v: bool) -> bool { !v }
|
||||
|
||||
/// Parse logic value from `s`
|
||||
pure fn from_str(s: &str) -> option<bool> {
|
||||
pure fn from_str(s: &str) -> Option<bool> {
|
||||
if s == "true" {
|
||||
some(true)
|
||||
Some(true)
|
||||
} else if s == "false" {
|
||||
some(false)
|
||||
Some(false)
|
||||
} else {
|
||||
none
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ pure fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }
|
|||
#[test]
|
||||
fn test_bool_from_str() {
|
||||
do all_values |v| {
|
||||
assert some(v) == from_str(bool::to_str(v))
|
||||
assert Some(v) == from_str(bool::to_str(v))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,15 +116,15 @@ pure fn is_digit(c: char) -> bool {
|
|||
* 'b' or 'B', 11, etc. Returns none if the char does not
|
||||
* refer to a digit in the given radix.
|
||||
*/
|
||||
pure fn to_digit(c: char, radix: uint) -> option<uint> {
|
||||
pure fn to_digit(c: char, radix: uint) -> Option<uint> {
|
||||
let val = match 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
|
||||
_ => return None
|
||||
};
|
||||
if val < radix { some(val) }
|
||||
else { none }
|
||||
if val < radix { Some(val) }
|
||||
else { None }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -219,19 +219,19 @@ fn test_is_whitespace() {
|
|||
|
||||
#[test]
|
||||
fn test_to_digit() {
|
||||
assert to_digit('0', 10u) == some(0u);
|
||||
assert to_digit('1', 2u) == some(1u);
|
||||
assert to_digit('2', 3u) == some(2u);
|
||||
assert to_digit('9', 10u) == some(9u);
|
||||
assert to_digit('a', 16u) == some(10u);
|
||||
assert to_digit('A', 16u) == some(10u);
|
||||
assert to_digit('b', 16u) == some(11u);
|
||||
assert to_digit('B', 16u) == some(11u);
|
||||
assert to_digit('z', 36u) == some(35u);
|
||||
assert to_digit('Z', 36u) == some(35u);
|
||||
assert to_digit('0', 10u) == Some(0u);
|
||||
assert to_digit('1', 2u) == Some(1u);
|
||||
assert to_digit('2', 3u) == Some(2u);
|
||||
assert to_digit('9', 10u) == Some(9u);
|
||||
assert to_digit('a', 16u) == Some(10u);
|
||||
assert to_digit('A', 16u) == Some(10u);
|
||||
assert to_digit('b', 16u) == Some(11u);
|
||||
assert to_digit('B', 16u) == Some(11u);
|
||||
assert to_digit('z', 36u) == Some(35u);
|
||||
assert to_digit('Z', 36u) == Some(35u);
|
||||
|
||||
assert to_digit(' ', 10u) == none;
|
||||
assert to_digit('$', 36u) == none;
|
||||
assert to_digit(' ', 10u) == None;
|
||||
assert to_digit('$', 36u) == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@
|
|||
|
||||
// Export various ubiquitous types, constructors, methods.
|
||||
|
||||
import option::{some, none};
|
||||
import option = option::option;
|
||||
import option::{Some, None};
|
||||
import Option = option::Option;
|
||||
// XXX: snapshot rustc is generating code that wants lower-case option
|
||||
#[cfg(stage0)]
|
||||
import option = option::Option;
|
||||
|
||||
import Path = path2::Path;
|
||||
import GenericPath = path2::GenericPath;
|
||||
|
|
@ -20,7 +23,7 @@ import ptr::Ptr;
|
|||
import to_str::ToStr;
|
||||
|
||||
export Path, WindowsPath, PosixPath, GenericPath;
|
||||
export option, some, none, unreachable;
|
||||
export Option, Some, None, unreachable;
|
||||
export extensions;
|
||||
// The following exports are the extension impls for numeric types
|
||||
export Num, Times, TimesIx;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
export DList, dlist, dlist_node;
|
||||
export new_dlist, from_elem, from_vec, extensions;
|
||||
|
||||
type DListLink<T> = option<DListNode<T>>;
|
||||
type DListLink<T> = Option<DListNode<T>>;
|
||||
|
||||
enum DListNode<T> = @{
|
||||
data: T,
|
||||
|
|
@ -29,49 +29,49 @@ enum DList<T> = @{
|
|||
priv impl<T> DListNode<T> {
|
||||
pure fn assert_links() {
|
||||
match self.next {
|
||||
some(neighbour) => match neighbour.prev {
|
||||
some(me) => if !box::ptr_eq(*self, *me) {
|
||||
Some(neighbour) => match 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 => fail ~"One-way next-link in dlist node."
|
||||
},
|
||||
none => ()
|
||||
None => ()
|
||||
}
|
||||
match self.prev {
|
||||
some(neighbour) => match neighbour.next {
|
||||
some(me) => if !box::ptr_eq(*me, *self) {
|
||||
Some(neighbour) => match 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 => fail ~"One-way prev-link in dlist node."
|
||||
},
|
||||
none => ()
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DListNode<T> {
|
||||
/// Get the next node in the list, if there is one.
|
||||
pure fn next_link() -> option<DListNode<T>> {
|
||||
pure fn next_link() -> Option<DListNode<T>> {
|
||||
self.assert_links();
|
||||
self.next
|
||||
}
|
||||
/// Get the next node in the list, failing if there isn't one.
|
||||
pure fn next_node() -> DListNode<T> {
|
||||
match 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.
|
||||
pure fn prev_link() -> option<DListNode<T>> {
|
||||
pure fn prev_link() -> Option<DListNode<T>> {
|
||||
self.assert_links();
|
||||
self.prev
|
||||
}
|
||||
/// Get the previous node in the list, failing if there isn't one.
|
||||
pure fn prev_node() -> DListNode<T> {
|
||||
match 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."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -79,12 +79,12 @@ impl<T> DListNode<T> {
|
|||
/// Creates a new dlist node with the given data.
|
||||
pure fn new_dlist_node<T>(+data: T) -> DListNode<T> {
|
||||
DListNode(@{data: data, mut linked: false,
|
||||
mut prev: none, mut next: none})
|
||||
mut prev: None, mut next: None})
|
||||
}
|
||||
|
||||
/// Creates a new, empty dlist.
|
||||
pure fn new_dlist<T>() -> DList<T> {
|
||||
DList(@{mut size: 0, mut hd: none, mut tl: none})
|
||||
DList(@{mut size: 0, mut hd: None, mut tl: None})
|
||||
}
|
||||
|
||||
/// Creates a new dlist with a single element
|
||||
|
|
@ -113,8 +113,8 @@ fn concat<T>(lists: DList<DList<T>>) -> DList<T> {
|
|||
|
||||
priv impl<T> DList<T> {
|
||||
pure fn new_link(-data: T) -> DListLink<T> {
|
||||
some(DListNode(@{data: data, mut linked: true,
|
||||
mut prev: none, mut next: none}))
|
||||
Some(DListNode(@{data: data, mut linked: true,
|
||||
mut prev: None, mut next: None}))
|
||||
}
|
||||
pure fn assert_mine(nobe: DListNode<T>) {
|
||||
// These asserts could be stronger if we had node-root back-pointers,
|
||||
|
|
@ -141,12 +141,12 @@ priv impl<T> DList<T> {
|
|||
#[inline(always)]
|
||||
fn link(+before: DListLink<T>, +after: DListLink<T>) {
|
||||
match before {
|
||||
some(neighbour) => neighbour.next = after,
|
||||
none => self.hd = after
|
||||
Some(neighbour) => neighbour.next = after,
|
||||
None => self.hd = after
|
||||
}
|
||||
match 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.
|
||||
|
|
@ -154,8 +154,8 @@ priv impl<T> DList<T> {
|
|||
self.assert_mine(nobe);
|
||||
assert self.size > 0;
|
||||
self.link(nobe.prev, nobe.next);
|
||||
nobe.prev = none; // Release extraneous references.
|
||||
nobe.next = none;
|
||||
nobe.prev = None; // Release extraneous references.
|
||||
nobe.next = None;
|
||||
nobe.linked = false;
|
||||
self.size -= 1;
|
||||
}
|
||||
|
|
@ -174,14 +174,14 @@ priv impl<T> DList<T> {
|
|||
self.assert_mine(neighbour);
|
||||
assert self.size > 0;
|
||||
self.link(neighbour.prev, nobe);
|
||||
self.link(nobe, some(neighbour));
|
||||
self.link(nobe, Some(neighbour));
|
||||
self.size += 1;
|
||||
}
|
||||
fn insert_right(neighbour: DListNode<T>, nobe: DListLink<T>) {
|
||||
self.assert_mine(neighbour);
|
||||
assert self.size > 0;
|
||||
self.link(nobe, neighbour.next);
|
||||
self.link(some(neighbour), nobe);
|
||||
self.link(Some(neighbour), nobe);
|
||||
self.size += 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -233,7 +233,7 @@ impl<T> DList<T> {
|
|||
*/
|
||||
fn insert_n_before(nobe: DListNode<T>, neighbour: DListNode<T>) {
|
||||
self.make_mine(nobe);
|
||||
self.insert_left(some(nobe), neighbour);
|
||||
self.insert_left(Some(nobe), neighbour);
|
||||
}
|
||||
/**
|
||||
* Insert data in the middle of the list, left of the given node,
|
||||
|
|
@ -257,7 +257,7 @@ impl<T> DList<T> {
|
|||
*/
|
||||
fn insert_n_after(nobe: DListNode<T>, neighbour: DListNode<T>) {
|
||||
self.make_mine(nobe);
|
||||
self.insert_right(neighbour, some(nobe));
|
||||
self.insert_right(neighbour, Some(nobe));
|
||||
}
|
||||
/**
|
||||
* Insert data in the middle of the list, right of the given node,
|
||||
|
|
@ -270,34 +270,34 @@ impl<T> DList<T> {
|
|||
}
|
||||
|
||||
/// Remove a node from the head of the list. O(1).
|
||||
fn pop_n() -> option<DListNode<T>> {
|
||||
fn pop_n() -> Option<DListNode<T>> {
|
||||
let hd = self.peek_n();
|
||||
hd.map(|nobe| self.unlink(nobe));
|
||||
hd
|
||||
}
|
||||
/// Remove a node from the tail of the list. O(1).
|
||||
fn pop_tail_n() -> option<DListNode<T>> {
|
||||
fn pop_tail_n() -> Option<DListNode<T>> {
|
||||
let tl = self.peek_tail_n();
|
||||
tl.map(|nobe| self.unlink(nobe));
|
||||
tl
|
||||
}
|
||||
/// Get the node at the list's head. O(1).
|
||||
pure fn peek_n() -> option<DListNode<T>> { self.hd }
|
||||
pure fn peek_n() -> Option<DListNode<T>> { self.hd }
|
||||
/// Get the node at the list's tail. O(1).
|
||||
pure fn peek_tail_n() -> option<DListNode<T>> { self.tl }
|
||||
pure fn peek_tail_n() -> Option<DListNode<T>> { self.tl }
|
||||
|
||||
/// Get the node at the list's head, failing if empty. O(1).
|
||||
pure fn head_n() -> DListNode<T> {
|
||||
match 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() -> DListNode<T> {
|
||||
match 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."
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -317,8 +317,8 @@ impl<T> DList<T> {
|
|||
self.tl = them.tl;
|
||||
self.size += them.size;
|
||||
them.size = 0;
|
||||
them.hd = none;
|
||||
them.tl = none;
|
||||
them.hd = None;
|
||||
them.tl = None;
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
|
@ -334,8 +334,8 @@ impl<T> DList<T> {
|
|||
self.hd = them.hd;
|
||||
self.size += them.size;
|
||||
them.size = 0;
|
||||
them.hd = none;
|
||||
them.tl = none;
|
||||
them.hd = None;
|
||||
them.tl = None;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -345,7 +345,7 @@ impl<T> DList<T> {
|
|||
let next_nobe = nobe.next;
|
||||
self.remove(nobe);
|
||||
self.make_mine(nobe);
|
||||
self.add_head(some(nobe));
|
||||
self.add_head(Some(nobe));
|
||||
next_nobe
|
||||
}
|
||||
}
|
||||
|
|
@ -417,13 +417,13 @@ impl<T> DList<T> {
|
|||
|
||||
impl<T: copy> DList<T> {
|
||||
/// Remove data from the head of the list. O(1).
|
||||
fn pop() -> option<T> { self.pop_n().map (|nobe| nobe.data) }
|
||||
fn pop() -> Option<T> { self.pop_n().map (|nobe| nobe.data) }
|
||||
/// Remove data from the tail of the list. O(1).
|
||||
fn pop_tail() -> option<T> { self.pop_tail_n().map (|nobe| nobe.data) }
|
||||
fn pop_tail() -> Option<T> { self.pop_tail_n().map (|nobe| nobe.data) }
|
||||
/// Get data at the list's head. O(1).
|
||||
pure fn peek() -> option<T> { self.peek_n().map (|nobe| nobe.data) }
|
||||
pure fn peek() -> Option<T> { self.peek_n().map (|nobe| nobe.data) }
|
||||
/// Get data at the list's tail. O(1).
|
||||
pure fn peek_tail() -> option<T> {
|
||||
pure fn peek_tail() -> Option<T> {
|
||||
self.peek_tail_n().map (|nobe| nobe.data)
|
||||
}
|
||||
/// Get data at the list's head, failing if empty. O(1).
|
||||
|
|
@ -777,7 +777,7 @@ mod tests {
|
|||
l.assert_consistent(); l.remove(two);
|
||||
l.assert_consistent(); l.remove(three);
|
||||
l.assert_consistent(); l.remove(one); // Twenty-three is number one!
|
||||
l.assert_consistent(); assert l.peek() == none;
|
||||
l.assert_consistent(); assert l.peek() == None;
|
||||
l.assert_consistent(); assert l.is_empty();
|
||||
}
|
||||
#[test]
|
||||
|
|
@ -847,7 +847,7 @@ mod tests {
|
|||
let l = new_dlist::<int>();
|
||||
let _one = l.push_n(1);
|
||||
let two = l.push_n(2);
|
||||
two.prev = none;
|
||||
two.prev = None;
|
||||
l.assert_consistent();
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
|
|
@ -856,8 +856,8 @@ mod tests {
|
|||
let one = l.push_n(1);
|
||||
let _two = l.push_n(2);
|
||||
let three = l.push_n(3);
|
||||
three.next = some(one);
|
||||
one.prev = some(three);
|
||||
three.next = Some(one);
|
||||
one.prev = Some(three);
|
||||
l.assert_consistent();
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ export unwrap;
|
|||
*
|
||||
* The reason that I did not use an unsafe pointer in the structure
|
||||
* itself is that I wanted to ensure that the vector would be freed when
|
||||
* the dvec is dropped. The reason that I did not use an `option<T>`
|
||||
* the dvec is dropped. The reason that I did not use an `Option<T>`
|
||||
* instead of a nullable pointer is that I found experimentally that it
|
||||
* becomes approximately 50% slower. This can probably be improved
|
||||
* through optimization. You can run your own experiments using
|
||||
|
|
@ -247,7 +247,7 @@ impl<A: copy> DVec<A> {
|
|||
do self.swap |v| {
|
||||
let mut v = match ts.size_hint() {
|
||||
none { v }
|
||||
some(h) {
|
||||
Some(h) {
|
||||
let len = v.len() + h;
|
||||
let mut v <- v;
|
||||
vec::reserve(v, len);
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ debug!("hello, %s!", "world");
|
|||
|
||||
*/
|
||||
|
||||
import option::{some, none};
|
||||
import option::{Some, None};
|
||||
|
||||
|
||||
/*
|
||||
|
|
@ -70,7 +70,7 @@ mod ct {
|
|||
|
||||
// A formatted conversion from an expression to a string
|
||||
type conv =
|
||||
{param: option<int>,
|
||||
{param: Option<int>,
|
||||
flags: ~[flag],
|
||||
width: count,
|
||||
precision: count,
|
||||
|
|
@ -117,25 +117,25 @@ mod ct {
|
|||
return pieces;
|
||||
}
|
||||
fn peek_num(s: ~str, i: uint, lim: uint) ->
|
||||
option<{num: uint, next: uint}> {
|
||||
Option<{num: uint, next: uint}> {
|
||||
let mut j = i;
|
||||
let mut accum = 0u;
|
||||
let mut found = false;
|
||||
while j < lim {
|
||||
match char::to_digit(s[j] as char, 10) {
|
||||
some(x) => {
|
||||
Some(x) => {
|
||||
found = true;
|
||||
accum *= 10;
|
||||
accum += x;
|
||||
j += 1;
|
||||
},
|
||||
none => break
|
||||
None => break
|
||||
}
|
||||
}
|
||||
if found {
|
||||
some({num: accum, next: j})
|
||||
Some({num: accum, next: j})
|
||||
} else {
|
||||
none
|
||||
None
|
||||
}
|
||||
}
|
||||
fn parse_conversion(s: ~str, i: uint, lim: uint, error: error_fn) ->
|
||||
|
|
@ -154,17 +154,17 @@ mod ct {
|
|||
next: ty.next};
|
||||
}
|
||||
fn parse_parameter(s: ~str, i: uint, lim: uint) ->
|
||||
{param: option<int>, next: uint} {
|
||||
if i >= lim { return {param: none, next: i}; }
|
||||
{param: Option<int>, next: uint} {
|
||||
if i >= lim { return {param: None, next: i}; }
|
||||
let num = peek_num(s, i, lim);
|
||||
return match 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 {
|
||||
{param: some(n as int), next: j + 1u}
|
||||
} else { {param: none, next: i} }
|
||||
{param: Some(n as int), next: j + 1u}
|
||||
} else { {param: None, next: i} }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -203,14 +203,14 @@ mod ct {
|
|||
let param = parse_parameter(s, i + 1u, lim);
|
||||
let j = param.next;
|
||||
match 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);
|
||||
match num {
|
||||
none => {count: count_implied, next: i},
|
||||
some(num) => {
|
||||
None => {count: count_implied, next: i},
|
||||
Some(num) => {
|
||||
count: count_is(num.num as int),
|
||||
next: num.next
|
||||
}
|
||||
|
|
|
|||
|
|
@ -241,29 +241,29 @@ fn to_str(num: float, digits: uint) -> ~str {
|
|||
* # Return value
|
||||
*
|
||||
* `none` if the string did not represent a valid number. Otherwise,
|
||||
* `some(n)` where `n` is the floating-point number represented by `[num]`.
|
||||
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
|
||||
*/
|
||||
fn from_str(num: &str) -> option<float> {
|
||||
fn from_str(num: &str) -> Option<float> {
|
||||
if num == "inf" {
|
||||
return some(infinity as float);
|
||||
return Some(infinity as float);
|
||||
} else if num == "-inf" {
|
||||
return some(neg_infinity as float);
|
||||
return Some(neg_infinity as float);
|
||||
} else if num == "NaN" {
|
||||
return some(NaN as float);
|
||||
return Some(NaN as float);
|
||||
}
|
||||
|
||||
let mut pos = 0u; //Current byte position in the string.
|
||||
//Used to walk the string in O(n).
|
||||
let len = str::len(num); //Length of the string, in bytes.
|
||||
|
||||
if len == 0u { return none; }
|
||||
if len == 0u { return None; }
|
||||
let mut total = 0f; //Accumulated result
|
||||
let mut c = 'z'; //Latest char.
|
||||
|
||||
//The string must start with one of the following characters.
|
||||
match str::char_at(num, 0u) {
|
||||
'-' | '+' | '0' to '9' | '.' => (),
|
||||
_ => return none
|
||||
_ => return None
|
||||
}
|
||||
|
||||
//Determine if first char is '-'/'+'. Set [pos] and [neg] accordingly.
|
||||
|
|
@ -290,7 +290,7 @@ fn from_str(num: &str) -> option<float> {
|
|||
total += ((c as int) - ('0' as int)) as float;
|
||||
}
|
||||
'.' | 'e' | 'E' => break,
|
||||
_ => return none
|
||||
_ => return None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -306,7 +306,7 @@ fn from_str(num: &str) -> option<float> {
|
|||
total += (((c as int) - ('0' as int)) as float)*decimal;
|
||||
}
|
||||
'e' | 'E' => break,
|
||||
_ => return none
|
||||
_ => return None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -348,17 +348,17 @@ fn from_str(num: &str) -> option<float> {
|
|||
total = total * multiplier;
|
||||
}
|
||||
} else {
|
||||
return none;
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
if(pos < len) {
|
||||
return none;
|
||||
return None;
|
||||
} else {
|
||||
if(neg) {
|
||||
total *= -1f;
|
||||
}
|
||||
return some(total);
|
||||
return Some(total);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -428,45 +428,45 @@ impl float: num::Num {
|
|||
|
||||
#[test]
|
||||
fn test_from_str() {
|
||||
assert from_str(~"3") == some(3.);
|
||||
assert from_str(~"3") == some(3.);
|
||||
assert from_str(~"3.14") == some(3.14);
|
||||
assert from_str(~"+3.14") == some(3.14);
|
||||
assert from_str(~"-3.14") == some(-3.14);
|
||||
assert from_str(~"2.5E10") == some(25000000000.);
|
||||
assert from_str(~"2.5e10") == some(25000000000.);
|
||||
assert from_str(~"25000000000.E-10") == some(2.5);
|
||||
assert from_str(~".") == some(0.);
|
||||
assert from_str(~".e1") == some(0.);
|
||||
assert from_str(~".e-1") == some(0.);
|
||||
assert from_str(~"5.") == some(5.);
|
||||
assert from_str(~".5") == some(0.5);
|
||||
assert from_str(~"0.5") == some(0.5);
|
||||
assert from_str(~"0.5") == some(0.5);
|
||||
assert from_str(~"0.5") == some(0.5);
|
||||
assert from_str(~"-.5") == some(-0.5);
|
||||
assert from_str(~"-.5") == some(-0.5);
|
||||
assert from_str(~"-5") == some(-5.);
|
||||
assert from_str(~"-0") == some(-0.);
|
||||
assert from_str(~"0") == some(0.);
|
||||
assert from_str(~"inf") == some(infinity);
|
||||
assert from_str(~"-inf") == some(neg_infinity);
|
||||
assert from_str(~"3") == Some(3.);
|
||||
assert from_str(~"3") == Some(3.);
|
||||
assert from_str(~"3.14") == Some(3.14);
|
||||
assert from_str(~"+3.14") == Some(3.14);
|
||||
assert from_str(~"-3.14") == Some(-3.14);
|
||||
assert from_str(~"2.5E10") == Some(25000000000.);
|
||||
assert from_str(~"2.5e10") == Some(25000000000.);
|
||||
assert from_str(~"25000000000.E-10") == Some(2.5);
|
||||
assert from_str(~".") == Some(0.);
|
||||
assert from_str(~".e1") == Some(0.);
|
||||
assert from_str(~".e-1") == Some(0.);
|
||||
assert from_str(~"5.") == Some(5.);
|
||||
assert from_str(~".5") == Some(0.5);
|
||||
assert from_str(~"0.5") == Some(0.5);
|
||||
assert from_str(~"0.5") == Some(0.5);
|
||||
assert from_str(~"0.5") == Some(0.5);
|
||||
assert from_str(~"-.5") == Some(-0.5);
|
||||
assert from_str(~"-.5") == Some(-0.5);
|
||||
assert from_str(~"-5") == Some(-5.);
|
||||
assert from_str(~"-0") == Some(-0.);
|
||||
assert from_str(~"0") == Some(0.);
|
||||
assert from_str(~"inf") == Some(infinity);
|
||||
assert from_str(~"-inf") == Some(neg_infinity);
|
||||
// note: NaN != NaN, hence this slightly complex test
|
||||
match from_str(~"NaN") {
|
||||
some(f) => assert is_NaN(f),
|
||||
none => fail
|
||||
Some(f) => assert is_NaN(f),
|
||||
None => fail
|
||||
}
|
||||
|
||||
assert from_str(~"") == none;
|
||||
assert from_str(~"x") == none;
|
||||
assert from_str(~" ") == none;
|
||||
assert from_str(~" ") == none;
|
||||
assert from_str(~"e") == none;
|
||||
assert from_str(~"E") == none;
|
||||
assert from_str(~"E1") == none;
|
||||
assert from_str(~"1e1e1") == none;
|
||||
assert from_str(~"1e1.1") == none;
|
||||
assert from_str(~"1e1-1") == none;
|
||||
assert from_str(~"") == None;
|
||||
assert from_str(~"x") == None;
|
||||
assert from_str(~" ") == None;
|
||||
assert from_str(~" ") == None;
|
||||
assert from_str(~"e") == None;
|
||||
assert from_str(~"E") == None;
|
||||
assert from_str(~"E1") == None;
|
||||
assert from_str(~"1e1e1") == None;
|
||||
assert from_str(~"1e1.1") == None;
|
||||
assert from_str(~"1e1-1") == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -72,9 +72,9 @@ fn from_port<A:send>(+port: future_pipe::client::waiting<A>) -> Future<A> {
|
|||
* waiting for the result to be received on the port.
|
||||
*/
|
||||
|
||||
let port = ~mut some(port);
|
||||
let port = ~mut Some(port);
|
||||
do from_fn |move port| {
|
||||
let mut port_ = none;
|
||||
let mut port_ = None;
|
||||
port_ <-> *port;
|
||||
let port = option::unwrap(port_);
|
||||
match recv(port) {
|
||||
|
|
|
|||
|
|
@ -133,8 +133,8 @@ impl T: iter::TimesIx {
|
|||
* * buf - A byte buffer
|
||||
* * radix - The base of the number
|
||||
*/
|
||||
fn parse_buf(buf: ~[u8], radix: uint) -> option<T> {
|
||||
if vec::len(buf) == 0u { return none; }
|
||||
fn parse_buf(buf: ~[u8], radix: uint) -> Option<T> {
|
||||
if vec::len(buf) == 0u { return None; }
|
||||
let mut i = vec::len(buf) - 1u;
|
||||
let mut start = 0u;
|
||||
let mut power = 1 as T;
|
||||
|
|
@ -146,17 +146,17 @@ fn parse_buf(buf: ~[u8], radix: uint) -> option<T> {
|
|||
let mut n = 0 as T;
|
||||
loop {
|
||||
match 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); }
|
||||
if i <= start { return Some(n); }
|
||||
i -= 1u;
|
||||
};
|
||||
}
|
||||
|
||||
/// Parse a string to an int
|
||||
fn from_str(s: ~str) -> option<T> { parse_buf(str::to_bytes(s), 10u) }
|
||||
fn from_str(s: ~str) -> Option<T> { parse_buf(str::to_bytes(s), 10u) }
|
||||
|
||||
/// Convert to a string in a given base
|
||||
fn to_str(n: T, radix: uint) -> ~str {
|
||||
|
|
@ -182,20 +182,20 @@ fn str(i: T) -> ~str { return to_str(i, 10u); }
|
|||
#[test]
|
||||
#[ignore]
|
||||
fn test_from_str() {
|
||||
assert from_str(~"0") == some(0 as T);
|
||||
assert from_str(~"3") == some(3 as T);
|
||||
assert from_str(~"10") == some(10 as T);
|
||||
assert from_str(~"123456789") == some(123456789 as T);
|
||||
assert from_str(~"00100") == some(100 as T);
|
||||
assert from_str(~"0") == Some(0 as T);
|
||||
assert from_str(~"3") == Some(3 as T);
|
||||
assert from_str(~"10") == Some(10 as T);
|
||||
assert from_str(~"123456789") == Some(123456789 as T);
|
||||
assert from_str(~"00100") == Some(100 as T);
|
||||
|
||||
assert from_str(~"-1") == some(-1 as T);
|
||||
assert from_str(~"-3") == some(-3 as T);
|
||||
assert from_str(~"-10") == some(-10 as T);
|
||||
assert from_str(~"-123456789") == some(-123456789 as T);
|
||||
assert from_str(~"-00100") == some(-100 as T);
|
||||
assert from_str(~"-1") == Some(-1 as T);
|
||||
assert from_str(~"-3") == Some(-3 as T);
|
||||
assert from_str(~"-10") == Some(-10 as T);
|
||||
assert from_str(~"-123456789") == Some(-123456789 as T);
|
||||
assert from_str(~"-00100") == Some(-100 as T);
|
||||
|
||||
assert from_str(~" ") == none;
|
||||
assert from_str(~"x") == none;
|
||||
assert from_str(~" ") == None;
|
||||
assert from_str(~"x") == None;
|
||||
}
|
||||
|
||||
// FIXME: Has alignment issues on windows and 32-bit linux (#2609)
|
||||
|
|
@ -203,26 +203,26 @@ fn test_from_str() {
|
|||
#[ignore]
|
||||
fn test_parse_buf() {
|
||||
import str::to_bytes;
|
||||
assert parse_buf(to_bytes(~"123"), 10u) == some(123 as T);
|
||||
assert parse_buf(to_bytes(~"1001"), 2u) == some(9 as T);
|
||||
assert parse_buf(to_bytes(~"123"), 8u) == some(83 as T);
|
||||
assert parse_buf(to_bytes(~"123"), 16u) == some(291 as T);
|
||||
assert parse_buf(to_bytes(~"ffff"), 16u) == some(65535 as T);
|
||||
assert parse_buf(to_bytes(~"FFFF"), 16u) == some(65535 as T);
|
||||
assert parse_buf(to_bytes(~"z"), 36u) == some(35 as T);
|
||||
assert parse_buf(to_bytes(~"Z"), 36u) == some(35 as T);
|
||||
assert parse_buf(to_bytes(~"123"), 10u) == Some(123 as T);
|
||||
assert parse_buf(to_bytes(~"1001"), 2u) == Some(9 as T);
|
||||
assert parse_buf(to_bytes(~"123"), 8u) == Some(83 as T);
|
||||
assert parse_buf(to_bytes(~"123"), 16u) == Some(291 as T);
|
||||
assert parse_buf(to_bytes(~"ffff"), 16u) == Some(65535 as T);
|
||||
assert parse_buf(to_bytes(~"FFFF"), 16u) == Some(65535 as T);
|
||||
assert parse_buf(to_bytes(~"z"), 36u) == Some(35 as T);
|
||||
assert parse_buf(to_bytes(~"Z"), 36u) == Some(35 as T);
|
||||
|
||||
assert parse_buf(to_bytes(~"-123"), 10u) == some(-123 as T);
|
||||
assert parse_buf(to_bytes(~"-1001"), 2u) == some(-9 as T);
|
||||
assert parse_buf(to_bytes(~"-123"), 8u) == some(-83 as T);
|
||||
assert parse_buf(to_bytes(~"-123"), 16u) == some(-291 as T);
|
||||
assert parse_buf(to_bytes(~"-ffff"), 16u) == some(-65535 as T);
|
||||
assert parse_buf(to_bytes(~"-FFFF"), 16u) == some(-65535 as T);
|
||||
assert parse_buf(to_bytes(~"-z"), 36u) == some(-35 as T);
|
||||
assert parse_buf(to_bytes(~"-Z"), 36u) == some(-35 as T);
|
||||
assert parse_buf(to_bytes(~"-123"), 10u) == Some(-123 as T);
|
||||
assert parse_buf(to_bytes(~"-1001"), 2u) == Some(-9 as T);
|
||||
assert parse_buf(to_bytes(~"-123"), 8u) == Some(-83 as T);
|
||||
assert parse_buf(to_bytes(~"-123"), 16u) == Some(-291 as T);
|
||||
assert parse_buf(to_bytes(~"-ffff"), 16u) == Some(-65535 as T);
|
||||
assert parse_buf(to_bytes(~"-FFFF"), 16u) == Some(-65535 as T);
|
||||
assert parse_buf(to_bytes(~"-z"), 36u) == Some(-35 as T);
|
||||
assert parse_buf(to_bytes(~"-Z"), 36u) == Some(-35 as T);
|
||||
|
||||
assert parse_buf(to_bytes(~"Z"), 35u) == none;
|
||||
assert parse_buf(to_bytes(~"-9"), 2u) == none;
|
||||
assert parse_buf(to_bytes(~"Z"), 35u) == None;
|
||||
assert parse_buf(to_bytes(~"-9"), 2u) == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -761,8 +761,8 @@ mod fsync {
|
|||
new(-arg: Arg<t>) { self.arg <- arg; }
|
||||
drop {
|
||||
match 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);
|
||||
}
|
||||
|
|
@ -772,14 +772,14 @@ mod fsync {
|
|||
|
||||
type Arg<t> = {
|
||||
val: t,
|
||||
opt_level: option<Level>,
|
||||
opt_level: Option<Level>,
|
||||
fsync_fn: fn@(t, Level) -> int
|
||||
};
|
||||
|
||||
// fsync file after executing blk
|
||||
// FIXME (#2004) find better way to create resources within lifetime of
|
||||
// outer res
|
||||
fn FILE_res_sync(&&file: FILERes, opt_level: option<Level>,
|
||||
fn FILE_res_sync(&&file: FILERes, opt_level: Option<Level>,
|
||||
blk: fn(&&Res<*libc::FILE>)) {
|
||||
blk(Res({
|
||||
val: file.f, opt_level: opt_level,
|
||||
|
|
@ -790,7 +790,7 @@ mod fsync {
|
|||
}
|
||||
|
||||
// fsync fd after executing blk
|
||||
fn fd_res_sync(&&fd: FdRes, opt_level: option<Level>,
|
||||
fn fd_res_sync(&&fd: FdRes, opt_level: Option<Level>,
|
||||
blk: fn(&&Res<fd_t>)) {
|
||||
blk(Res({
|
||||
val: fd.fd, opt_level: opt_level,
|
||||
|
|
@ -804,7 +804,7 @@ mod fsync {
|
|||
trait FSyncable { fn fsync(l: Level) -> int; }
|
||||
|
||||
// Call o.fsync after executing blk
|
||||
fn obj_sync(&&o: FSyncable, opt_level: option<Level>,
|
||||
fn obj_sync(&&o: FSyncable, opt_level: Option<Level>,
|
||||
blk: fn(&&Res<FSyncable>)) {
|
||||
blk(Res({
|
||||
val: o, opt_level: opt_level,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ export extensions;
|
|||
|
||||
impl<A> IMPL_T<A>: iter::BaseIter<A> {
|
||||
pure fn each(blk: fn(A) -> bool) { EACH(self, blk) }
|
||||
pure fn size_hint() -> option<uint> { SIZE_HINT(self) }
|
||||
pure fn size_hint() -> Option<uint> { SIZE_HINT(self) }
|
||||
}
|
||||
|
||||
impl<A> IMPL_T<A>: iter::ExtendedIter<A> {
|
||||
|
|
@ -19,7 +19,7 @@ impl<A> IMPL_T<A>: iter::ExtendedIter<A> {
|
|||
}
|
||||
pure fn contains(x: A) -> bool { iter::contains(self, x) }
|
||||
pure fn count(x: A) -> uint { iter::count(self, x) }
|
||||
pure fn position(f: fn(A) -> bool) -> option<uint> {
|
||||
pure fn position(f: fn(A) -> bool) -> Option<uint> {
|
||||
iter::position(self, f)
|
||||
}
|
||||
}
|
||||
|
|
@ -40,5 +40,5 @@ impl<A: copy> IMPL_T<A>: iter::CopyableIter<A> {
|
|||
|
||||
pure fn min() -> A { iter::min(self) }
|
||||
pure fn max() -> A { iter::max(self) }
|
||||
pure fn find(p: fn(A) -> bool) -> option<A> { iter::find(self, p) }
|
||||
pure fn find(p: fn(A) -> bool) -> Option<A> { iter::find(self, p) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,6 @@ pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
|
|||
}
|
||||
}
|
||||
|
||||
pure fn SIZE_HINT<A>(self: IMPL_T<A>) -> option<uint> {
|
||||
some(self.len())
|
||||
pure fn SIZE_HINT<A>(self: IMPL_T<A>) -> Option<uint> {
|
||||
Some(self.len())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,6 @@ pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
|
|||
unsafe { self.swap(|v| { vec::each(v, f); v }) }
|
||||
}
|
||||
|
||||
pure fn SIZE_HINT<A>(self: IMPL_T<A>) -> option<uint> {
|
||||
some(self.len())
|
||||
pure fn SIZE_HINT<A>(self: IMPL_T<A>) -> Option<uint> {
|
||||
Some(self.len())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
type IMPL_T<A> = option<A>;
|
||||
type IMPL_T<A> = Option<A>;
|
||||
|
||||
pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
|
||||
match self {
|
||||
none => (),
|
||||
some(a) => { f(a); }
|
||||
None => (),
|
||||
Some(a) => { f(a); }
|
||||
}
|
||||
}
|
||||
|
||||
pure fn SIZE_HINT<A>(self: IMPL_T<A>) -> option<uint> {
|
||||
pure fn SIZE_HINT<A>(self: IMPL_T<A>) -> Option<uint> {
|
||||
match self {
|
||||
none => some(0u),
|
||||
some(_) => some(1u)
|
||||
None => Some(0u),
|
||||
Some(_) => Some(1u)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ type InitOp<T> = fn(uint) -> T;
|
|||
|
||||
trait BaseIter<A> {
|
||||
pure fn each(blk: fn(A) -> bool);
|
||||
pure fn size_hint() -> option<uint>;
|
||||
pure fn size_hint() -> Option<uint>;
|
||||
}
|
||||
|
||||
trait ExtendedIter<A> {
|
||||
|
|
@ -13,7 +13,7 @@ trait ExtendedIter<A> {
|
|||
pure fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B;
|
||||
pure fn contains(x: A) -> bool;
|
||||
pure fn count(x: A) -> uint;
|
||||
pure fn position(f: fn(A) -> bool) -> option<uint>;
|
||||
pure fn position(f: fn(A) -> bool) -> Option<uint>;
|
||||
}
|
||||
|
||||
trait Times {
|
||||
|
|
@ -29,7 +29,7 @@ trait CopyableIter<A:copy> {
|
|||
pure fn to_vec() -> ~[A];
|
||||
pure fn min() -> A;
|
||||
pure fn max() -> A;
|
||||
pure fn find(p: fn(A) -> bool) -> option<A>;
|
||||
pure fn find(p: fn(A) -> bool) -> Option<A>;
|
||||
}
|
||||
|
||||
// A trait for sequences that can be by imperatively pushing elements
|
||||
|
|
@ -134,13 +134,13 @@ pure fn count<A,IA:BaseIter<A>>(self: IA, x: A) -> uint {
|
|||
}
|
||||
|
||||
pure fn position<A,IA:BaseIter<A>>(self: IA, f: fn(A) -> bool)
|
||||
-> option<uint> {
|
||||
-> Option<uint> {
|
||||
let mut i = 0;
|
||||
for self.each |a| {
|
||||
if f(a) { return some(i); }
|
||||
if f(a) { return Some(i); }
|
||||
i += 1;
|
||||
}
|
||||
return none;
|
||||
return None;
|
||||
}
|
||||
|
||||
// note: 'rposition' would only make sense to provide with a bidirectional
|
||||
|
|
@ -156,43 +156,43 @@ pure fn repeat(times: uint, blk: fn() -> bool) {
|
|||
}
|
||||
|
||||
pure fn min<A:copy,IA:BaseIter<A>>(self: IA) -> A {
|
||||
match do foldl::<A,option<A>,IA>(self, none) |a, b| {
|
||||
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||
match 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"
|
||||
}
|
||||
}
|
||||
|
||||
pure fn max<A:copy,IA:BaseIter<A>>(self: IA) -> A {
|
||||
match do foldl::<A,option<A>,IA>(self, none) |a, b| {
|
||||
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||
match 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"
|
||||
}
|
||||
}
|
||||
|
||||
pure fn find<A: copy,IA:BaseIter<A>>(self: IA,
|
||||
p: fn(A) -> bool) -> option<A> {
|
||||
p: fn(A) -> bool) -> Option<A> {
|
||||
for self.each |i| {
|
||||
if p(i) { return some(i) }
|
||||
if p(i) { return Some(i) }
|
||||
}
|
||||
return none;
|
||||
return None;
|
||||
}
|
||||
|
||||
// Some functions for just building
|
||||
|
|
@ -227,7 +227,7 @@ pure fn build<A,B: Buildable<A>>(builder: fn(push: pure fn(+A))) -> B {
|
|||
*/
|
||||
#[inline(always)]
|
||||
pure fn build_sized_opt<A,B: Buildable<A>>(
|
||||
size: option<uint>,
|
||||
size: Option<uint>,
|
||||
builder: fn(push: pure fn(+A))) -> B {
|
||||
|
||||
build_sized(size.get_default(4), builder)
|
||||
|
|
@ -339,9 +339,9 @@ fn test_filter_on_uint_range() {
|
|||
|
||||
#[test]
|
||||
fn test_filter_map() {
|
||||
fn negativate_the_evens(&&i: int) -> option<int> {
|
||||
fn negativate_the_evens(&&i: int) -> Option<int> {
|
||||
if i % 2 == 0 {
|
||||
some(-i)
|
||||
Some(-i)
|
||||
} else {
|
||||
none
|
||||
}
|
||||
|
|
@ -354,8 +354,8 @@ fn test_filter_map() {
|
|||
|
||||
#[test]
|
||||
fn test_flat_map_with_option() {
|
||||
fn if_even(&&i: int) -> option<int> {
|
||||
if (i % 2) == 0 { some(i) }
|
||||
fn if_even(&&i: int) -> Option<int> {
|
||||
if (i % 2) == 0 { Some(i) }
|
||||
else { none }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,18 +3,18 @@
|
|||
*
|
||||
* Type `option` represents an optional value.
|
||||
*
|
||||
* Every `option<T>` value can either be `some(T)` or `none`. Where in other
|
||||
* Every `Option<T>` value can either be `Some(T)` or `none`. Where in other
|
||||
* languages you might use a nullable type, in Rust you would use an option
|
||||
* type.
|
||||
*/
|
||||
|
||||
/// The option type
|
||||
enum option<T> {
|
||||
none,
|
||||
some(T),
|
||||
enum Option<T> {
|
||||
None,
|
||||
Some(T),
|
||||
}
|
||||
|
||||
pure fn get<T: copy>(opt: option<T>) -> T {
|
||||
pure fn get<T: copy>(opt: Option<T>) -> T {
|
||||
/*!
|
||||
* Gets the value out of an option
|
||||
*
|
||||
|
|
@ -24,12 +24,12 @@ pure fn get<T: copy>(opt: option<T>) -> T {
|
|||
*/
|
||||
|
||||
match opt {
|
||||
some(x) => return x,
|
||||
none => fail ~"option::get none"
|
||||
Some(x) => return x,
|
||||
None => fail ~"option::get none"
|
||||
}
|
||||
}
|
||||
|
||||
pure fn get_ref<T>(opt: &r/option<T>) -> &r/T {
|
||||
pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
|
||||
/*!
|
||||
* Gets an immutable reference to the value inside an option.
|
||||
*
|
||||
|
|
@ -38,12 +38,12 @@ pure fn get_ref<T>(opt: &r/option<T>) -> &r/T {
|
|||
* Fails if the value equals `none`
|
||||
*/
|
||||
match *opt {
|
||||
some(ref x) => x,
|
||||
none => fail ~"option::get_ref none"
|
||||
Some(ref x) => x,
|
||||
None => fail ~"option::get_ref none"
|
||||
}
|
||||
}
|
||||
|
||||
pure fn expect<T: copy>(opt: option<T>, reason: ~str) -> T {
|
||||
pure fn expect<T: copy>(opt: Option<T>, reason: ~str) -> T {
|
||||
/*!
|
||||
* Gets the value out of an option, printing a specified message on
|
||||
* failure
|
||||
|
|
@ -52,60 +52,60 @@ pure fn expect<T: copy>(opt: option<T>, reason: ~str) -> T {
|
|||
*
|
||||
* Fails if the value equals `none`
|
||||
*/
|
||||
match opt { some(x) => x, none => fail reason }
|
||||
match opt { Some(x) => x, None => fail reason }
|
||||
}
|
||||
|
||||
pure fn map<T, U>(opt: option<T>, f: fn(T) -> U) -> option<U> {
|
||||
pure fn map<T, U>(opt: Option<T>, f: fn(T) -> U) -> Option<U> {
|
||||
//! Maps a `some` value from one type to another
|
||||
|
||||
match opt { some(x) => some(f(x)), none => none }
|
||||
match opt { Some(x) => Some(f(x)), None => None }
|
||||
}
|
||||
|
||||
pure fn map_ref<T, U>(opt: &option<T>, f: fn(x: &T) -> U) -> option<U> {
|
||||
pure fn map_ref<T, U>(opt: &Option<T>, f: fn(x: &T) -> U) -> Option<U> {
|
||||
//! Maps a `some` value by reference from one type to another
|
||||
|
||||
match *opt { some(ref x) => some(f(x)), none => none }
|
||||
match *opt { Some(ref x) => Some(f(x)), None => None }
|
||||
}
|
||||
|
||||
pure fn map_consume<T, U>(+opt: option<T>, f: fn(+T) -> U) -> option<U> {
|
||||
pure fn map_consume<T, U>(+opt: Option<T>, f: fn(+T) -> U) -> Option<U> {
|
||||
/*!
|
||||
* As `map`, but consumes the option and gives `f` ownership to avoid
|
||||
* copying.
|
||||
*/
|
||||
if opt.is_some() { some(f(option::unwrap(opt))) } else { none }
|
||||
if opt.is_some() { Some(f(option::unwrap(opt))) } else { None }
|
||||
}
|
||||
|
||||
pure fn chain<T, U>(opt: option<T>, f: fn(T) -> option<U>) -> option<U> {
|
||||
pure fn chain<T, U>(opt: Option<T>, f: fn(T) -> Option<U>) -> Option<U> {
|
||||
/*!
|
||||
* Update an optional value by optionally running its content through a
|
||||
* function that returns an option.
|
||||
*/
|
||||
|
||||
match opt { some(x) => f(x), none => none }
|
||||
match opt { Some(x) => f(x), None => None }
|
||||
}
|
||||
|
||||
pure fn chain_ref<T, U>(opt: &option<T>,
|
||||
f: fn(x: &T) -> option<U>) -> option<U> {
|
||||
pure fn chain_ref<T, U>(opt: &Option<T>,
|
||||
f: fn(x: &T) -> Option<U>) -> Option<U> {
|
||||
/*!
|
||||
* Update an optional value by optionally running its content by reference
|
||||
* through a function that returns an option.
|
||||
*/
|
||||
|
||||
match *opt { some(ref x) => f(x), none => none }
|
||||
match *opt { Some(ref x) => f(x), None => None }
|
||||
}
|
||||
|
||||
pure fn or<T>(+opta: option<T>, +optb: option<T>) -> option<T> {
|
||||
pure fn or<T>(+opta: Option<T>, +optb: Option<T>) -> Option<T> {
|
||||
/*!
|
||||
* Returns the leftmost some() value, or none if both are none.
|
||||
*/
|
||||
match opta {
|
||||
some(_) => opta,
|
||||
Some(_) => opta,
|
||||
_ => optb
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn while_some<T>(+x: option<T>, blk: fn(+T) -> option<T>) {
|
||||
pure fn while_some<T>(+x: Option<T>, blk: fn(+T) -> Option<T>) {
|
||||
//! Applies a function zero or more times until the result is none.
|
||||
|
||||
let mut opt <- x;
|
||||
|
|
@ -114,52 +114,52 @@ pure fn while_some<T>(+x: option<T>, blk: fn(+T) -> option<T>) {
|
|||
}
|
||||
}
|
||||
|
||||
pure fn is_none<T>(opt: option<T>) -> bool {
|
||||
pure fn is_none<T>(opt: Option<T>) -> bool {
|
||||
//! Returns true if the option equals `none`
|
||||
|
||||
match opt { none => true, some(_) => false }
|
||||
match opt { None => true, Some(_) => false }
|
||||
}
|
||||
|
||||
pure fn is_some<T>(opt: option<T>) -> bool {
|
||||
pure fn is_some<T>(opt: Option<T>) -> bool {
|
||||
//! Returns true if the option contains some value
|
||||
|
||||
!is_none(opt)
|
||||
}
|
||||
|
||||
pure fn get_default<T: copy>(opt: option<T>, def: T) -> T {
|
||||
pure fn get_default<T: copy>(opt: Option<T>, def: T) -> T {
|
||||
//! Returns the contained value or a default
|
||||
|
||||
match opt { some(x) => x, none => def }
|
||||
match opt { Some(x) => x, None => def }
|
||||
}
|
||||
|
||||
pure fn map_default<T, U>(opt: option<T>, +def: U, f: fn(T) -> U) -> U {
|
||||
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
|
||||
|
||||
match opt { none => def, some(t) => f(t) }
|
||||
match opt { None => def, Some(t) => f(t) }
|
||||
}
|
||||
|
||||
// This should replace map_default.
|
||||
pure fn map_default_ref<T, U>(opt: &option<T>, +def: U,
|
||||
pure fn map_default_ref<T, U>(opt: &Option<T>, +def: U,
|
||||
f: fn(x: &T) -> U) -> U {
|
||||
//! Applies a function to the contained value or returns a default
|
||||
|
||||
match *opt { none => def, some(ref t) => f(t) }
|
||||
match *opt { None => def, Some(ref t) => f(t) }
|
||||
}
|
||||
|
||||
// This should change to by-copy mode; use iter_ref below for by reference
|
||||
pure fn iter<T>(opt: option<T>, f: fn(T)) {
|
||||
pure fn iter<T>(opt: Option<T>, f: fn(T)) {
|
||||
//! Performs an operation on the contained value or does nothing
|
||||
|
||||
match opt { none => (), some(t) => f(t) }
|
||||
match opt { None => (), Some(t) => f(t) }
|
||||
}
|
||||
|
||||
pure fn iter_ref<T>(opt: &option<T>, f: fn(x: &T)) {
|
||||
pure fn iter_ref<T>(opt: &Option<T>, f: fn(x: &T)) {
|
||||
//! Performs an operation on the contained value by reference
|
||||
match *opt { none => (), some(ref t) => f(t) }
|
||||
match *opt { None => (), Some(ref t) => f(t) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn unwrap<T>(+opt: option<T>) -> T {
|
||||
pure fn unwrap<T>(+opt: Option<T>) -> T {
|
||||
/*!
|
||||
* Moves a value out of an option type and returns it.
|
||||
*
|
||||
|
|
@ -167,31 +167,31 @@ pure fn unwrap<T>(+opt: option<T>) -> T {
|
|||
* of option types without copying them.
|
||||
*/
|
||||
match move opt {
|
||||
some(move x) => x,
|
||||
none => fail ~"option::unwrap none"
|
||||
Some(move x) => x,
|
||||
None => fail ~"option::unwrap none"
|
||||
}
|
||||
}
|
||||
|
||||
/// The ubiquitous option dance.
|
||||
#[inline(always)]
|
||||
fn swap_unwrap<T>(opt: &mut option<T>) -> T {
|
||||
fn swap_unwrap<T>(opt: &mut Option<T>) -> T {
|
||||
if opt.is_none() { fail ~"option::swap_unwrap none" }
|
||||
unwrap(util::replace(opt, none))
|
||||
unwrap(util::replace(opt, None))
|
||||
}
|
||||
|
||||
pure fn unwrap_expect<T>(+opt: option<T>, reason: &str) -> T {
|
||||
pure fn unwrap_expect<T>(+opt: Option<T>, reason: &str) -> T {
|
||||
//! As unwrap, but with a specified failure message.
|
||||
if opt.is_none() { fail reason.to_unique(); }
|
||||
unwrap(opt)
|
||||
}
|
||||
|
||||
// Some of these should change to be &option<T>, some should not. See below.
|
||||
impl<T> option<T> {
|
||||
// Some of these should change to be &Option<T>, some should not. See below.
|
||||
impl<T> Option<T> {
|
||||
/**
|
||||
* Update an optional value by optionally running its content through a
|
||||
* function that returns an option.
|
||||
*/
|
||||
pure fn chain<U>(f: fn(T) -> option<U>) -> option<U> { chain(self, f) }
|
||||
pure fn chain<U>(f: fn(T) -> Option<U>) -> Option<U> { chain(self, f) }
|
||||
/// Applies a function to the contained value or returns a default
|
||||
pure fn map_default<U>(+def: U, f: fn(T) -> U) -> U
|
||||
{ map_default(self, def, f) }
|
||||
|
|
@ -202,15 +202,15 @@ impl<T> option<T> {
|
|||
/// Returns true if the option contains some value
|
||||
pure fn is_some() -> bool { is_some(self) }
|
||||
/// Maps a `some` value from one type to another
|
||||
pure fn map<U>(f: fn(T) -> U) -> option<U> { map(self, f) }
|
||||
pure fn map<U>(f: fn(T) -> U) -> Option<U> { map(self, f) }
|
||||
}
|
||||
|
||||
impl<T> &option<T> {
|
||||
impl<T> &Option<T> {
|
||||
/**
|
||||
* Update an optional value by optionally running its content by reference
|
||||
* through a function that returns an option.
|
||||
*/
|
||||
pure fn chain_ref<U>(f: fn(x: &T) -> option<U>) -> option<U> {
|
||||
pure fn chain_ref<U>(f: fn(x: &T) -> Option<U>) -> Option<U> {
|
||||
chain_ref(self, f)
|
||||
}
|
||||
/// Applies a function to the contained value or returns a default
|
||||
|
|
@ -219,12 +219,12 @@ impl<T> &option<T> {
|
|||
/// Performs an operation on the contained value by reference
|
||||
pure fn iter_ref(f: fn(x: &T)) { iter_ref(self, f) }
|
||||
/// Maps a `some` value from one type to another by reference
|
||||
pure fn map_ref<U>(f: fn(x: &T) -> U) -> option<U> { map_ref(self, f) }
|
||||
pure fn map_ref<U>(f: fn(x: &T) -> U) -> Option<U> { map_ref(self, f) }
|
||||
/// Gets an immutable reference to the value inside a `some`.
|
||||
pure fn get_ref() -> &self/T { get_ref(self) }
|
||||
}
|
||||
|
||||
impl<T: copy> option<T> {
|
||||
impl<T: copy> Option<T> {
|
||||
/**
|
||||
* Gets the value out of an option
|
||||
*
|
||||
|
|
@ -244,14 +244,14 @@ impl<T: copy> option<T> {
|
|||
*/
|
||||
pure fn expect(reason: ~str) -> T { expect(self, reason) }
|
||||
/// Applies a function zero or more times until the result is none.
|
||||
pure fn while_some(blk: fn(+T) -> option<T>) { while_some(self, blk) }
|
||||
pure fn while_some(blk: fn(+T) -> Option<T>) { while_some(self, blk) }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unwrap_ptr() {
|
||||
let x = ~0;
|
||||
let addr_x = ptr::addr_of(*x);
|
||||
let opt = some(x);
|
||||
let opt = Some(x);
|
||||
let y = unwrap(opt);
|
||||
let addr_y = ptr::addr_of(*y);
|
||||
assert addr_x == addr_y;
|
||||
|
|
@ -261,7 +261,7 @@ fn test_unwrap_ptr() {
|
|||
fn test_unwrap_str() {
|
||||
let x = ~"test";
|
||||
let addr_x = str::as_buf(x, |buf, _len| ptr::addr_of(buf));
|
||||
let opt = some(x);
|
||||
let opt = Some(x);
|
||||
let y = unwrap(opt);
|
||||
let addr_y = str::as_buf(y, |buf, _len| ptr::addr_of(buf));
|
||||
assert addr_x == addr_y;
|
||||
|
|
@ -277,7 +277,7 @@ fn test_unwrap_resource() {
|
|||
let i = @mut 0;
|
||||
{
|
||||
let x = r(i);
|
||||
let opt = some(x);
|
||||
let opt = Some(x);
|
||||
let _y = unwrap(opt);
|
||||
}
|
||||
assert *i == 1;
|
||||
|
|
@ -285,8 +285,8 @@ fn test_unwrap_resource() {
|
|||
|
||||
#[test]
|
||||
fn test_option_dance() {
|
||||
let x = some(());
|
||||
let mut y = some(5);
|
||||
let x = Some(());
|
||||
let mut y = Some(5);
|
||||
let mut y2 = 0;
|
||||
do x.iter |_x| {
|
||||
y2 = swap_unwrap(&mut y);
|
||||
|
|
@ -296,7 +296,7 @@ fn test_option_dance() {
|
|||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn test_option_too_much_dance() {
|
||||
let mut y = some(util::NonCopyable());
|
||||
let mut y = Some(util::NonCopyable());
|
||||
let _y2 = swap_unwrap(&mut y);
|
||||
let _y3 = swap_unwrap(&mut y);
|
||||
}
|
||||
|
|
@ -304,12 +304,12 @@ fn test_option_too_much_dance() {
|
|||
#[test]
|
||||
fn test_option_while_some() {
|
||||
let mut i = 0;
|
||||
do some(10).while_some |j| {
|
||||
do Some(10).while_some |j| {
|
||||
i += 1;
|
||||
if (j > 0) {
|
||||
some(j-1)
|
||||
Some(j-1)
|
||||
} else {
|
||||
none
|
||||
None
|
||||
}
|
||||
}
|
||||
assert i == 11;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import libc::{c_char, c_void, c_int, c_uint, size_t, ssize_t,
|
|||
mode_t, pid_t, FILE};
|
||||
import libc::{close, fclose};
|
||||
|
||||
import option::{some, none};
|
||||
import option::{Some, None};
|
||||
|
||||
import consts::*;
|
||||
import task::TaskBuilder;
|
||||
|
|
@ -65,13 +65,13 @@ fn as_c_charp<T>(s: &str, f: fn(*c_char) -> T) -> T {
|
|||
}
|
||||
|
||||
fn fill_charp_buf(f: fn(*mut c_char, size_t) -> bool)
|
||||
-> option<~str> {
|
||||
-> Option<~str> {
|
||||
let buf = vec::to_mut(vec::from_elem(tmpbuf_sz, 0u8 as c_char));
|
||||
do vec::as_mut_buf(buf) |b, sz| {
|
||||
if f(b, sz as size_t) unsafe {
|
||||
some(str::unsafe::from_buf(b as *u8))
|
||||
Some(str::unsafe::from_buf(b as *u8))
|
||||
} else {
|
||||
none
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -81,14 +81,14 @@ mod win32 {
|
|||
import dword = libc::types::os::arch::extra::DWORD;
|
||||
|
||||
fn fill_utf16_buf_and_decode(f: fn(*mut u16, dword) -> dword)
|
||||
-> option<~str> {
|
||||
-> Option<~str> {
|
||||
|
||||
// FIXME: remove these when export globs work properly. #1238
|
||||
import libc::funcs::extra::kernel32::*;
|
||||
import libc::consts::os::extra::*;
|
||||
|
||||
let mut n = tmpbuf_sz as dword;
|
||||
let mut res = none;
|
||||
let mut res = None;
|
||||
let mut done = false;
|
||||
while !done {
|
||||
let buf = vec::to_mut(vec::from_elem(n as uint, 0u16));
|
||||
|
|
@ -102,7 +102,7 @@ mod win32 {
|
|||
n *= (2 as dword);
|
||||
} else {
|
||||
let sub = vec::slice(buf, 0u, k as uint);
|
||||
res = option::some(str::from_utf16(sub));
|
||||
res = option::Some(str::from_utf16(sub));
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ mod win32 {
|
|||
}
|
||||
}
|
||||
|
||||
fn getenv(n: &str) -> option<~str> {
|
||||
fn getenv(n: &str) -> Option<~str> {
|
||||
global_env::getenv(n)
|
||||
}
|
||||
|
||||
|
|
@ -142,12 +142,12 @@ mod global_env {
|
|||
}
|
||||
|
||||
enum Msg {
|
||||
MsgGetEnv(~str, comm::Chan<option<~str>>),
|
||||
MsgGetEnv(~str, comm::Chan<Option<~str>>),
|
||||
MsgSetEnv(~str, ~str, comm::Chan<()>),
|
||||
MsgEnv(comm::Chan<~[(~str,~str)]>)
|
||||
}
|
||||
|
||||
fn getenv(n: &str) -> option<~str> {
|
||||
fn getenv(n: &str) -> Option<~str> {
|
||||
let env_ch = get_global_env_chan();
|
||||
let po = comm::port();
|
||||
comm::send(env_ch, MsgGetEnv(str::from_slice(n),
|
||||
|
|
@ -219,20 +219,20 @@ mod global_env {
|
|||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn getenv(n: &str) -> option<~str> {
|
||||
fn getenv(n: &str) -> Option<~str> {
|
||||
unsafe {
|
||||
let s = str::as_c_str(n, libc::getenv);
|
||||
return if unsafe::reinterpret_cast(s) == 0 {
|
||||
option::none::<~str>
|
||||
option::None::<~str>
|
||||
} else {
|
||||
let s = unsafe::reinterpret_cast(s);
|
||||
option::some::<~str>(str::unsafe::from_buf(s))
|
||||
option::Some::<~str>(str::unsafe::from_buf(s))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn getenv(n: &str) -> option<~str> {
|
||||
fn getenv(n: &str) -> Option<~str> {
|
||||
import libc::types::os::arch::extra::*;
|
||||
import libc::funcs::extra::kernel32::*;
|
||||
import win32::*;
|
||||
|
|
@ -383,10 +383,10 @@ fn dll_filename(base: &str) -> ~str {
|
|||
}
|
||||
|
||||
|
||||
fn self_exe_path() -> option<Path> {
|
||||
fn self_exe_path() -> Option<Path> {
|
||||
|
||||
#[cfg(target_os = "freebsd")]
|
||||
fn load_self() -> option<~str> {
|
||||
fn load_self() -> Option<~str> {
|
||||
unsafe {
|
||||
import libc::funcs::bsd44::*;
|
||||
import libc::consts::os::extra::*;
|
||||
|
|
@ -402,7 +402,7 @@ fn self_exe_path() -> option<Path> {
|
|||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn load_self() -> option<~str> {
|
||||
fn load_self() -> Option<~str> {
|
||||
import libc::funcs::posix01::unistd::readlink;
|
||||
do fill_charp_buf() |buf, sz| {
|
||||
do as_c_charp("/proc/self/exe") |proc_self_buf| {
|
||||
|
|
@ -412,7 +412,7 @@ fn self_exe_path() -> option<Path> {
|
|||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn load_self() -> option<~str> {
|
||||
fn load_self() -> Option<~str> {
|
||||
// FIXME: remove imports when export globs work properly. #1238
|
||||
import libc::funcs::extra::*;
|
||||
do fill_charp_buf() |buf, sz| {
|
||||
|
|
@ -422,7 +422,7 @@ fn self_exe_path() -> option<Path> {
|
|||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn load_self() -> option<~str> {
|
||||
fn load_self() -> Option<~str> {
|
||||
// FIXME: remove imports when export globs work properly. #1238
|
||||
import libc::types::os::arch::extra::*;
|
||||
import libc::funcs::extra::kernel32::*;
|
||||
|
|
@ -451,28 +451,28 @@ fn self_exe_path() -> option<Path> {
|
|||
*
|
||||
* Otherwise, homedir returns option::none.
|
||||
*/
|
||||
fn homedir() -> option<Path> {
|
||||
fn homedir() -> Option<Path> {
|
||||
return match getenv(~"HOME") {
|
||||
some(p) => if !str::is_empty(p) {
|
||||
some(Path(p))
|
||||
Some(p) => if !str::is_empty(p) {
|
||||
Some(Path(p))
|
||||
} else {
|
||||
secondary()
|
||||
},
|
||||
none => secondary()
|
||||
None => secondary()
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
fn secondary() -> option<Path> {
|
||||
none
|
||||
fn secondary() -> Option<Path> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn secondary() -> option<Path> {
|
||||
fn secondary() -> Option<Path> {
|
||||
do option::chain(getenv(~"USERPROFILE")) |p| {
|
||||
if !str::is_empty(p) {
|
||||
some(Path(p))
|
||||
Some(Path(p))
|
||||
} else {
|
||||
none
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -491,15 +491,15 @@ fn homedir() -> option<Path> {
|
|||
fn tmpdir() -> Path {
|
||||
return lookup();
|
||||
|
||||
fn getenv_nonempty(v: &str) -> option<Path> {
|
||||
fn getenv_nonempty(v: &str) -> Option<Path> {
|
||||
match getenv(v) {
|
||||
some(x) =>
|
||||
Some(x) =>
|
||||
if str::is_empty(x) {
|
||||
none
|
||||
None
|
||||
} else {
|
||||
some(Path(x))
|
||||
Some(Path(x))
|
||||
},
|
||||
_ => none
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -843,7 +843,7 @@ mod tests {
|
|||
fn test_setenv() {
|
||||
let n = make_rand_name();
|
||||
setenv(n, ~"VALUE");
|
||||
assert getenv(n) == option::some(~"VALUE");
|
||||
assert getenv(n) == option::Some(~"VALUE");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -853,9 +853,9 @@ mod tests {
|
|||
let n = make_rand_name();
|
||||
setenv(n, ~"1");
|
||||
setenv(n, ~"2");
|
||||
assert getenv(n) == option::some(~"2");
|
||||
assert getenv(n) == option::Some(~"2");
|
||||
setenv(n, ~"");
|
||||
assert getenv(n) == option::some(~"");
|
||||
assert getenv(n) == option::Some(~"");
|
||||
}
|
||||
|
||||
// Windows GetEnvironmentVariable requires some extra work to make sure
|
||||
|
|
@ -870,7 +870,7 @@ mod tests {
|
|||
let n = make_rand_name();
|
||||
setenv(n, s);
|
||||
log(debug, s);
|
||||
assert getenv(n) == option::some(s);
|
||||
assert getenv(n) == option::Some(s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -896,7 +896,7 @@ mod tests {
|
|||
// MingW seems to set some funky environment variables like
|
||||
// "=C:=C:\MinGW\msys\1.0\bin" and "!::=::\" that are returned
|
||||
// from env() but not visible from getenv().
|
||||
assert option::is_none(v2) || v2 == option::some(v);
|
||||
assert option::is_none(v2) || v2 == option::Some(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -928,10 +928,10 @@ mod tests {
|
|||
let oldhome = getenv(~"HOME");
|
||||
|
||||
setenv(~"HOME", ~"/home/MountainView");
|
||||
assert os::homedir() == some(Path("/home/MountainView"));
|
||||
assert os::homedir() == Some(Path("/home/MountainView"));
|
||||
|
||||
setenv(~"HOME", ~"");
|
||||
assert os::homedir() == none;
|
||||
assert os::homedir() == None;
|
||||
|
||||
option::iter(oldhome, |s| setenv(~"HOME", s));
|
||||
}
|
||||
|
|
@ -946,19 +946,19 @@ mod tests {
|
|||
setenv(~"HOME", ~"");
|
||||
setenv(~"USERPROFILE", ~"");
|
||||
|
||||
assert os::homedir() == none;
|
||||
assert os::homedir() == None;
|
||||
|
||||
setenv(~"HOME", ~"/home/MountainView");
|
||||
assert os::homedir() == some(Path("/home/MountainView"));
|
||||
assert os::homedir() == Some(Path("/home/MountainView"));
|
||||
|
||||
setenv(~"HOME", ~"");
|
||||
|
||||
setenv(~"USERPROFILE", ~"/home/MountainView");
|
||||
assert os::homedir() == some(Path("/home/MountainView"));
|
||||
assert os::homedir() == Some(Path("/home/MountainView"));
|
||||
|
||||
setenv(~"HOME", ~"/home/MountainView");
|
||||
setenv(~"USERPROFILE", ~"/home/PaloAlto");
|
||||
assert os::homedir() == some(Path("/home/MountainView"));
|
||||
assert os::homedir() == Some(Path("/home/MountainView"));
|
||||
|
||||
option::iter(oldhome, |s| setenv(~"HOME", s));
|
||||
option::iter(olduserprofile,
|
||||
|
|
|
|||
|
|
@ -64,11 +64,11 @@ fn split_dirname_basename (pp: Path) -> {dirname: ~str, basename: ~str} {
|
|||
match str::rfind(pp, |ch|
|
||||
ch == consts::path_sep || ch == consts::alt_path_sep
|
||||
) {
|
||||
some(i) => {
|
||||
Some(i) => {
|
||||
dirname: str::slice(pp, 0u, i),
|
||||
basename: str::slice(pp, i + 1u, str::len(pp))
|
||||
},
|
||||
none => {dirname: ~".", basename: pp}
|
||||
None => {dirname: ~".", basename: pp}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -236,9 +236,9 @@ fn normalize(p: Path) -> Path {
|
|||
fn strip_dots(s: ~[Path]) -> ~[Path] {
|
||||
vec::filter_map(s, |elem|
|
||||
if elem == ~"." {
|
||||
option::none
|
||||
option::None
|
||||
} else {
|
||||
option::some(elem)
|
||||
option::Some(elem)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
#[forbid(deprecated_pattern)];
|
||||
|
||||
struct WindowsPath {
|
||||
host: option<~str>;
|
||||
device: option<~str>;
|
||||
host: Option<~str>;
|
||||
device: Option<~str>;
|
||||
is_absolute: bool;
|
||||
components: ~[~str];
|
||||
}
|
||||
|
|
@ -19,9 +19,9 @@ trait GenericPath {
|
|||
static pure fn from_str((&str)) -> self;
|
||||
|
||||
pure fn dirname() -> ~str;
|
||||
pure fn filename() -> option<~str>;
|
||||
pure fn filestem() -> option<~str>;
|
||||
pure fn filetype() -> option<~str>;
|
||||
pure fn filename() -> Option<~str>;
|
||||
pure fn filestem() -> Option<~str>;
|
||||
pure fn filetype() -> Option<~str>;
|
||||
|
||||
pure fn with_dirname((&str)) -> self;
|
||||
pure fn with_filename((&str)) -> self;
|
||||
|
|
@ -82,32 +82,32 @@ impl PosixPath : GenericPath {
|
|||
}
|
||||
}
|
||||
|
||||
pure fn filename() -> option<~str> {
|
||||
pure fn filename() -> Option<~str> {
|
||||
match self.components.len() {
|
||||
0 => none,
|
||||
n => some(copy self.components[n - 1])
|
||||
0 => None,
|
||||
n => Some(copy self.components[n - 1])
|
||||
}
|
||||
}
|
||||
|
||||
pure fn filestem() -> option<~str> {
|
||||
pure fn filestem() -> Option<~str> {
|
||||
match self.filename() {
|
||||
none => none,
|
||||
some(ref f) => {
|
||||
None => None,
|
||||
Some(ref f) => {
|
||||
match str::rfind_char(*f, '.') {
|
||||
some(p) => some(f.slice(0, p)),
|
||||
none => some(copy *f)
|
||||
Some(p) => Some(f.slice(0, p)),
|
||||
None => Some(copy *f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pure fn filetype() -> option<~str> {
|
||||
pure fn filetype() -> Option<~str> {
|
||||
match self.filename() {
|
||||
none => none,
|
||||
some(ref f) => {
|
||||
None => None,
|
||||
Some(ref f) => {
|
||||
match str::rfind_char(*f, '.') {
|
||||
some(p) if p+1 < f.len() => some(f.slice(p+1, f.len())),
|
||||
_ => none
|
||||
Some(p) if p+1 < f.len() => Some(f.slice(p+1, f.len())),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -116,8 +116,8 @@ impl PosixPath : GenericPath {
|
|||
pure fn with_dirname(d: &str) -> PosixPath {
|
||||
let dpath = from_str::<PosixPath>(d);
|
||||
match self.filename() {
|
||||
some(ref f) => dpath.push(*f),
|
||||
none => dpath
|
||||
Some(ref f) => dpath.push(*f),
|
||||
None => dpath
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -130,8 +130,8 @@ impl PosixPath : GenericPath {
|
|||
|
||||
pure fn with_filestem(s: &str) -> PosixPath {
|
||||
match self.filetype() {
|
||||
none => self.with_filename(s),
|
||||
some(ref t) =>
|
||||
None => self.with_filename(s),
|
||||
Some(ref t) =>
|
||||
self.with_filename(str::from_slice(s) + "." + *t)
|
||||
}
|
||||
}
|
||||
|
|
@ -139,14 +139,14 @@ impl PosixPath : GenericPath {
|
|||
pure fn with_filetype(t: &str) -> PosixPath {
|
||||
if t.len() == 0 {
|
||||
match self.filestem() {
|
||||
none => copy self,
|
||||
some(s) => self.with_filename(s)
|
||||
None => copy self,
|
||||
Some(s) => self.with_filename(s)
|
||||
}
|
||||
} else {
|
||||
let t = ~"." + str::from_slice(t);
|
||||
match self.filestem() {
|
||||
none => self.with_filename(t),
|
||||
some(ref s) =>
|
||||
None => self.with_filename(t),
|
||||
Some(ref s) =>
|
||||
self.with_filename(*s + t)
|
||||
}
|
||||
}
|
||||
|
|
@ -162,8 +162,8 @@ impl PosixPath : GenericPath {
|
|||
|
||||
pure fn file_path() -> PosixPath {
|
||||
let cs = match self.filename() {
|
||||
none => ~[],
|
||||
some(ref f) => ~[copy *f]
|
||||
None => ~[],
|
||||
Some(ref f) => ~[copy *f]
|
||||
};
|
||||
return PosixPath { is_absolute: false,
|
||||
components: cs }
|
||||
|
|
@ -201,12 +201,12 @@ impl WindowsPath : ToStr {
|
|||
fn to_str() -> ~str {
|
||||
let mut s = ~"";
|
||||
match self.host {
|
||||
some(h) => { s += "\\\\"; s += h; }
|
||||
none => { }
|
||||
Some(h) => { s += "\\\\"; s += h; }
|
||||
None => { }
|
||||
}
|
||||
match self.device {
|
||||
some(d) => { s += d; s += ":"; }
|
||||
none => { }
|
||||
Some(d) => { s += d; s += ":"; }
|
||||
None => { }
|
||||
}
|
||||
if self.is_absolute {
|
||||
s += "\\";
|
||||
|
|
@ -224,21 +224,21 @@ impl WindowsPath : GenericPath {
|
|||
let rest;
|
||||
|
||||
match windows::extract_drive_prefix(s) {
|
||||
some((ref d, ref r)) => {
|
||||
host = none;
|
||||
device = some(copy *d);
|
||||
Some((ref d, ref r)) => {
|
||||
host = None;
|
||||
device = Some(copy *d);
|
||||
rest = copy *r;
|
||||
}
|
||||
none => {
|
||||
None => {
|
||||
match windows::extract_unc_prefix(s) {
|
||||
some((ref h, ref r)) => {
|
||||
host = some(copy *h);
|
||||
device = none;
|
||||
Some((ref h, ref r)) => {
|
||||
host = Some(copy *h);
|
||||
device = None;
|
||||
rest = copy *r;
|
||||
}
|
||||
none => {
|
||||
host = none;
|
||||
device = none;
|
||||
None => {
|
||||
host = None;
|
||||
device = None;
|
||||
rest = str::from_slice(s);
|
||||
}
|
||||
}
|
||||
|
|
@ -265,32 +265,32 @@ impl WindowsPath : GenericPath {
|
|||
}
|
||||
}
|
||||
|
||||
pure fn filename() -> option<~str> {
|
||||
pure fn filename() -> Option<~str> {
|
||||
match self.components.len() {
|
||||
0 => none,
|
||||
n => some(copy self.components[n - 1])
|
||||
0 => None,
|
||||
n => Some(copy self.components[n - 1])
|
||||
}
|
||||
}
|
||||
|
||||
pure fn filestem() -> option<~str> {
|
||||
pure fn filestem() -> Option<~str> {
|
||||
match self.filename() {
|
||||
none => none,
|
||||
some(ref f) => {
|
||||
None => None,
|
||||
Some(ref f) => {
|
||||
match str::rfind_char(*f, '.') {
|
||||
some(p) => some(f.slice(0, p)),
|
||||
none => some(copy *f)
|
||||
Some(p) => Some(f.slice(0, p)),
|
||||
None => Some(copy *f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pure fn filetype() -> option<~str> {
|
||||
pure fn filetype() -> Option<~str> {
|
||||
match self.filename() {
|
||||
none => none,
|
||||
some(ref f) => {
|
||||
None => None,
|
||||
Some(ref f) => {
|
||||
match str::rfind_char(*f, '.') {
|
||||
some(p) if p+1 < f.len() => some(f.slice(p+1, f.len())),
|
||||
_ => none
|
||||
Some(p) if p+1 < f.len() => Some(f.slice(p+1, f.len())),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -299,8 +299,8 @@ impl WindowsPath : GenericPath {
|
|||
pure fn with_dirname(d: &str) -> WindowsPath {
|
||||
let dpath = from_str::<WindowsPath>(d);
|
||||
match self.filename() {
|
||||
some(ref f) => dpath.push(*f),
|
||||
none => dpath
|
||||
Some(ref f) => dpath.push(*f),
|
||||
None => dpath
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -311,8 +311,8 @@ impl WindowsPath : GenericPath {
|
|||
|
||||
pure fn with_filestem(s: &str) -> WindowsPath {
|
||||
match self.filetype() {
|
||||
none => self.with_filename(s),
|
||||
some(ref t) =>
|
||||
None => self.with_filename(s),
|
||||
Some(ref t) =>
|
||||
self.with_filename(str::from_slice(s) + "." + *t)
|
||||
}
|
||||
}
|
||||
|
|
@ -320,14 +320,14 @@ impl WindowsPath : GenericPath {
|
|||
pure fn with_filetype(t: &str) -> WindowsPath {
|
||||
if t.len() == 0 {
|
||||
match self.filestem() {
|
||||
none => copy self,
|
||||
some(s) => self.with_filename(s)
|
||||
None => copy self,
|
||||
Some(s) => self.with_filename(s)
|
||||
}
|
||||
} else {
|
||||
let t = ~"." + str::from_slice(t);
|
||||
match self.filestem() {
|
||||
none => self.with_filename(t),
|
||||
some(ref s) =>
|
||||
None => self.with_filename(t),
|
||||
Some(ref s) =>
|
||||
self.with_filename(*s + t)
|
||||
}
|
||||
}
|
||||
|
|
@ -343,11 +343,11 @@ impl WindowsPath : GenericPath {
|
|||
|
||||
pure fn file_path() -> WindowsPath {
|
||||
let cs = match self.filename() {
|
||||
none => ~[],
|
||||
some(ref f) => ~[copy *f]
|
||||
None => ~[],
|
||||
Some(ref f) => ~[copy *f]
|
||||
};
|
||||
return WindowsPath { host: none,
|
||||
device: none,
|
||||
return WindowsPath { host: None,
|
||||
device: None,
|
||||
is_absolute: false,
|
||||
components: cs }
|
||||
}
|
||||
|
|
@ -471,7 +471,7 @@ mod windows {
|
|||
u == '/' as u8 || u == '\\' as u8
|
||||
}
|
||||
|
||||
pure fn extract_unc_prefix(s: &str) -> option<(~str,~str)> {
|
||||
pure fn extract_unc_prefix(s: &str) -> Option<(~str,~str)> {
|
||||
if (s.len() > 1 &&
|
||||
s[0] == '\\' as u8 &&
|
||||
s[1] == '\\' as u8) {
|
||||
|
|
@ -480,15 +480,15 @@ mod windows {
|
|||
if s[i] == '\\' as u8 {
|
||||
let pre = s.slice(2, i);
|
||||
let rest = s.slice(i, s.len());
|
||||
return some((pre, rest));
|
||||
return Some((pre, rest));
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
none
|
||||
None
|
||||
}
|
||||
|
||||
pure fn extract_drive_prefix(s: &str) -> option<(~str,~str)> {
|
||||
pure fn extract_drive_prefix(s: &str) -> Option<(~str,~str)> {
|
||||
unchecked {
|
||||
if (s.len() > 1 &&
|
||||
libc::isalpha(s[0] as libc::c_int) != 0 &&
|
||||
|
|
@ -498,35 +498,35 @@ mod windows {
|
|||
} else {
|
||||
s.slice(2, s.len())
|
||||
};
|
||||
return some((s.slice(0,1), rest));
|
||||
return Some((s.slice(0,1), rest));
|
||||
}
|
||||
none
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_unc_prefixes() {
|
||||
assert extract_unc_prefix("\\\\") == none;
|
||||
assert extract_unc_prefix("\\\\hi") == none;
|
||||
assert extract_unc_prefix("\\\\hi\\") == some((~"hi", ~"\\"));
|
||||
assert extract_unc_prefix("\\\\") == None;
|
||||
assert extract_unc_prefix("\\\\hi") == None;
|
||||
assert extract_unc_prefix("\\\\hi\\") == Some((~"hi", ~"\\"));
|
||||
assert extract_unc_prefix("\\\\hi\\there") ==
|
||||
some((~"hi", ~"\\there"));
|
||||
Some((~"hi", ~"\\there"));
|
||||
assert extract_unc_prefix("\\\\hi\\there\\friends.txt") ==
|
||||
some((~"hi", ~"\\there\\friends.txt"));
|
||||
Some((~"hi", ~"\\there\\friends.txt"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_drive_prefixes() {
|
||||
assert extract_drive_prefix("c") == none;
|
||||
assert extract_drive_prefix("c:") == some((~"c", ~""));
|
||||
assert extract_drive_prefix("d:") == some((~"d", ~""));
|
||||
assert extract_drive_prefix("z:") == some((~"z", ~""));
|
||||
assert extract_drive_prefix("c:\\hi") == some((~"c", ~"\\hi"));
|
||||
assert extract_drive_prefix("d:hi") == some((~"d", ~"hi"));
|
||||
assert extract_drive_prefix("c") == None;
|
||||
assert extract_drive_prefix("c:") == Some((~"c", ~""));
|
||||
assert extract_drive_prefix("d:") == Some((~"d", ~""));
|
||||
assert extract_drive_prefix("z:") == Some((~"z", ~""));
|
||||
assert extract_drive_prefix("c:\\hi") == Some((~"c", ~"\\hi"));
|
||||
assert extract_drive_prefix("d:hi") == Some((~"d", ~"hi"));
|
||||
assert extract_drive_prefix("c:hi\\there.txt") ==
|
||||
some((~"c", ~"hi\\there.txt"));
|
||||
Some((~"c", ~"hi\\there.txt"));
|
||||
assert extract_drive_prefix("c:\\hi\\there.txt") ==
|
||||
some((~"c", ~"\\hi\\there.txt"));
|
||||
Some((~"c", ~"\\hi\\there.txt"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ struct packet_header {
|
|||
#[doc(hidden)]
|
||||
type packet<T: send> = {
|
||||
header: packet_header,
|
||||
mut payload: option<T>,
|
||||
mut payload: Option<T>,
|
||||
};
|
||||
|
||||
#[doc(hidden)]
|
||||
|
|
@ -199,7 +199,7 @@ impl<T: send> packet<T>: has_buffer {
|
|||
fn mk_packet<T: send>() -> packet<T> {
|
||||
{
|
||||
header: packet_header(),
|
||||
mut payload: none
|
||||
mut payload: None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -209,7 +209,7 @@ fn unibuffer<T: send>() -> ~buffer<packet<T>> {
|
|||
header: buffer_header(),
|
||||
data: {
|
||||
header: packet_header(),
|
||||
mut payload: none,
|
||||
mut payload: None,
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -359,8 +359,8 @@ fn send<T: send, Tbuffer: send>(+p: send_packet_buffered<T, Tbuffer>,
|
|||
let p_ = p.unwrap();
|
||||
let p = unsafe { &*p_ };
|
||||
assert ptr::addr_of(p.header) == header;
|
||||
assert p.payload == none;
|
||||
p.payload <- some(payload);
|
||||
assert p.payload == None;
|
||||
p.payload <- Some(payload);
|
||||
let old_state = swap_state_rel(&mut p.header.state, full);
|
||||
match old_state {
|
||||
empty => {
|
||||
|
|
@ -404,11 +404,11 @@ fn recv<T: send, Tbuffer: send>(+p: recv_packet_buffered<T, Tbuffer>) -> T {
|
|||
/** Attempts to receive a message from a pipe.
|
||||
|
||||
Returns `none` if the sender has closed the connection without sending
|
||||
a message, or `some(T)` if a message was received.
|
||||
a message, or `Some(T)` if a message was received.
|
||||
|
||||
*/
|
||||
fn try_recv<T: send, Tbuffer: send>(+p: recv_packet_buffered<T, Tbuffer>)
|
||||
-> option<T>
|
||||
-> Option<T>
|
||||
{
|
||||
let p_ = p.unwrap();
|
||||
let p = unsafe { &*p_ };
|
||||
|
|
@ -433,12 +433,12 @@ fn try_recv<T: send, Tbuffer: send>(+p: recv_packet_buffered<T, Tbuffer>)
|
|||
// optimistic path
|
||||
match p.header.state {
|
||||
full => {
|
||||
let mut payload = none;
|
||||
let mut payload = None;
|
||||
payload <-> p.payload;
|
||||
p.header.state = empty;
|
||||
return some(option::unwrap(payload))
|
||||
return Some(option::unwrap(payload))
|
||||
},
|
||||
terminated => return none,
|
||||
terminated => return None,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
|
@ -475,14 +475,14 @@ fn try_recv<T: send, Tbuffer: send>(+p: recv_packet_buffered<T, Tbuffer>)
|
|||
fail ~"blocking on already blocked packet"
|
||||
},
|
||||
full => {
|
||||
let mut payload = none;
|
||||
let mut payload = None;
|
||||
payload <-> p.payload;
|
||||
let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
|
||||
if !old_task.is_null() {
|
||||
rustrt::rust_task_deref(old_task);
|
||||
}
|
||||
p.header.state = empty;
|
||||
return some(option::unwrap(payload))
|
||||
return Some(option::unwrap(payload))
|
||||
}
|
||||
terminated => {
|
||||
// This assert detects when we've accidentally unsafely
|
||||
|
|
@ -493,7 +493,7 @@ fn try_recv<T: send, Tbuffer: send>(+p: recv_packet_buffered<T, Tbuffer>)
|
|||
if !old_task.is_null() {
|
||||
rustrt::rust_task_deref(old_task);
|
||||
}
|
||||
return none;
|
||||
return None;
|
||||
}
|
||||
}
|
||||
first = false;
|
||||
|
|
@ -603,11 +603,11 @@ fn wait_many<T: selectable>(pkts: &[T]) -> uint {
|
|||
let pos = vec::position(pkts, |p| p.header() == event);
|
||||
|
||||
match pos {
|
||||
some(i) => {
|
||||
Some(i) => {
|
||||
ready_packet = i;
|
||||
data_avail = true;
|
||||
}
|
||||
none => debug!("ignoring spurious event, %?", event)
|
||||
None => debug!("ignoring spurious event, %?", event)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -640,10 +640,10 @@ match select2(a, b) {
|
|||
right((a, none)) {
|
||||
// endpoint b was closed.
|
||||
}
|
||||
left((some(_), b)) {
|
||||
left((Some(_), b)) {
|
||||
// endpoint a received a message
|
||||
}
|
||||
right(a, some(_)) {
|
||||
right(a, Some(_)) {
|
||||
// endpoint b received a message.
|
||||
}
|
||||
}
|
||||
|
|
@ -656,8 +656,8 @@ this case, `select2` may return either `left` or `right`.
|
|||
fn select2<A: send, Ab: send, B: send, Bb: send>(
|
||||
+a: recv_packet_buffered<A, Ab>,
|
||||
+b: recv_packet_buffered<B, Bb>)
|
||||
-> Either<(option<A>, recv_packet_buffered<B, Bb>),
|
||||
(recv_packet_buffered<A, Ab>, option<B>)>
|
||||
-> Either<(Option<A>, recv_packet_buffered<B, Bb>),
|
||||
(recv_packet_buffered<A, Ab>, Option<B>)>
|
||||
{
|
||||
let i = wait_many([a.header(), b.header()]/_);
|
||||
|
||||
|
|
@ -696,7 +696,7 @@ fn select2i<A: selectable, B: selectable>(a: &A, b: &B) -> Either<(), ()> {
|
|||
|
||||
*/
|
||||
fn select<T: send, Tb: send>(+endpoints: ~[recv_packet_buffered<T, Tb>])
|
||||
-> (uint, option<T>, ~[recv_packet_buffered<T, Tb>])
|
||||
-> (uint, Option<T>, ~[recv_packet_buffered<T, Tb>])
|
||||
{
|
||||
let ready = wait_many(endpoints.map(|p| p.header()));
|
||||
let mut remaining = endpoints;
|
||||
|
|
@ -717,13 +717,13 @@ fn send_packet<T: send>(p: *packet<T>) -> send_packet<T> {
|
|||
}
|
||||
|
||||
struct send_packet_buffered<T: send, Tbuffer: send> {
|
||||
let mut p: option<*packet<T>>;
|
||||
let mut buffer: option<buffer_resource<Tbuffer>>;
|
||||
let mut p: Option<*packet<T>>;
|
||||
let mut buffer: Option<buffer_resource<Tbuffer>>;
|
||||
new(p: *packet<T>) {
|
||||
//debug!("take send %?", p);
|
||||
self.p = some(p);
|
||||
self.p = Some(p);
|
||||
unsafe {
|
||||
self.buffer = some(
|
||||
self.buffer = Some(
|
||||
buffer_resource(
|
||||
get_buffer(ptr::addr_of((*p).header))));
|
||||
};
|
||||
|
|
@ -732,8 +732,8 @@ struct send_packet_buffered<T: send, Tbuffer: send> {
|
|||
//if self.p != none {
|
||||
// debug!("drop send %?", option::get(self.p));
|
||||
//}
|
||||
if self.p != none {
|
||||
let mut p = none;
|
||||
if self.p != None {
|
||||
let mut p = None;
|
||||
p <-> self.p;
|
||||
sender_terminate(option::unwrap(p))
|
||||
}
|
||||
|
|
@ -743,26 +743,26 @@ struct send_packet_buffered<T: send, Tbuffer: send> {
|
|||
// } else { "some" }); }
|
||||
}
|
||||
fn unwrap() -> *packet<T> {
|
||||
let mut p = none;
|
||||
let mut p = None;
|
||||
p <-> self.p;
|
||||
option::unwrap(p)
|
||||
}
|
||||
|
||||
pure fn header() -> *packet_header {
|
||||
match self.p {
|
||||
some(packet) => unsafe {
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
fn reuse_buffer() -> buffer_resource<Tbuffer> {
|
||||
//error!("send reuse_buffer");
|
||||
let mut tmp = none;
|
||||
let mut tmp = None;
|
||||
tmp <-> self.buffer;
|
||||
option::unwrap(tmp)
|
||||
}
|
||||
|
|
@ -778,13 +778,13 @@ fn recv_packet<T: send>(p: *packet<T>) -> recv_packet<T> {
|
|||
}
|
||||
|
||||
struct recv_packet_buffered<T: send, Tbuffer: send> : selectable {
|
||||
let mut p: option<*packet<T>>;
|
||||
let mut buffer: option<buffer_resource<Tbuffer>>;
|
||||
let mut p: Option<*packet<T>>;
|
||||
let mut buffer: Option<buffer_resource<Tbuffer>>;
|
||||
new(p: *packet<T>) {
|
||||
//debug!("take recv %?", p);
|
||||
self.p = some(p);
|
||||
self.p = Some(p);
|
||||
unsafe {
|
||||
self.buffer = some(
|
||||
self.buffer = Some(
|
||||
buffer_resource(
|
||||
get_buffer(ptr::addr_of((*p).header))));
|
||||
};
|
||||
|
|
@ -793,8 +793,8 @@ struct recv_packet_buffered<T: send, Tbuffer: send> : selectable {
|
|||
//if self.p != none {
|
||||
// debug!("drop recv %?", option::get(self.p));
|
||||
//}
|
||||
if self.p != none {
|
||||
let mut p = none;
|
||||
if self.p != None {
|
||||
let mut p = None;
|
||||
p <-> self.p;
|
||||
receiver_terminate(option::unwrap(p))
|
||||
}
|
||||
|
|
@ -804,26 +804,26 @@ struct recv_packet_buffered<T: send, Tbuffer: send> : selectable {
|
|||
// } else { "some" }); }
|
||||
}
|
||||
fn unwrap() -> *packet<T> {
|
||||
let mut p = none;
|
||||
let mut p = None;
|
||||
p <-> self.p;
|
||||
option::unwrap(p)
|
||||
}
|
||||
|
||||
pure fn header() -> *packet_header {
|
||||
match self.p {
|
||||
some(packet) => unsafe {
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
fn reuse_buffer() -> buffer_resource<Tbuffer> {
|
||||
//error!("recv reuse_buffer");
|
||||
let mut tmp = none;
|
||||
let mut tmp = None;
|
||||
tmp <-> self.buffer;
|
||||
option::unwrap(tmp)
|
||||
}
|
||||
|
|
@ -852,9 +852,9 @@ fn spawn_service<T: send, Tb: send>(
|
|||
|
||||
// This is some nasty gymnastics required to safely move the pipe
|
||||
// into a new task.
|
||||
let server = ~mut some(server);
|
||||
let server = ~mut Some(server);
|
||||
do task::spawn |move service| {
|
||||
let mut server_ = none;
|
||||
let mut server_ = None;
|
||||
server_ <-> *server;
|
||||
service(option::unwrap(server_))
|
||||
}
|
||||
|
|
@ -876,9 +876,9 @@ fn spawn_service_recv<T: send, Tb: send>(
|
|||
|
||||
// This is some nasty gymnastics required to safely move the pipe
|
||||
// into a new task.
|
||||
let server = ~mut some(server);
|
||||
let server = ~mut Some(server);
|
||||
do task::spawn |move service| {
|
||||
let mut server_ = none;
|
||||
let mut server_ = None;
|
||||
server_ <-> *server;
|
||||
service(option::unwrap(server_))
|
||||
}
|
||||
|
|
@ -915,7 +915,7 @@ trait recv<T: send> {
|
|||
the connection is closed.
|
||||
|
||||
*/
|
||||
fn try_recv() -> option<T>;
|
||||
fn try_recv() -> Option<T>;
|
||||
|
||||
/** Returns true if a message is available or the connection is
|
||||
closed.
|
||||
|
|
@ -925,7 +925,7 @@ trait recv<T: send> {
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
type chan_<T:send> = { mut endp: option<streamp::client::open<T>> };
|
||||
type chan_<T:send> = { mut endp: Option<streamp::client::open<T>> };
|
||||
|
||||
/// An endpoint that can send many messages.
|
||||
enum chan<T:send> {
|
||||
|
|
@ -933,7 +933,7 @@ enum chan<T:send> {
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
type port_<T:send> = { mut endp: option<streamp::server::open<T>> };
|
||||
type port_<T:send> = { mut endp: Option<streamp::server::open<T>> };
|
||||
|
||||
/// An endpoint that can receive many messages.
|
||||
enum port<T:send> {
|
||||
|
|
@ -948,57 +948,57 @@ These allow sending or receiving an unlimited number of messages.
|
|||
fn stream<T:send>() -> (chan<T>, port<T>) {
|
||||
let (c, s) = streamp::init();
|
||||
|
||||
(chan_({ mut endp: some(c) }), port_({ mut endp: some(s) }))
|
||||
(chan_({ mut endp: Some(c) }), port_({ mut endp: Some(s) }))
|
||||
}
|
||||
|
||||
impl<T: send> chan<T>: channel<T> {
|
||||
fn send(+x: T) {
|
||||
let mut endp = none;
|
||||
let mut endp = None;
|
||||
endp <-> self.endp;
|
||||
self.endp = some(
|
||||
self.endp = Some(
|
||||
streamp::client::data(unwrap(endp), x))
|
||||
}
|
||||
|
||||
fn try_send(+x: T) -> bool {
|
||||
let mut endp = none;
|
||||
let mut endp = None;
|
||||
endp <-> self.endp;
|
||||
match move streamp::client::try_data(unwrap(endp), x) {
|
||||
some(move next) => {
|
||||
self.endp = some(next);
|
||||
Some(move next) => {
|
||||
self.endp = Some(next);
|
||||
true
|
||||
}
|
||||
none => false
|
||||
None => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: send> port<T>: recv<T> {
|
||||
fn recv() -> T {
|
||||
let mut endp = none;
|
||||
let mut endp = None;
|
||||
endp <-> self.endp;
|
||||
let streamp::data(x, endp) = pipes::recv(unwrap(endp));
|
||||
self.endp = some(endp);
|
||||
self.endp = Some(endp);
|
||||
x
|
||||
}
|
||||
|
||||
fn try_recv() -> option<T> {
|
||||
let mut endp = none;
|
||||
fn try_recv() -> Option<T> {
|
||||
let mut endp = None;
|
||||
endp <-> self.endp;
|
||||
match move pipes::try_recv(unwrap(endp)) {
|
||||
some(streamp::data(move x, move endp)) => {
|
||||
self.endp = some(endp);
|
||||
some(x)
|
||||
Some(streamp::data(move x, move endp)) => {
|
||||
self.endp = Some(endp);
|
||||
Some(x)
|
||||
}
|
||||
none => none
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
pure fn peek() -> bool unchecked {
|
||||
let mut endp = none;
|
||||
let mut endp = None;
|
||||
endp <-> self.endp;
|
||||
let peek = match 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
|
||||
|
|
@ -1021,19 +1021,19 @@ struct PortSet<T: send> : recv<T> {
|
|||
ch
|
||||
}
|
||||
|
||||
fn try_recv() -> option<T> {
|
||||
let mut result = none;
|
||||
fn try_recv() -> Option<T> {
|
||||
let mut result = None;
|
||||
// we have to swap the ports array so we aren't borrowing
|
||||
// aliasable mutable memory.
|
||||
let mut ports = ~[];
|
||||
ports <-> self.ports;
|
||||
while result == none && ports.len() > 0 {
|
||||
while result == None && ports.len() > 0 {
|
||||
let i = wait_many(ports);
|
||||
match move ports[i].try_recv() {
|
||||
some(move m) => {
|
||||
result = some(m);
|
||||
Some(move m) => {
|
||||
result = Some(m);
|
||||
}
|
||||
none => {
|
||||
None => {
|
||||
// Remove this port.
|
||||
let _ = vec::swap_remove(ports, i);
|
||||
}
|
||||
|
|
@ -1060,8 +1060,8 @@ struct PortSet<T: send> : recv<T> {
|
|||
impl<T: send> port<T>: selectable {
|
||||
pure fn header() -> *packet_header unchecked {
|
||||
match self.endp {
|
||||
some(endp) => endp.header(),
|
||||
none => fail ~"peeking empty stream"
|
||||
Some(endp) => endp.header(),
|
||||
None => fail ~"peeking empty stream"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1071,18 +1071,18 @@ type SharedChan<T: send> = unsafe::Exclusive<chan<T>>;
|
|||
|
||||
impl<T: send> SharedChan<T>: channel<T> {
|
||||
fn send(+x: T) {
|
||||
let mut xx = some(x);
|
||||
let mut xx = Some(x);
|
||||
do self.with |chan| {
|
||||
let mut x = none;
|
||||
let mut x = None;
|
||||
x <-> xx;
|
||||
chan.send(option::unwrap(x))
|
||||
}
|
||||
}
|
||||
|
||||
fn try_send(+x: T) -> bool {
|
||||
let mut xx = some(x);
|
||||
let mut xx = Some(x);
|
||||
do self.with |chan| {
|
||||
let mut x = none;
|
||||
let mut x = None;
|
||||
x <-> xx;
|
||||
chan.try_send(option::unwrap(x))
|
||||
}
|
||||
|
|
@ -1097,7 +1097,7 @@ fn SharedChan<T:send>(+c: chan<T>) -> SharedChan<T> {
|
|||
/// Receive a message from one of two endpoints.
|
||||
trait select2<T: send, U: send> {
|
||||
/// Receive a message or return `none` if a connection closes.
|
||||
fn try_select() -> Either<option<T>, option<U>>;
|
||||
fn try_select() -> Either<Option<T>, Option<U>>;
|
||||
/// Receive a message or fail if a connection closes.
|
||||
fn select() -> Either<T, U>;
|
||||
}
|
||||
|
|
@ -1114,7 +1114,7 @@ impl<T: send, U: send, Left: selectable recv<T>, Right: selectable recv<U>>
|
|||
}
|
||||
}
|
||||
|
||||
fn try_select() -> Either<option<T>, option<U>> {
|
||||
fn try_select() -> Either<Option<T>, Option<U>> {
|
||||
match self {
|
||||
(lp, rp) => match select2i(&lp, &rp) {
|
||||
Left(()) => Left (lp.try_recv()),
|
||||
|
|
@ -1150,13 +1150,13 @@ fn recv_one<T: send>(+port: port_one<T>) -> T {
|
|||
}
|
||||
|
||||
/// Receive a message from a oneshot pipe unless the connection was closed.
|
||||
fn try_recv_one<T: send> (+port: port_one<T>) -> option<T> {
|
||||
fn try_recv_one<T: send> (+port: port_one<T>) -> Option<T> {
|
||||
let message = try_recv(port);
|
||||
|
||||
if message == none { none }
|
||||
if message == None { None }
|
||||
else {
|
||||
let oneshot::send(message) = option::unwrap(message);
|
||||
some(message)
|
||||
Some(message)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1177,8 +1177,8 @@ fn try_send_one<T: send>(+chan: chan_one<T>, +data: T)
|
|||
mod rt {
|
||||
// These are used to hide the option constructors from the
|
||||
// compiler because their names are changing
|
||||
fn make_some<T>(+val: T) -> option<T> { some(val) }
|
||||
fn make_none<T>() -> option<T> { none }
|
||||
fn make_some<T>(+val: T) -> Option<T> { Some(val) }
|
||||
fn make_none<T>() -> Option<T> { None }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -169,12 +169,12 @@ impl Rng {
|
|||
self.choose_option(values).get()
|
||||
}
|
||||
|
||||
/// Choose some(item) randomly, returning none if values is empty
|
||||
fn choose_option<T:copy>(values: ~[T]) -> option<T> {
|
||||
/// Choose Some(item) randomly, returning None if values is empty
|
||||
fn choose_option<T:copy>(values: ~[T]) -> Option<T> {
|
||||
if values.is_empty() {
|
||||
none
|
||||
None
|
||||
} else {
|
||||
some(values[self.gen_uint_range(0u, values.len())])
|
||||
Some(values[self.gen_uint_range(0u, values.len())])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -187,23 +187,23 @@ impl Rng {
|
|||
}
|
||||
|
||||
/**
|
||||
* Choose some(item) respecting the relative weights, returning none if
|
||||
* Choose Some(item) respecting the relative weights, returning none if
|
||||
* the sum of the weights is 0
|
||||
*/
|
||||
fn choose_weighted_option<T:copy>(v: ~[Weighted<T>]) -> option<T> {
|
||||
fn choose_weighted_option<T:copy>(v: ~[Weighted<T>]) -> Option<T> {
|
||||
let mut total = 0u;
|
||||
for v.each |item| {
|
||||
total += item.weight;
|
||||
}
|
||||
if total == 0u {
|
||||
return none;
|
||||
return None;
|
||||
}
|
||||
let chosen = self.gen_uint_range(0u, total);
|
||||
let mut so_far = 0u;
|
||||
for v.each |item| {
|
||||
so_far += item.weight;
|
||||
if so_far > chosen {
|
||||
return some(item.item);
|
||||
return Some(item.item);
|
||||
}
|
||||
}
|
||||
unreachable();
|
||||
|
|
@ -408,8 +408,8 @@ mod tests {
|
|||
#[test]
|
||||
fn choose_option() {
|
||||
let r = rand::rng();
|
||||
assert r.choose_option(~[]) == none::<int>;
|
||||
assert r.choose_option(~[1, 1, 1]) == some(1);
|
||||
assert r.choose_option(~[]) == None::<int>;
|
||||
assert r.choose_option(~[1, 1, 1]) == Some(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -426,12 +426,12 @@ mod tests {
|
|||
fn choose_weighted_option() {
|
||||
let r = rand::rng();
|
||||
assert r.choose_weighted_option(~[{weight: 1u, item: 42}]) ==
|
||||
some(42);
|
||||
Some(42);
|
||||
assert r.choose_weighted_option(~[
|
||||
{weight: 0u, item: 42},
|
||||
{weight: 1u, item: 43}
|
||||
]) == some(43);
|
||||
assert r.choose_weighted_option(~[]) == none::<int>;
|
||||
]) == Some(43);
|
||||
assert r.choose_weighted_option(~[]) == None::<int>;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -280,12 +280,12 @@ fn map_vec<T,U:copy,V:copy>(
|
|||
}
|
||||
|
||||
fn map_opt<T,U:copy,V:copy>(
|
||||
o_t: option<T>, op: fn(T) -> result<V,U>) -> result<option<V>,U> {
|
||||
o_t: Option<T>, op: fn(T) -> result<V,U>) -> result<Option<V>,U> {
|
||||
|
||||
match o_t {
|
||||
none => ok(none),
|
||||
some(t) => match op(t) {
|
||||
ok(v) => ok(some(v)),
|
||||
None => ok(None),
|
||||
Some(t) => match op(t) {
|
||||
ok(v) => ok(Some(v)),
|
||||
err(e) => err(e)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#[forbid(deprecated_pattern)];
|
||||
|
||||
//! Process spawning
|
||||
import option::{some, none};
|
||||
import option::{Some, None};
|
||||
import libc::{pid_t, c_void, c_int};
|
||||
import io::ReaderUtil;
|
||||
|
||||
|
|
@ -68,8 +68,8 @@ trait Program {
|
|||
* The process id of the spawned process
|
||||
*/
|
||||
fn spawn_process(prog: &str, args: &[~str],
|
||||
env: &option<~[(~str,~str)]>,
|
||||
dir: &option<~str>,
|
||||
env: &Option<~[(~str,~str)]>,
|
||||
dir: &Option<~str>,
|
||||
in_fd: c_int, out_fd: c_int, err_fd: c_int)
|
||||
-> pid_t {
|
||||
do with_argv(prog, args) |argv| {
|
||||
|
|
@ -96,12 +96,12 @@ fn with_argv<T>(prog: &str, args: &[~str],
|
|||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn with_envp<T>(env: &option<~[(~str,~str)]>,
|
||||
fn with_envp<T>(env: &Option<~[(~str,~str)]>,
|
||||
cb: fn(*c_void) -> T) -> T {
|
||||
// On posixy systems we can pass a char** for envp, which is
|
||||
// a null-terminated array of "k=v\n" strings.
|
||||
match *env {
|
||||
some(es) if !vec::is_empty(es) => {
|
||||
Some(es) if !vec::is_empty(es) => {
|
||||
let mut tmps = ~[];
|
||||
let mut ptrs = ~[];
|
||||
|
||||
|
|
@ -121,14 +121,14 @@ fn with_envp<T>(env: &option<~[(~str,~str)]>,
|
|||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn with_envp<T>(env: &option<~[(~str,~str)]>,
|
||||
fn with_envp<T>(env: &Option<~[(~str,~str)]>,
|
||||
cb: fn(*c_void) -> T) -> T {
|
||||
// On win32 we pass an "environment block" which is not a char**, but
|
||||
// rather a concatenation of null-terminated k=v\0 sequences, with a final
|
||||
// \0 to terminate.
|
||||
unsafe {
|
||||
match *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;
|
||||
|
|
@ -145,11 +145,11 @@ fn with_envp<T>(env: &option<~[(~str,~str)]>,
|
|||
}
|
||||
}
|
||||
|
||||
fn with_dirp<T>(d: &option<~str>,
|
||||
fn with_dirp<T>(d: &Option<~str>,
|
||||
cb: fn(*libc::c_char) -> T) -> T {
|
||||
match *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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -166,7 +166,7 @@ fn with_dirp<T>(d: &option<~str>,
|
|||
* The process id
|
||||
*/
|
||||
fn run_program(prog: &str, args: &[~str]) -> int {
|
||||
let pid = spawn_process(prog, args, &none, &none,
|
||||
let pid = spawn_process(prog, args, &None, &None,
|
||||
0i32, 0i32, 0i32);
|
||||
if pid == -1 as pid_t { fail; }
|
||||
return waitpid(pid);
|
||||
|
|
@ -193,7 +193,7 @@ fn start_program(prog: &str, args: &[~str]) -> Program {
|
|||
let pipe_output = os::pipe();
|
||||
let pipe_err = os::pipe();
|
||||
let pid =
|
||||
spawn_process(prog, args, &none, &none,
|
||||
spawn_process(prog, args, &None, &None,
|
||||
pipe_input.in, pipe_output.out,
|
||||
pipe_err.out);
|
||||
|
||||
|
|
@ -278,7 +278,7 @@ fn program_output(prog: &str, args: &[~str]) ->
|
|||
let pipe_in = os::pipe();
|
||||
let pipe_out = os::pipe();
|
||||
let pipe_err = os::pipe();
|
||||
let pid = spawn_process(prog, args, &none, &none,
|
||||
let pid = spawn_process(prog, args, &None, &None,
|
||||
pipe_in.in, pipe_out.out, pipe_err.out);
|
||||
|
||||
os::close(pipe_in.in);
|
||||
|
|
@ -415,7 +415,7 @@ mod tests {
|
|||
|
||||
let pid =
|
||||
run::spawn_process(
|
||||
"cat", [], &none, &none,
|
||||
"cat", [], &None, &None,
|
||||
pipe_in.in, pipe_out.out, pipe_err.out);
|
||||
os::close(pipe_in.in);
|
||||
os::close(pipe_out.out);
|
||||
|
|
@ -436,7 +436,7 @@ mod tests {
|
|||
#[test]
|
||||
fn waitpid() {
|
||||
let pid = run::spawn_process("false", [],
|
||||
&none, &none,
|
||||
&None, &None,
|
||||
0i32, 0i32, 0i32);
|
||||
let status = run::waitpid(pid);
|
||||
assert status == 1;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ mod linear {
|
|||
eqfn: pure fn~(x: &K, y: &K) -> bool,
|
||||
resize_at: uint,
|
||||
size: uint,
|
||||
buckets: ~[option<Bucket<K,V>>]})
|
||||
buckets: ~[Option<Bucket<K,V>>]})
|
||||
}
|
||||
|
||||
// FIXME(#3148) -- we could rewrite found_entry
|
||||
|
|
@ -56,7 +56,7 @@ mod linear {
|
|||
eqfn: eqfn,
|
||||
resize_at: resize_at(initial_capacity),
|
||||
size: 0,
|
||||
buckets: vec::from_fn(initial_capacity, |_i| none)})
|
||||
buckets: vec::from_fn(initial_capacity, |_i| None)})
|
||||
}
|
||||
|
||||
priv impl<K, V> LinearMap<K,V> {
|
||||
|
|
@ -101,7 +101,7 @@ mod linear {
|
|||
|
||||
#[inline(always)]
|
||||
pure fn bucket_for_key(&const self,
|
||||
buckets: &[option<Bucket<K,V>>],
|
||||
buckets: &[Option<Bucket<K,V>>],
|
||||
k: &K) -> SearchResult {
|
||||
let hash = self.hashfn(k);
|
||||
self.bucket_for_key_with_hash(buckets, hash, k)
|
||||
|
|
@ -109,15 +109,15 @@ mod linear {
|
|||
|
||||
#[inline(always)]
|
||||
pure fn bucket_for_key_with_hash(&const self,
|
||||
buckets: &[option<Bucket<K,V>>],
|
||||
buckets: &[Option<Bucket<K,V>>],
|
||||
hash: uint,
|
||||
k: &K) -> SearchResult {
|
||||
let _ = for self.bucket_sequence(hash) |i| {
|
||||
match buckets[i] {
|
||||
some(bkt) => if bkt.hash == hash && self.eqfn(k, &bkt.key) {
|
||||
Some(bkt) => if bkt.hash == hash && self.eqfn(k, &bkt.key) {
|
||||
return FoundEntry(i);
|
||||
},
|
||||
none => return FoundHole(i)
|
||||
None => return FoundHole(i)
|
||||
}
|
||||
};
|
||||
return TableFull;
|
||||
|
|
@ -130,11 +130,11 @@ mod linear {
|
|||
let new_capacity = old_capacity * 2;
|
||||
self.resize_at = ((new_capacity as float) * 3.0 / 4.0) as uint;
|
||||
|
||||
let mut old_buckets = vec::from_fn(new_capacity, |_i| none);
|
||||
let mut old_buckets = vec::from_fn(new_capacity, |_i| None);
|
||||
self.buckets <-> old_buckets;
|
||||
|
||||
for uint::range(0, old_capacity) |i| {
|
||||
let mut bucket = none;
|
||||
let mut bucket = None;
|
||||
bucket <-> old_buckets[i];
|
||||
if bucket.is_some() {
|
||||
self.insert_bucket(bucket);
|
||||
|
|
@ -142,7 +142,7 @@ mod linear {
|
|||
}
|
||||
}
|
||||
|
||||
fn insert_bucket(&mut self, +bucket: option<Bucket<K,V>>) {
|
||||
fn insert_bucket(&mut self, +bucket: Option<Bucket<K,V>>) {
|
||||
let {hash, key, value} <- option::unwrap(bucket);
|
||||
let _ = self.insert_internal(hash, key, value);
|
||||
}
|
||||
|
|
@ -156,14 +156,14 @@ mod linear {
|
|||
FoundHole(idx) => {
|
||||
debug!("insert fresh (%?->%?) at idx %?, hash %?",
|
||||
k, v, idx, hash);
|
||||
self.buckets[idx] = some({hash: hash, key: k, value: v});
|
||||
self.buckets[idx] = Some({hash: hash, key: k, value: v});
|
||||
self.size += 1;
|
||||
return true;
|
||||
}
|
||||
FoundEntry(idx) => {
|
||||
debug!("insert overwrite (%?->%?) at idx %?, hash %?",
|
||||
k, v, idx, hash);
|
||||
self.buckets[idx] = some({hash: hash, key: k, value: v});
|
||||
self.buckets[idx] = Some({hash: hash, key: k, value: v});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -171,7 +171,7 @@ mod linear {
|
|||
|
||||
fn search(&self,
|
||||
hash: uint,
|
||||
op: fn(x: &option<Bucket<K,V>>) -> bool) {
|
||||
op: fn(x: &Option<Bucket<K,V>>) -> bool) {
|
||||
let _ = self.bucket_sequence(hash, |i| op(&self.buckets[i]));
|
||||
}
|
||||
}
|
||||
|
|
@ -218,10 +218,10 @@ mod linear {
|
|||
};
|
||||
|
||||
let len_buckets = self.buckets.len();
|
||||
self.buckets[idx] = none;
|
||||
self.buckets[idx] = None;
|
||||
idx = self.next_bucket(idx, len_buckets);
|
||||
while self.buckets[idx].is_some() {
|
||||
let mut bucket = none;
|
||||
let mut bucket = None;
|
||||
bucket <-> self.buckets[idx];
|
||||
self.insert_bucket(bucket);
|
||||
idx = self.next_bucket(idx, len_buckets);
|
||||
|
|
@ -232,7 +232,7 @@ mod linear {
|
|||
|
||||
fn clear(&mut self) {
|
||||
for uint::range(0, self.buckets.len()) |idx| {
|
||||
self.buckets[idx] = none;
|
||||
self.buckets[idx] = None;
|
||||
}
|
||||
self.size = 0;
|
||||
}
|
||||
|
|
@ -292,18 +292,18 @@ mod linear {
|
|||
}
|
||||
|
||||
impl<K,V: copy> LinearMap<K,V> {
|
||||
fn find(&const self, k: &K) -> option<V> {
|
||||
fn find(&const self, k: &K) -> Option<V> {
|
||||
match self.bucket_for_key(self.buckets, k) {
|
||||
FoundEntry(idx) => {
|
||||
// FIXME (#3148): Once we rewrite found_entry, this
|
||||
// failure case won't be necessary
|
||||
match self.buckets[idx] {
|
||||
some(bkt) => {some(copy bkt.value)}
|
||||
none => fail ~"LinearMap::find: internal logic error"
|
||||
Some(bkt) => {Some(copy bkt.value)}
|
||||
None => fail ~"LinearMap::find: internal logic error"
|
||||
}
|
||||
}
|
||||
TableFull | FoundHole(_) => {
|
||||
none
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -362,16 +362,16 @@ fn unshift_char(&s: ~str, ch: char) { s = from_char(ch) + s; }
|
|||
/// Returns a string with leading whitespace removed
|
||||
pure fn trim_left(s: &str) -> ~str {
|
||||
match 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 {
|
||||
match 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) }
|
||||
}
|
||||
|
|
@ -831,7 +831,7 @@ Section: Searching
|
|||
* An `option` containing the byte index of the first matching character
|
||||
* or `none` if there is no match
|
||||
*/
|
||||
pure fn find_char(s: &str, c: char) -> option<uint> {
|
||||
pure fn find_char(s: &str, c: char) -> Option<uint> {
|
||||
find_char_between(s, c, 0u, len(s))
|
||||
}
|
||||
|
||||
|
|
@ -855,7 +855,7 @@ pure fn find_char(s: &str, c: char) -> option<uint> {
|
|||
* `start` must be less than or equal to `len(s)`. `start` must be the
|
||||
* index of a character boundary, as defined by `is_char_boundary`.
|
||||
*/
|
||||
pure fn find_char_from(s: &str, c: char, start: uint) -> option<uint> {
|
||||
pure fn find_char_from(s: &str, c: char, start: uint) -> Option<uint> {
|
||||
find_char_between(s, c, start, len(s))
|
||||
}
|
||||
|
||||
|
|
@ -881,17 +881,17 @@ pure fn find_char_from(s: &str, c: char, start: uint) -> option<uint> {
|
|||
* as defined by `is_char_boundary`.
|
||||
*/
|
||||
pure fn find_char_between(s: &str, c: char, start: uint, end: uint)
|
||||
-> option<uint> {
|
||||
-> Option<uint> {
|
||||
if c < 128u as char {
|
||||
assert start <= end;
|
||||
assert end <= len(s);
|
||||
let mut i = start;
|
||||
let b = c as u8;
|
||||
while i < end {
|
||||
if s[i] == b { return some(i); }
|
||||
if s[i] == b { return Some(i); }
|
||||
i += 1u;
|
||||
}
|
||||
return none;
|
||||
return None;
|
||||
} else {
|
||||
find_between(s, start, end, |x| x == c)
|
||||
}
|
||||
|
|
@ -910,7 +910,7 @@ pure fn find_char_between(s: &str, c: char, start: uint, end: uint)
|
|||
* An `option` containing the byte index of the last matching character
|
||||
* or `none` if there is no match
|
||||
*/
|
||||
pure fn rfind_char(s: &str, c: char) -> option<uint> {
|
||||
pure fn rfind_char(s: &str, c: char) -> Option<uint> {
|
||||
rfind_char_between(s, c, len(s), 0u)
|
||||
}
|
||||
|
||||
|
|
@ -934,7 +934,7 @@ pure fn rfind_char(s: &str, c: char) -> option<uint> {
|
|||
* `start` must be less than or equal to `len(s)`. `start` must be
|
||||
* the index of a character boundary, as defined by `is_char_boundary`.
|
||||
*/
|
||||
pure fn rfind_char_from(s: &str, c: char, start: uint) -> option<uint> {
|
||||
pure fn rfind_char_from(s: &str, c: char, start: uint) -> Option<uint> {
|
||||
rfind_char_between(s, c, start, 0u)
|
||||
}
|
||||
|
||||
|
|
@ -960,7 +960,7 @@ pure fn rfind_char_from(s: &str, c: char, start: uint) -> option<uint> {
|
|||
* as defined by `is_char_boundary`.
|
||||
*/
|
||||
pure fn rfind_char_between(s: &str, c: char, start: uint, end: uint)
|
||||
-> option<uint> {
|
||||
-> Option<uint> {
|
||||
if c < 128u as char {
|
||||
assert start >= end;
|
||||
assert start <= len(s);
|
||||
|
|
@ -968,9 +968,9 @@ pure fn rfind_char_between(s: &str, c: char, start: uint, end: uint)
|
|||
let b = c as u8;
|
||||
while i > end {
|
||||
i -= 1u;
|
||||
if s[i] == b { return some(i); }
|
||||
if s[i] == b { return Some(i); }
|
||||
}
|
||||
return none;
|
||||
return None;
|
||||
} else {
|
||||
rfind_between(s, start, end, |x| x == c)
|
||||
}
|
||||
|
|
@ -990,7 +990,7 @@ pure fn rfind_char_between(s: &str, c: char, start: uint, end: uint)
|
|||
* An `option` containing the byte index of the first matching character
|
||||
* or `none` if there is no match
|
||||
*/
|
||||
pure fn find(s: &str, f: fn(char) -> bool) -> option<uint> {
|
||||
pure fn find(s: &str, f: fn(char) -> bool) -> Option<uint> {
|
||||
find_between(s, 0u, len(s), f)
|
||||
}
|
||||
|
||||
|
|
@ -1015,7 +1015,7 @@ pure fn find(s: &str, f: fn(char) -> bool) -> option<uint> {
|
|||
* index of a character boundary, as defined by `is_char_boundary`.
|
||||
*/
|
||||
pure fn find_from(s: &str, start: uint, f: fn(char)
|
||||
-> bool) -> option<uint> {
|
||||
-> bool) -> Option<uint> {
|
||||
find_between(s, start, len(s), f)
|
||||
}
|
||||
|
||||
|
|
@ -1042,17 +1042,17 @@ pure fn find_from(s: &str, start: uint, f: fn(char)
|
|||
* boundary, as defined by `is_char_boundary`.
|
||||
*/
|
||||
pure fn find_between(s: &str, start: uint, end: uint, f: fn(char) -> bool)
|
||||
-> option<uint> {
|
||||
-> Option<uint> {
|
||||
assert start <= end;
|
||||
assert end <= len(s);
|
||||
assert is_char_boundary(s, start);
|
||||
let mut i = start;
|
||||
while i < end {
|
||||
let {ch, next} = char_range_at(s, i);
|
||||
if f(ch) { return some(i); }
|
||||
if f(ch) { return Some(i); }
|
||||
i = next;
|
||||
}
|
||||
return none;
|
||||
return None;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1069,7 +1069,7 @@ pure fn find_between(s: &str, start: uint, end: uint, f: fn(char) -> bool)
|
|||
* An option containing the byte index of the last matching character
|
||||
* or `none` if there is no match
|
||||
*/
|
||||
pure fn rfind(s: &str, f: fn(char) -> bool) -> option<uint> {
|
||||
pure fn rfind(s: &str, f: fn(char) -> bool) -> Option<uint> {
|
||||
rfind_between(s, len(s), 0u, f)
|
||||
}
|
||||
|
||||
|
|
@ -1094,7 +1094,7 @@ pure fn rfind(s: &str, f: fn(char) -> bool) -> option<uint> {
|
|||
* index of a character boundary, as defined by `is_char_boundary`
|
||||
*/
|
||||
pure fn rfind_from(s: &str, start: uint, f: fn(char) -> bool)
|
||||
-> option<uint> {
|
||||
-> Option<uint> {
|
||||
rfind_between(s, start, 0u, f)
|
||||
}
|
||||
|
||||
|
|
@ -1121,17 +1121,17 @@ pure fn rfind_from(s: &str, start: uint, f: fn(char) -> bool)
|
|||
* boundary, as defined by `is_char_boundary`
|
||||
*/
|
||||
pure fn rfind_between(s: &str, start: uint, end: uint, f: fn(char) -> bool)
|
||||
-> option<uint> {
|
||||
-> Option<uint> {
|
||||
assert start >= end;
|
||||
assert start <= len(s);
|
||||
assert is_char_boundary(s, start);
|
||||
let mut i = start;
|
||||
while i > end {
|
||||
let {ch, prev} = char_range_at_reverse(s, i);
|
||||
if f(ch) { return some(prev); }
|
||||
if f(ch) { return Some(prev); }
|
||||
i = prev;
|
||||
}
|
||||
return none;
|
||||
return None;
|
||||
}
|
||||
|
||||
// Utility used by various searching functions
|
||||
|
|
@ -1154,7 +1154,7 @@ pure fn match_at(haystack: &a/str, needle: &b/str, at: uint) -> bool {
|
|||
* An `option` containing the byte index of the first matching substring
|
||||
* or `none` if there is no match
|
||||
*/
|
||||
pure fn find_str(haystack: &a/str, needle: &b/str) -> option<uint> {
|
||||
pure fn find_str(haystack: &a/str, needle: &b/str) -> Option<uint> {
|
||||
find_str_between(haystack, needle, 0u, len(haystack))
|
||||
}
|
||||
|
||||
|
|
@ -1178,7 +1178,7 @@ pure fn find_str(haystack: &a/str, needle: &b/str) -> option<uint> {
|
|||
* `start` must be less than or equal to `len(s)`
|
||||
*/
|
||||
pure fn find_str_from(haystack: &a/str, needle: &b/str, start: uint)
|
||||
-> option<uint> {
|
||||
-> Option<uint> {
|
||||
find_str_between(haystack, needle, start, len(haystack))
|
||||
}
|
||||
|
||||
|
|
@ -1204,20 +1204,20 @@ pure fn find_str_from(haystack: &a/str, needle: &b/str, start: uint)
|
|||
*/
|
||||
pure fn find_str_between(haystack: &a/str, needle: &b/str, start: uint,
|
||||
end:uint)
|
||||
-> option<uint> {
|
||||
-> Option<uint> {
|
||||
// See Issue #1932 for why this is a naive search
|
||||
assert end <= len(haystack);
|
||||
let needle_len = len(needle);
|
||||
if needle_len == 0u { return some(start); }
|
||||
if needle_len > end { return none; }
|
||||
if needle_len == 0u { return Some(start); }
|
||||
if needle_len > end { return None; }
|
||||
|
||||
let mut i = start;
|
||||
let e = end - needle_len;
|
||||
while i <= e {
|
||||
if match_at(haystack, needle, i) { return some(i); }
|
||||
if match_at(haystack, needle, i) { return Some(i); }
|
||||
i += 1u;
|
||||
}
|
||||
return none;
|
||||
return None;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -2167,11 +2167,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_rfind_char() {
|
||||
assert rfind_char(~"hello", 'l') == some(3u);
|
||||
assert rfind_char(~"hello", 'o') == some(4u);
|
||||
assert rfind_char(~"hello", 'h') == some(0u);
|
||||
assert rfind_char(~"hello", 'z') == none;
|
||||
assert rfind_char(~"ประเทศไทย中华Việt Nam", '华') == some(30u);
|
||||
assert rfind_char(~"hello", 'l') == Some(3u);
|
||||
assert rfind_char(~"hello", 'o') == Some(4u);
|
||||
assert rfind_char(~"hello", 'h') == Some(0u);
|
||||
assert rfind_char(~"hello", 'z') == None;
|
||||
assert rfind_char(~"ประเทศไทย中华Việt Nam", '华') == Some(30u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -2368,43 +2368,43 @@ mod tests {
|
|||
#[test]
|
||||
fn test_find_str() {
|
||||
// byte positions
|
||||
assert find_str(~"banana", ~"apple pie") == none;
|
||||
assert find_str(~"", ~"") == some(0u);
|
||||
assert find_str(~"banana", ~"apple pie") == None;
|
||||
assert find_str(~"", ~"") == Some(0u);
|
||||
|
||||
let data = ~"ประเทศไทย中华Việt Nam";
|
||||
assert find_str(data, ~"") == some(0u);
|
||||
assert find_str(data, ~"ประเ") == some( 0u);
|
||||
assert find_str(data, ~"ะเ") == some( 6u);
|
||||
assert find_str(data, ~"中华") == some(27u);
|
||||
assert find_str(data, ~"ไท华") == none;
|
||||
assert find_str(data, ~"") == Some(0u);
|
||||
assert find_str(data, ~"ประเ") == Some( 0u);
|
||||
assert find_str(data, ~"ะเ") == Some( 6u);
|
||||
assert find_str(data, ~"中华") == Some(27u);
|
||||
assert find_str(data, ~"ไท华") == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_str_between() {
|
||||
// byte positions
|
||||
assert find_str_between(~"", ~"", 0u, 0u) == some(0u);
|
||||
assert find_str_between(~"", ~"", 0u, 0u) == Some(0u);
|
||||
|
||||
let data = ~"abcabc";
|
||||
assert find_str_between(data, ~"ab", 0u, 6u) == some(0u);
|
||||
assert find_str_between(data, ~"ab", 2u, 6u) == some(3u);
|
||||
assert find_str_between(data, ~"ab", 2u, 4u) == none;
|
||||
assert find_str_between(data, ~"ab", 0u, 6u) == Some(0u);
|
||||
assert find_str_between(data, ~"ab", 2u, 6u) == Some(3u);
|
||||
assert find_str_between(data, ~"ab", 2u, 4u) == None;
|
||||
|
||||
let mut data = ~"ประเทศไทย中华Việt Nam";
|
||||
data += data;
|
||||
assert find_str_between(data, ~"", 0u, 43u) == some(0u);
|
||||
assert find_str_between(data, ~"", 6u, 43u) == some(6u);
|
||||
assert find_str_between(data, ~"", 0u, 43u) == Some(0u);
|
||||
assert find_str_between(data, ~"", 6u, 43u) == Some(6u);
|
||||
|
||||
assert find_str_between(data, ~"ประ", 0u, 43u) == some( 0u);
|
||||
assert find_str_between(data, ~"ทศไ", 0u, 43u) == some(12u);
|
||||
assert find_str_between(data, ~"ย中", 0u, 43u) == some(24u);
|
||||
assert find_str_between(data, ~"iệt", 0u, 43u) == some(34u);
|
||||
assert find_str_between(data, ~"Nam", 0u, 43u) == some(40u);
|
||||
assert find_str_between(data, ~"ประ", 0u, 43u) == Some( 0u);
|
||||
assert find_str_between(data, ~"ทศไ", 0u, 43u) == Some(12u);
|
||||
assert find_str_between(data, ~"ย中", 0u, 43u) == Some(24u);
|
||||
assert find_str_between(data, ~"iệt", 0u, 43u) == Some(34u);
|
||||
assert find_str_between(data, ~"Nam", 0u, 43u) == Some(40u);
|
||||
|
||||
assert find_str_between(data, ~"ประ", 43u, 86u) == some(43u);
|
||||
assert find_str_between(data, ~"ทศไ", 43u, 86u) == some(55u);
|
||||
assert find_str_between(data, ~"ย中", 43u, 86u) == some(67u);
|
||||
assert find_str_between(data, ~"iệt", 43u, 86u) == some(77u);
|
||||
assert find_str_between(data, ~"Nam", 43u, 86u) == some(83u);
|
||||
assert find_str_between(data, ~"ประ", 43u, 86u) == Some(43u);
|
||||
assert find_str_between(data, ~"ทศไ", 43u, 86u) == Some(55u);
|
||||
assert find_str_between(data, ~"ย中", 43u, 86u) == Some(67u);
|
||||
assert find_str_between(data, ~"iệt", 43u, 86u) == Some(77u);
|
||||
assert find_str_between(data, ~"Nam", 43u, 86u) == Some(83u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ enum SchedMode {
|
|||
*/
|
||||
type SchedOpts = {
|
||||
mode: SchedMode,
|
||||
foreign_stack_size: option<uint>
|
||||
foreign_stack_size: Option<uint>
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -172,8 +172,8 @@ type SchedOpts = {
|
|||
type TaskOpts = {
|
||||
linked: bool,
|
||||
supervised: bool,
|
||||
notify_chan: option<comm::Chan<Notification>>,
|
||||
sched: option<SchedOpts>,
|
||||
notify_chan: Option<comm::Chan<Notification>>,
|
||||
sched: Option<SchedOpts>,
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -193,7 +193,7 @@ type TaskOpts = {
|
|||
enum TaskBuilder = {
|
||||
opts: TaskOpts,
|
||||
gen_body: fn@(+fn~()) -> fn~(),
|
||||
can_not_copy: option<util::NonCopyable>,
|
||||
can_not_copy: Option<util::NonCopyable>,
|
||||
mut consumed: bool,
|
||||
};
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ fn task() -> TaskBuilder {
|
|||
TaskBuilder({
|
||||
opts: default_task_opts(),
|
||||
gen_body: |body| body, // Identity function
|
||||
can_not_copy: none,
|
||||
can_not_copy: None,
|
||||
mut consumed: false,
|
||||
})
|
||||
}
|
||||
|
|
@ -217,7 +217,7 @@ priv impl TaskBuilder {
|
|||
fail ~"Cannot copy a task_builder"; // Fake move mode on self
|
||||
}
|
||||
self.consumed = true;
|
||||
TaskBuilder({ can_not_copy: none, mut consumed: false, with *self })
|
||||
TaskBuilder({ can_not_copy: None, mut consumed: false, with *self })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -229,7 +229,7 @@ impl TaskBuilder {
|
|||
fn unlinked() -> TaskBuilder {
|
||||
TaskBuilder({
|
||||
opts: { linked: false with self.opts },
|
||||
can_not_copy: none,
|
||||
can_not_copy: None,
|
||||
with *self.consume()
|
||||
})
|
||||
}
|
||||
|
|
@ -241,7 +241,7 @@ impl TaskBuilder {
|
|||
fn supervised() -> TaskBuilder {
|
||||
TaskBuilder({
|
||||
opts: { linked: false, supervised: true with self.opts },
|
||||
can_not_copy: none,
|
||||
can_not_copy: None,
|
||||
with *self.consume()
|
||||
})
|
||||
}
|
||||
|
|
@ -252,7 +252,7 @@ impl TaskBuilder {
|
|||
fn linked() -> TaskBuilder {
|
||||
TaskBuilder({
|
||||
opts: { linked: true, supervised: false with self.opts },
|
||||
can_not_copy: none,
|
||||
can_not_copy: None,
|
||||
with *self.consume()
|
||||
})
|
||||
}
|
||||
|
|
@ -296,17 +296,17 @@ impl TaskBuilder {
|
|||
|
||||
// Reconfigure self to use a notify channel.
|
||||
TaskBuilder({
|
||||
opts: { notify_chan: some(ch) with self.opts },
|
||||
can_not_copy: none,
|
||||
opts: { notify_chan: Some(ch) with self.opts },
|
||||
can_not_copy: None,
|
||||
with *self.consume()
|
||||
})
|
||||
}
|
||||
/// Configure a custom scheduler mode for the task.
|
||||
fn sched_mode(mode: SchedMode) -> TaskBuilder {
|
||||
TaskBuilder({
|
||||
opts: { sched: some({ mode: mode, foreign_stack_size: none})
|
||||
opts: { sched: Some({ mode: mode, foreign_stack_size: None})
|
||||
with self.opts },
|
||||
can_not_copy: none,
|
||||
can_not_copy: None,
|
||||
with *self.consume()
|
||||
})
|
||||
}
|
||||
|
|
@ -327,7 +327,7 @@ impl TaskBuilder {
|
|||
let prev_gen_body = self.gen_body;
|
||||
TaskBuilder({
|
||||
gen_body: |body| { wrapper(prev_gen_body(body)) },
|
||||
can_not_copy: none,
|
||||
can_not_copy: None,
|
||||
with *self.consume()
|
||||
})
|
||||
}
|
||||
|
|
@ -350,7 +350,7 @@ impl TaskBuilder {
|
|||
}
|
||||
/// Runs a task, while transfering ownership of one argument to the child.
|
||||
fn spawn_with<A: send>(+arg: A, +f: fn~(+A)) {
|
||||
let arg = ~mut some(arg);
|
||||
let arg = ~mut Some(arg);
|
||||
do self.spawn {
|
||||
f(option::swap_unwrap(arg))
|
||||
}
|
||||
|
|
@ -409,9 +409,9 @@ impl TaskBuilder {
|
|||
fn try<T: send>(+f: fn~() -> T) -> result<T,()> {
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
let mut result = none;
|
||||
let mut result = None;
|
||||
|
||||
do self.future_result(|+r| { result = some(r); }).spawn {
|
||||
do self.future_result(|+r| { result = Some(r); }).spawn {
|
||||
comm::send(ch, f());
|
||||
}
|
||||
match future::get(&option::unwrap(result)) {
|
||||
|
|
@ -435,8 +435,8 @@ fn default_task_opts() -> TaskOpts {
|
|||
{
|
||||
linked: true,
|
||||
supervised: false,
|
||||
notify_chan: none,
|
||||
sched: none
|
||||
notify_chan: None,
|
||||
sched: None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -734,9 +734,9 @@ type TaskGroupData = {
|
|||
// tasks in this group.
|
||||
mut descendants: TaskSet,
|
||||
};
|
||||
type TaskGroupArc = unsafe::Exclusive<option<TaskGroupData>>;
|
||||
type TaskGroupArc = unsafe::Exclusive<Option<TaskGroupData>>;
|
||||
|
||||
type TaskGroupInner = &mut option<TaskGroupData>;
|
||||
type TaskGroupInner = &mut Option<TaskGroupData>;
|
||||
|
||||
// A taskgroup is 'dead' when nothing can cause it to fail; only members can.
|
||||
pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool {
|
||||
|
|
@ -759,11 +759,11 @@ type AncestorNode = {
|
|||
// FIXME(#3068): Make the generation counter togglable with #[cfg(debug)].
|
||||
generation: uint,
|
||||
// Should really be an immutable non-option. This way appeases borrowck.
|
||||
mut parent_group: option<TaskGroupArc>,
|
||||
mut parent_group: Option<TaskGroupArc>,
|
||||
// Recursive rest of the list.
|
||||
mut ancestors: AncestorList,
|
||||
};
|
||||
enum AncestorList = option<unsafe::Exclusive<AncestorNode>>;
|
||||
enum AncestorList = Option<unsafe::Exclusive<AncestorNode>>;
|
||||
|
||||
// Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety.
|
||||
#[inline(always)]
|
||||
|
|
@ -783,10 +783,10 @@ fn access_ancestors<U>(x: &unsafe::Exclusive<AncestorNode>,
|
|||
// taskgroups that forward_blk already ran on successfully (Note: bail_blk
|
||||
// is NOT called on the block that forward_blk broke on!).
|
||||
// (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list.
|
||||
// FIXME(#2190): Change option<fn@(...)> to option<fn&(...)>, to save on
|
||||
// FIXME(#2190): Change Option<fn@(...)> to Option<fn&(...)>, to save on
|
||||
// allocations. Once that bug is fixed, changing the sigil should suffice.
|
||||
fn each_ancestor(list: &mut AncestorList,
|
||||
bail_opt: option<fn@(TaskGroupInner)>,
|
||||
bail_opt: Option<fn@(TaskGroupInner)>,
|
||||
forward_blk: fn(TaskGroupInner) -> bool)
|
||||
-> bool {
|
||||
// "Kickoff" call - there was no last generation.
|
||||
|
|
@ -795,11 +795,11 @@ fn each_ancestor(list: &mut AncestorList,
|
|||
// Recursively iterates, and coalesces afterwards if needed. Returns
|
||||
// whether or not unwinding is needed (i.e., !successful iteration).
|
||||
fn coalesce(list: &mut AncestorList,
|
||||
bail_opt: option<fn@(TaskGroupInner)>,
|
||||
bail_opt: Option<fn@(TaskGroupInner)>,
|
||||
forward_blk: fn(TaskGroupInner) -> bool,
|
||||
last_generation: uint) -> bool {
|
||||
// Need to swap the list out to use it, to appease borrowck.
|
||||
let tmp_list = util::replace(list, AncestorList(none));
|
||||
let tmp_list = util::replace(list, AncestorList(None));
|
||||
let (coalesce_this, early_break) =
|
||||
iterate(&tmp_list, bail_opt, forward_blk, last_generation);
|
||||
// What should our next ancestor end up being?
|
||||
|
|
@ -815,7 +815,7 @@ fn each_ancestor(list: &mut AncestorList,
|
|||
}
|
||||
|
||||
// Returns an optional list-to-coalesce and whether unwinding is needed.
|
||||
// option<ancestor_list>:
|
||||
// Option<ancestor_list>:
|
||||
// Whether or not the ancestor taskgroup being iterated over is
|
||||
// dead or not; i.e., it has no more tasks left in it, whether or not
|
||||
// it has descendants. If dead, the caller shall coalesce it away.
|
||||
|
|
@ -823,9 +823,9 @@ fn each_ancestor(list: &mut AncestorList,
|
|||
// True if the supplied block did 'break', here or in any recursive
|
||||
// calls. If so, must call the unwinder on all previous nodes.
|
||||
fn iterate(ancestors: &AncestorList,
|
||||
bail_opt: option<fn@(TaskGroupInner)>,
|
||||
bail_opt: Option<fn@(TaskGroupInner)>,
|
||||
forward_blk: fn(TaskGroupInner) -> bool,
|
||||
last_generation: uint) -> (option<AncestorList>, bool) {
|
||||
last_generation: uint) -> (Option<AncestorList>, bool) {
|
||||
// At each step of iteration, three booleans are at play which govern
|
||||
// how the iteration should behave.
|
||||
// 'nobe_is_dead' - Should the list should be coalesced at this point?
|
||||
|
|
@ -837,7 +837,7 @@ fn each_ancestor(list: &mut AncestorList,
|
|||
|
||||
// The map defaults to none, because if ancestors is none, we're at
|
||||
// the end of the list, which doesn't make sense to coalesce.
|
||||
return do (**ancestors).map_default((none,false)) |ancestor_arc| {
|
||||
return do (**ancestors).map_default((None,false)) |ancestor_arc| {
|
||||
// NB: Takes a lock! (this ancestor node)
|
||||
do access_ancestors(&ancestor_arc) |nobe| {
|
||||
// Check monotonicity
|
||||
|
|
@ -852,8 +852,8 @@ fn each_ancestor(list: &mut AncestorList,
|
|||
// Decide whether this group is dead. Note that the
|
||||
// group being *dead* is disjoint from it *failing*.
|
||||
nobe_is_dead = match *tg_opt {
|
||||
some(ref tg) => taskgroup_is_dead(tg),
|
||||
none => nobe_is_dead
|
||||
Some(ref tg) => taskgroup_is_dead(tg),
|
||||
None => nobe_is_dead
|
||||
};
|
||||
// Call iterator block. (If the group is dead, it's
|
||||
// safe to skip it. This will leave our *rust_task
|
||||
|
|
@ -889,21 +889,21 @@ fn each_ancestor(list: &mut AncestorList,
|
|||
if nobe_is_dead {
|
||||
// Swap the list out here; the caller replaces us with it.
|
||||
let rest = util::replace(&mut nobe.ancestors,
|
||||
AncestorList(none));
|
||||
(some(rest), need_unwind)
|
||||
AncestorList(None));
|
||||
(Some(rest), need_unwind)
|
||||
} else {
|
||||
(none, need_unwind)
|
||||
(None, need_unwind)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper around exclusive::with that appeases borrowck.
|
||||
fn with_parent_tg<U>(parent_group: &mut option<TaskGroupArc>,
|
||||
fn with_parent_tg<U>(parent_group: &mut Option<TaskGroupArc>,
|
||||
blk: fn(TaskGroupInner) -> U) -> U {
|
||||
// If this trips, more likely the problem is 'blk' failed inside.
|
||||
let tmp_arc = option::swap_unwrap(parent_group);
|
||||
let result = do access_group(&tmp_arc) |tg_opt| { blk(tg_opt) };
|
||||
*parent_group <- some(tmp_arc);
|
||||
*parent_group <- Some(tmp_arc);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
|
@ -917,9 +917,9 @@ struct Tcb {
|
|||
// Lists of tasks who will kill us if they fail, but whom we won't kill.
|
||||
let mut ancestors: AncestorList;
|
||||
let is_main: bool;
|
||||
let notifier: option<AutoNotify>;
|
||||
let notifier: Option<AutoNotify>;
|
||||
new(me: *rust_task, -tasks: TaskGroupArc, -ancestors: AncestorList,
|
||||
is_main: bool, -notifier: option<AutoNotify>) {
|
||||
is_main: bool, -notifier: Option<AutoNotify>) {
|
||||
self.me = me;
|
||||
self.tasks = tasks;
|
||||
self.ancestors = ancestors;
|
||||
|
|
@ -945,7 +945,7 @@ struct Tcb {
|
|||
// It doesn't matter whether this happens before or after dealing with
|
||||
// our own taskgroup, so long as both happen before we die. We need to
|
||||
// remove ourself from every ancestor we can, so no cleanup; no break.
|
||||
for each_ancestor(&mut self.ancestors, none) |ancestor_group| {
|
||||
for each_ancestor(&mut self.ancestors, None) |ancestor_group| {
|
||||
leave_taskgroup(ancestor_group, self.me, false);
|
||||
};
|
||||
}
|
||||
|
|
@ -966,13 +966,13 @@ struct AutoNotify {
|
|||
|
||||
fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task,
|
||||
is_member: bool) -> bool {
|
||||
let newstate = util::replace(state, none);
|
||||
let newstate = util::replace(state, None);
|
||||
// If 'none', the group was failing. Can't enlist.
|
||||
if newstate.is_some() {
|
||||
let group = option::unwrap(newstate);
|
||||
taskset_insert(if is_member { &mut group.members }
|
||||
else { &mut group.descendants }, me);
|
||||
*state = some(group);
|
||||
*state = Some(group);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
|
@ -981,13 +981,13 @@ fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task,
|
|||
|
||||
// NB: Runs in destructor/post-exit context. Can't 'fail'.
|
||||
fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, is_member: bool) {
|
||||
let newstate = util::replace(state, none);
|
||||
let newstate = util::replace(state, None);
|
||||
// If 'none', already failing and we've already gotten a kill signal.
|
||||
if newstate.is_some() {
|
||||
let group = option::unwrap(newstate);
|
||||
taskset_remove(if is_member { &mut group.members }
|
||||
else { &mut group.descendants }, me);
|
||||
*state = some(group);
|
||||
*state = Some(group);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1001,7 +1001,7 @@ fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) {
|
|||
// so if we're failing, all concurrently exiting tasks must wait for us.
|
||||
// To do it differently, we'd have to use the runtime's task refcounting,
|
||||
// but that could leave task structs around long after their task exited.
|
||||
let newstate = util::replace(state, none);
|
||||
let newstate = util::replace(state, None);
|
||||
// Might already be none, if somebody is failing simultaneously.
|
||||
// That's ok; only one task needs to do the dirty work. (Might also
|
||||
// see 'none' if somebody already failed and we got a kill signal.)
|
||||
|
|
@ -1021,7 +1021,7 @@ fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) {
|
|||
if is_main {
|
||||
rustrt::rust_task_kill_all(me);
|
||||
}
|
||||
// Do NOT restore state to some(..)! It stays none to indicate
|
||||
// Do NOT restore state to Some(..)! It stays none to indicate
|
||||
// that the whole taskgroup is failing, to forbid new spawns.
|
||||
}
|
||||
// (note: multiple tasks may reach this point)
|
||||
|
|
@ -1042,20 +1042,20 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
|
|||
*######################################################################*/
|
||||
let spawner_group = match 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);
|
||||
let tasks =
|
||||
unsafe::exclusive(some({ mut members: members,
|
||||
unsafe::exclusive(Some({ mut members: members,
|
||||
mut descendants: new_taskset() }));
|
||||
// Main task/group has no ancestors, no notifier, etc.
|
||||
let group =
|
||||
@Tcb(spawner, tasks, AncestorList(none), true, none);
|
||||
@Tcb(spawner, tasks, AncestorList(None), true, None);
|
||||
unsafe { local_set(spawner, taskgroup_key!(), group); }
|
||||
group
|
||||
}
|
||||
some(group) => group
|
||||
Some(group) => group
|
||||
};
|
||||
/*######################################################################*
|
||||
* Step 2. Process spawn options for child.
|
||||
|
|
@ -1069,7 +1069,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
|
|||
(g, a, spawner_group.is_main)
|
||||
} else {
|
||||
// Child is in a separate group from spawner.
|
||||
let g = unsafe::exclusive(some({ mut members: new_taskset(),
|
||||
let g = unsafe::exclusive(Some({ mut members: new_taskset(),
|
||||
mut descendants: new_taskset() }));
|
||||
let a = if supervised {
|
||||
// Child's ancestors start with the spawner.
|
||||
|
|
@ -1079,18 +1079,18 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
|
|||
// it should be enabled only in debug builds.
|
||||
let new_generation =
|
||||
match *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.
|
||||
AncestorList(some(unsafe::exclusive(
|
||||
AncestorList(Some(unsafe::exclusive(
|
||||
{ generation: new_generation,
|
||||
mut parent_group: some(spawner_group.tasks.clone()),
|
||||
mut parent_group: Some(spawner_group.tasks.clone()),
|
||||
mut ancestors: old_ancestors })))
|
||||
} else {
|
||||
// Child has no ancestors.
|
||||
AncestorList(none)
|
||||
AncestorList(None)
|
||||
};
|
||||
(g,a, false)
|
||||
};
|
||||
|
|
@ -1098,16 +1098,16 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
|
|||
fn share_ancestors(ancestors: &mut AncestorList) -> AncestorList {
|
||||
// Appease the borrow-checker. Really this wants to be written as:
|
||||
// match ancestors
|
||||
// some(ancestor_arc) { ancestor_list(some(ancestor_arc.clone())) }
|
||||
// Some(ancestor_arc) { ancestor_list(Some(ancestor_arc.clone())) }
|
||||
// none { ancestor_list(none) }
|
||||
let tmp = util::replace(&mut **ancestors, none);
|
||||
let tmp = util::replace(&mut **ancestors, None);
|
||||
if tmp.is_some() {
|
||||
let ancestor_arc = option::unwrap(tmp);
|
||||
let result = ancestor_arc.clone();
|
||||
**ancestors <- some(ancestor_arc);
|
||||
AncestorList(some(result))
|
||||
**ancestors <- Some(ancestor_arc);
|
||||
AncestorList(Some(result))
|
||||
} else {
|
||||
AncestorList(none)
|
||||
AncestorList(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1117,15 +1117,15 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) {
|
|||
gen_child_taskgroup(opts.linked, opts.supervised);
|
||||
|
||||
unsafe {
|
||||
let child_data = ~mut some((child_tg, ancestors, f));
|
||||
let child_data = ~mut Some((child_tg, ancestors, f));
|
||||
// Being killed with the unsafe task/closure pointers would leak them.
|
||||
do unkillable {
|
||||
// Agh. Get move-mode items into the closure. FIXME (#2829)
|
||||
let (child_tg, ancestors, f) = option::swap_unwrap(child_data);
|
||||
// Create child task.
|
||||
let new_task = match 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.
|
||||
|
|
@ -1152,9 +1152,9 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) {
|
|||
// (4) ...and runs the provided body function.
|
||||
fn make_child_wrapper(child: *rust_task, +child_arc: TaskGroupArc,
|
||||
+ancestors: AncestorList, is_main: bool,
|
||||
notify_chan: option<comm::Chan<Notification>>,
|
||||
notify_chan: Option<comm::Chan<Notification>>,
|
||||
+f: fn~()) -> fn~() {
|
||||
let child_data = ~mut some((child_arc, ancestors));
|
||||
let child_data = ~mut Some((child_arc, ancestors));
|
||||
return fn~() {
|
||||
// Agh. Get move-mode items into the closure. FIXME (#2829)
|
||||
let mut (child_arc, ancestors) = option::swap_unwrap(child_data);
|
||||
|
|
@ -1191,7 +1191,7 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) {
|
|||
};
|
||||
// Attempt to join every ancestor group.
|
||||
result =
|
||||
for each_ancestor(ancestors, some(bail)) |ancestor_tg| {
|
||||
for each_ancestor(ancestors, Some(bail)) |ancestor_tg| {
|
||||
// Enlist as a descendant, not as an actual member.
|
||||
// Descendants don't kill ancestor groups on failure.
|
||||
if !enlist_in_taskgroup(ancestor_tg, child, false) {
|
||||
|
|
@ -1210,7 +1210,7 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) {
|
|||
}
|
||||
|
||||
fn new_task_in_new_sched(opts: SchedOpts) -> *rust_task {
|
||||
if opts.foreign_stack_size != none {
|
||||
if opts.foreign_stack_size != None {
|
||||
fail ~"foreign_stack_size scheduler option unimplemented";
|
||||
}
|
||||
|
||||
|
|
@ -1277,7 +1277,7 @@ impl<T: owned> @T: LocalData { }
|
|||
// heavily in future, this could be made more efficient with a proper map.
|
||||
type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData);
|
||||
// Has to be a pointer at outermost layer; the foreign call returns void *.
|
||||
type TaskLocalMap = @dvec::DVec<option<TaskLocalElement>>;
|
||||
type TaskLocalMap = @dvec::DVec<Option<TaskLocalElement>>;
|
||||
|
||||
extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe {
|
||||
assert !map_ptr.is_null();
|
||||
|
|
@ -1318,16 +1318,16 @@ unsafe fn key_to_key_value<T: owned>(
|
|||
pair.first()
|
||||
}
|
||||
|
||||
// If returning some(..), returns with @T with the map's reference. Careful!
|
||||
// If returning Some(..), returns with @T with the map's reference. Careful!
|
||||
unsafe fn local_data_lookup<T: owned>(
|
||||
map: TaskLocalMap, key: LocalDataKey<T>)
|
||||
-> option<(uint, *libc::c_void)> {
|
||||
-> Option<(uint, *libc::c_void)> {
|
||||
|
||||
let key_value = key_to_key_value(key);
|
||||
let map_pos = (*map).position(|entry|
|
||||
match entry {
|
||||
some((k,_,_)) => k == key_value,
|
||||
none => false
|
||||
Some((k,_,_)) => k == key_value,
|
||||
None => false
|
||||
}
|
||||
);
|
||||
do map_pos.map |index| {
|
||||
|
|
@ -1339,7 +1339,7 @@ unsafe fn local_data_lookup<T: owned>(
|
|||
|
||||
unsafe fn local_get_helper<T: owned>(
|
||||
task: *rust_task, key: LocalDataKey<T>,
|
||||
do_pop: bool) -> option<@T> {
|
||||
do_pop: bool) -> Option<@T> {
|
||||
|
||||
let map = get_task_local_map(task);
|
||||
// Interpreturn our findings from the map
|
||||
|
|
@ -1352,7 +1352,7 @@ unsafe fn local_get_helper<T: owned>(
|
|||
let data: @T = unsafe::transmute(data_ptr);
|
||||
unsafe::bump_box_refcount(data);
|
||||
if do_pop {
|
||||
(*map).set_elt(index, none);
|
||||
(*map).set_elt(index, None);
|
||||
}
|
||||
data
|
||||
}
|
||||
|
|
@ -1360,14 +1360,14 @@ unsafe fn local_get_helper<T: owned>(
|
|||
|
||||
unsafe fn local_pop<T: owned>(
|
||||
task: *rust_task,
|
||||
key: LocalDataKey<T>) -> option<@T> {
|
||||
key: LocalDataKey<T>) -> Option<@T> {
|
||||
|
||||
local_get_helper(task, key, true)
|
||||
}
|
||||
|
||||
unsafe fn local_get<T: owned>(
|
||||
task: *rust_task,
|
||||
key: LocalDataKey<T>) -> option<@T> {
|
||||
key: LocalDataKey<T>) -> Option<@T> {
|
||||
|
||||
local_get_helper(task, key, false)
|
||||
}
|
||||
|
|
@ -1386,19 +1386,19 @@ unsafe fn local_set<T: owned>(
|
|||
let data_ptr = unsafe::reinterpret_cast(data);
|
||||
let data_box = data as LocalData;
|
||||
// Construct new entry to store in the map.
|
||||
let new_entry = some((keyval, data_ptr, data_box));
|
||||
let new_entry = Some((keyval, data_ptr, data_box));
|
||||
// Find a place to put it.
|
||||
match 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.
|
||||
match (*map).position(|x| x == none) {
|
||||
some(empty_index) => (*map).set_elt(empty_index, new_entry),
|
||||
none => (*map).push(new_entry)
|
||||
match (*map).position(|x| x == None) {
|
||||
Some(empty_index) => (*map).set_elt(empty_index, new_entry),
|
||||
None => (*map).push(new_entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1406,7 +1406,7 @@ unsafe fn local_set<T: owned>(
|
|||
|
||||
unsafe fn local_modify<T: owned>(
|
||||
task: *rust_task, key: LocalDataKey<T>,
|
||||
modify_fn: fn(option<@T>) -> option<@T>) {
|
||||
modify_fn: fn(Option<@T>) -> Option<@T>) {
|
||||
|
||||
// Could be more efficient by doing the lookup work, but this is easy.
|
||||
let newdata = modify_fn(local_pop(task, key));
|
||||
|
|
@ -1421,7 +1421,7 @@ unsafe fn local_modify<T: owned>(
|
|||
* reference that was originally created to insert it.
|
||||
*/
|
||||
unsafe fn local_data_pop<T: owned>(
|
||||
key: LocalDataKey<T>) -> option<@T> {
|
||||
key: LocalDataKey<T>) -> Option<@T> {
|
||||
|
||||
local_pop(rustrt::rust_get_task(), key)
|
||||
}
|
||||
|
|
@ -1430,7 +1430,7 @@ unsafe fn local_data_pop<T: owned>(
|
|||
* table until explicitly removed.
|
||||
*/
|
||||
unsafe fn local_data_get<T: owned>(
|
||||
key: LocalDataKey<T>) -> option<@T> {
|
||||
key: LocalDataKey<T>) -> Option<@T> {
|
||||
|
||||
local_get(rustrt::rust_get_task(), key)
|
||||
}
|
||||
|
|
@ -1449,7 +1449,7 @@ unsafe fn local_data_set<T: owned>(
|
|||
*/
|
||||
unsafe fn local_data_modify<T: owned>(
|
||||
key: LocalDataKey<T>,
|
||||
modify_fn: fn(option<@T>) -> option<@T>) {
|
||||
modify_fn: fn(Option<@T>) -> Option<@T>) {
|
||||
|
||||
local_modify(rustrt::rust_get_task(), key, modify_fn)
|
||||
}
|
||||
|
|
@ -1570,7 +1570,7 @@ fn test_spawn_linked_sup_fail_up() { // child fails; parent fails
|
|||
let b0 = task();
|
||||
let b1 = TaskBuilder({
|
||||
opts: { linked: true, supervised: true with b0.opts },
|
||||
can_not_copy: none,
|
||||
can_not_copy: None,
|
||||
with *b0
|
||||
});
|
||||
do b1.spawn { fail; }
|
||||
|
|
@ -1583,7 +1583,7 @@ fn test_spawn_linked_sup_fail_down() { // parent fails; child fails
|
|||
let b0 = task();
|
||||
let b1 = TaskBuilder({
|
||||
opts: { linked: true, supervised: true with b0.opts },
|
||||
can_not_copy: none,
|
||||
can_not_copy: None,
|
||||
with *b0
|
||||
});
|
||||
do b1.spawn { loop { task::yield(); } }
|
||||
|
|
@ -1670,7 +1670,7 @@ fn test_spawn_raw_notify() {
|
|||
let notify_ch = comm::chan(notify_po);
|
||||
|
||||
let opts = {
|
||||
notify_chan: some(notify_ch)
|
||||
notify_chan: Some(notify_ch)
|
||||
with default_task_opts()
|
||||
};
|
||||
do spawn_raw(opts) {
|
||||
|
|
@ -1681,7 +1681,7 @@ fn test_spawn_raw_notify() {
|
|||
|
||||
let opts = {
|
||||
linked: false,
|
||||
notify_chan: some(notify_ch)
|
||||
notify_chan: Some(notify_ch)
|
||||
with default_task_opts()
|
||||
};
|
||||
do spawn_raw(opts) {
|
||||
|
|
@ -1720,12 +1720,12 @@ fn test_add_wrapper() {
|
|||
#[test]
|
||||
#[ignore(cfg(windows))]
|
||||
fn test_future_result() {
|
||||
let mut result = none;
|
||||
do task().future_result(|+r| { result = some(r); }).spawn { }
|
||||
let mut result = None;
|
||||
do task().future_result(|+r| { result = Some(r); }).spawn { }
|
||||
assert future::get(&option::unwrap(result)) == Success;
|
||||
|
||||
result = none;
|
||||
do task().future_result(|+r| { result = some(r); }).unlinked().spawn {
|
||||
result = None;
|
||||
do task().future_result(|+r| { result = Some(r); }).unlinked().spawn {
|
||||
fail;
|
||||
}
|
||||
assert future::get(&option::unwrap(result)) == Failure;
|
||||
|
|
@ -2090,7 +2090,7 @@ fn test_tls_multitask() unsafe {
|
|||
fn my_key(+_x: @~str) { }
|
||||
local_data_set(my_key, @~"parent data");
|
||||
do task::spawn unsafe {
|
||||
assert local_data_get(my_key) == none; // TLS shouldn't carry over.
|
||||
assert local_data_get(my_key) == None; // TLS shouldn't carry over.
|
||||
local_data_set(my_key, @~"child data");
|
||||
assert *(local_data_get(my_key).get()) == ~"child data";
|
||||
// should be cleaned up for us
|
||||
|
|
@ -2115,7 +2115,7 @@ fn test_tls_pop() unsafe {
|
|||
local_data_set(my_key, @~"weasel");
|
||||
assert *(local_data_pop(my_key).get()) == ~"weasel";
|
||||
// Pop must remove the data from the map.
|
||||
assert local_data_pop(my_key) == none;
|
||||
assert local_data_pop(my_key) == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -2123,15 +2123,15 @@ fn test_tls_modify() unsafe {
|
|||
fn my_key(+_x: @~str) { }
|
||||
local_data_modify(my_key, |data| {
|
||||
match 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| {
|
||||
match 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";
|
||||
|
|
|
|||
|
|
@ -121,37 +121,37 @@ impl T: iter::TimesIx {
|
|||
*
|
||||
* `buf` must not be empty
|
||||
*/
|
||||
fn parse_buf(buf: &[const u8], radix: uint) -> option<T> {
|
||||
if vec::len(buf) == 0u { return none; }
|
||||
fn parse_buf(buf: &[const u8], radix: uint) -> Option<T> {
|
||||
if vec::len(buf) == 0u { return None; }
|
||||
let mut i = vec::len(buf) - 1u;
|
||||
let mut power = 1u as T;
|
||||
let mut n = 0u as T;
|
||||
loop {
|
||||
match 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); }
|
||||
if i == 0u { return Some(n); }
|
||||
i -= 1u;
|
||||
};
|
||||
}
|
||||
|
||||
/// Parse a string to an int
|
||||
fn from_str(s: ~str) -> option<T> { parse_buf(str::to_bytes(s), 10u) }
|
||||
fn from_str(s: ~str) -> Option<T> { parse_buf(str::to_bytes(s), 10u) }
|
||||
|
||||
/// Parse a string as an unsigned integer.
|
||||
fn from_str_radix(buf: ~str, radix: u64) -> option<u64> {
|
||||
if str::len(buf) == 0u { return none; }
|
||||
fn from_str_radix(buf: ~str, radix: u64) -> Option<u64> {
|
||||
if str::len(buf) == 0u { return None; }
|
||||
let mut i = str::len(buf) - 1u;
|
||||
let mut power = 1u64, n = 0u64;
|
||||
loop {
|
||||
match 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); }
|
||||
if i == 0u { return Some(n); }
|
||||
i -= 1u;
|
||||
};
|
||||
}
|
||||
|
|
@ -253,30 +253,30 @@ fn test_to_str() {
|
|||
#[test]
|
||||
#[ignore]
|
||||
fn test_from_str() {
|
||||
assert from_str(~"0") == some(0u as T);
|
||||
assert from_str(~"3") == some(3u as T);
|
||||
assert from_str(~"10") == some(10u as T);
|
||||
assert from_str(~"123456789") == some(123456789u as T);
|
||||
assert from_str(~"00100") == some(100u as T);
|
||||
assert from_str(~"0") == Some(0u as T);
|
||||
assert from_str(~"3") == Some(3u as T);
|
||||
assert from_str(~"10") == Some(10u as T);
|
||||
assert from_str(~"123456789") == Some(123456789u as T);
|
||||
assert from_str(~"00100") == Some(100u as T);
|
||||
|
||||
assert from_str(~"") == none;
|
||||
assert from_str(~" ") == none;
|
||||
assert from_str(~"x") == none;
|
||||
assert from_str(~"") == None;
|
||||
assert from_str(~" ") == None;
|
||||
assert from_str(~"x") == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_parse_buf() {
|
||||
import str::to_bytes;
|
||||
assert parse_buf(to_bytes(~"123"), 10u) == some(123u as T);
|
||||
assert parse_buf(to_bytes(~"1001"), 2u) == some(9u as T);
|
||||
assert parse_buf(to_bytes(~"123"), 8u) == some(83u as T);
|
||||
assert parse_buf(to_bytes(~"123"), 16u) == some(291u as T);
|
||||
assert parse_buf(to_bytes(~"ffff"), 16u) == some(65535u as T);
|
||||
assert parse_buf(to_bytes(~"z"), 36u) == some(35u as T);
|
||||
assert parse_buf(to_bytes(~"123"), 10u) == Some(123u as T);
|
||||
assert parse_buf(to_bytes(~"1001"), 2u) == Some(9u as T);
|
||||
assert parse_buf(to_bytes(~"123"), 8u) == Some(83u as T);
|
||||
assert parse_buf(to_bytes(~"123"), 16u) == Some(291u as T);
|
||||
assert parse_buf(to_bytes(~"ffff"), 16u) == Some(65535u as T);
|
||||
assert parse_buf(to_bytes(~"z"), 36u) == Some(35u as T);
|
||||
|
||||
assert parse_buf(to_bytes(~"Z"), 10u) == none;
|
||||
assert parse_buf(to_bytes(~"_"), 2u) == none;
|
||||
assert parse_buf(to_bytes(~"Z"), 10u) == None;
|
||||
assert parse_buf(to_bytes(~"_"), 2u) == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -73,14 +73,14 @@ unsafe fn transmute_mut_region<T>(+ptr: &a/mut T) -> &b/mut T {
|
|||
// An unwrapper uses this protocol to communicate with the "other" task that
|
||||
// drops the last refcount on an arc. Unfortunately this can't be a proper
|
||||
// pipe protocol because the unwrapper has to access both stages at once.
|
||||
type UnwrapProto = ~mut option<(pipes::chan_one<()>, pipes::port_one<bool>)>;
|
||||
type UnwrapProto = ~mut Option<(pipes::chan_one<()>, pipes::port_one<bool>)>;
|
||||
|
||||
struct ArcData<T> {
|
||||
mut count: libc::intptr_t;
|
||||
mut unwrapper: libc::uintptr_t; // either a UnwrapProto or 0
|
||||
// FIXME(#3224) should be able to make this non-option to save memory, and
|
||||
// in unwrap() use "let ~ArcData { data: result, _ } = thing" to unwrap it
|
||||
mut data: option<T>;
|
||||
mut data: Option<T>;
|
||||
}
|
||||
|
||||
struct ArcDestruct<T> {
|
||||
|
|
@ -125,8 +125,8 @@ struct ArcDestruct<T> {
|
|||
unsafe fn unwrap_shared_mutable_state<T: send>(+rc: SharedMutableState<T>)
|
||||
-> T {
|
||||
struct DeathThroes<T> {
|
||||
mut ptr: option<~ArcData<T>>;
|
||||
mut response: option<pipes::chan_one<bool>>;
|
||||
mut ptr: Option<~ArcData<T>>;
|
||||
mut response: Option<pipes::chan_one<bool>>;
|
||||
drop unsafe {
|
||||
let response = option::swap_unwrap(&mut self.response);
|
||||
// In case we get killed early, we need to tell the person who
|
||||
|
|
@ -147,7 +147,7 @@ unsafe fn unwrap_shared_mutable_state<T: send>(+rc: SharedMutableState<T>)
|
|||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(rc.data);
|
||||
let (c1,p1) = pipes::oneshot(); // ()
|
||||
let (c2,p2) = pipes::oneshot(); // bool
|
||||
let server: UnwrapProto = ~mut some((c1,p2));
|
||||
let server: UnwrapProto = ~mut Some((c1,p2));
|
||||
let serverp: libc::uintptr_t = unsafe::transmute(server);
|
||||
// Try to put our server end in the unwrapper slot.
|
||||
if rustrt::rust_compare_and_swap_ptr(&mut ptr.unwrapper, 0, serverp) {
|
||||
|
|
@ -165,8 +165,8 @@ unsafe fn unwrap_shared_mutable_state<T: send>(+rc: SharedMutableState<T>)
|
|||
} else {
|
||||
// The *next* person who sees the refcount hit 0 will wake us.
|
||||
let end_result =
|
||||
DeathThroes { ptr: some(ptr), response: some(c2) };
|
||||
let mut p1 = some(p1); // argh
|
||||
DeathThroes { ptr: Some(ptr), response: Some(c2) };
|
||||
let mut p1 = Some(p1); // argh
|
||||
do task::rekillable {
|
||||
pipes::recv_one(option::swap_unwrap(&mut p1));
|
||||
}
|
||||
|
|
@ -195,7 +195,7 @@ unsafe fn unwrap_shared_mutable_state<T: send>(+rc: SharedMutableState<T>)
|
|||
type SharedMutableState<T: send> = ArcDestruct<T>;
|
||||
|
||||
unsafe fn shared_mutable_state<T: send>(+data: T) -> SharedMutableState<T> {
|
||||
let data = ~ArcData { count: 1, unwrapper: 0, data: some(data) };
|
||||
let data = ~ArcData { count: 1, unwrapper: 0, data: Some(data) };
|
||||
unsafe {
|
||||
let ptr = unsafe::transmute(data);
|
||||
ArcDestruct(ptr)
|
||||
|
|
@ -433,7 +433,7 @@ mod tests {
|
|||
#[test]
|
||||
fn exclusive_unwrap_contended() {
|
||||
let x = exclusive(~~"hello");
|
||||
let x2 = ~mut some(x.clone());
|
||||
let x2 = ~mut Some(x.clone());
|
||||
do task::spawn {
|
||||
let x2 = option::swap_unwrap(x2);
|
||||
do x2.with |_hello| { }
|
||||
|
|
@ -443,9 +443,9 @@ mod tests {
|
|||
|
||||
// Now try the same thing, but with the child task blocking.
|
||||
let x = exclusive(~~"hello");
|
||||
let x2 = ~mut some(x.clone());
|
||||
let mut res = none;
|
||||
do task::task().future_result(|+r| res = some(r)).spawn {
|
||||
let x2 = ~mut Some(x.clone());
|
||||
let mut res = None;
|
||||
do task::task().future_result(|+r| res = Some(r)).spawn {
|
||||
let x2 = option::swap_unwrap(x2);
|
||||
assert unwrap_exclusive(x2) == ~~"hello";
|
||||
}
|
||||
|
|
@ -458,9 +458,9 @@ mod tests {
|
|||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn exclusive_unwrap_conflict() {
|
||||
let x = exclusive(~~"hello");
|
||||
let x2 = ~mut some(x.clone());
|
||||
let mut res = none;
|
||||
do task::task().future_result(|+r| res = some(r)).spawn {
|
||||
let x2 = ~mut Some(x.clone());
|
||||
let mut res = None;
|
||||
do task::task().future_result(|+r| res = Some(r)).spawn {
|
||||
let x2 = option::swap_unwrap(x2);
|
||||
assert unwrap_exclusive(x2) == ~~"hello";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ mod tests {
|
|||
}
|
||||
#[test]
|
||||
fn test_replace() {
|
||||
let mut x = some(NonCopyable());
|
||||
let y = replace(&mut x, none);
|
||||
let mut x = Some(NonCopyable());
|
||||
let y = replace(&mut x, None);
|
||||
assert x.is_none();
|
||||
assert y.is_some();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! Vectors
|
||||
|
||||
import option::{some, none};
|
||||
import option::{Some, None};
|
||||
import ptr::addr_of;
|
||||
import libc::size_t;
|
||||
|
||||
|
|
@ -264,7 +264,7 @@ pure fn build<A>(builder: fn(push: pure fn(+A))) -> ~[A] {
|
|||
* onto the vector being constructed.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn build_sized_opt<A>(size: option<uint>,
|
||||
pure fn build_sized_opt<A>(size: Option<uint>,
|
||||
builder: fn(push: pure fn(+A))) -> ~[A] {
|
||||
build_sized(size.get_default(4), builder)
|
||||
}
|
||||
|
|
@ -310,12 +310,12 @@ pure fn last<T: copy>(v: &[const T]) -> T {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns `some(x)` where `x` is the last element of the slice `v`,
|
||||
* Returns `Some(x)` where `x` is the last element of the slice `v`,
|
||||
* or `none` if the vector is empty.
|
||||
*/
|
||||
pure fn last_opt<T: copy>(v: &[const T]) -> option<T> {
|
||||
if len(v) == 0u { return none; }
|
||||
some(v[len(v) - 1u])
|
||||
pure fn last_opt<T: copy>(v: &[const T]) -> Option<T> {
|
||||
if len(v) == 0u { return None; }
|
||||
Some(v[len(v) - 1u])
|
||||
}
|
||||
|
||||
/// Returns a copy of the elements from [`start`..`end`) from `v`.
|
||||
|
|
@ -374,8 +374,8 @@ fn split<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
|
|||
let mut result = ~[];
|
||||
while start < ln {
|
||||
match position_between(v, start, ln, f) {
|
||||
none => break,
|
||||
some(i) => {
|
||||
None => break,
|
||||
Some(i) => {
|
||||
push(result, slice(v, start, i));
|
||||
start = i + 1u;
|
||||
}
|
||||
|
|
@ -398,8 +398,8 @@ fn splitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
|
|||
let mut result = ~[];
|
||||
while start < ln && count > 0u {
|
||||
match 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;
|
||||
|
|
@ -423,8 +423,8 @@ fn rsplit<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
|
|||
let mut result = ~[];
|
||||
while end > 0u {
|
||||
match rposition_between(v, 0u, end, f) {
|
||||
none => break,
|
||||
some(i) => {
|
||||
None => break,
|
||||
Some(i) => {
|
||||
push(result, slice(v, i + 1u, end));
|
||||
end = i;
|
||||
}
|
||||
|
|
@ -447,8 +447,8 @@ fn rsplitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
|
|||
let mut result = ~[];
|
||||
while end > 0u && count > 0u {
|
||||
match 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;
|
||||
|
|
@ -751,13 +751,13 @@ pure fn map2<T: copy, U: copy, V>(v0: &[T], v1: &[U],
|
|||
* If function `f` returns `none` then that element is excluded from
|
||||
* the resulting vector.
|
||||
*/
|
||||
pure fn filter_map<T, U: copy>(v: &[T], f: fn(T) -> option<U>)
|
||||
pure fn filter_map<T, U: copy>(v: &[T], f: fn(T) -> Option<U>)
|
||||
-> ~[U] {
|
||||
let mut result = ~[];
|
||||
for each(v) |elem| {
|
||||
match 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;
|
||||
|
|
@ -899,7 +899,7 @@ pure fn count<T>(v: &[T], x: T) -> uint {
|
|||
* When function `f` returns true then an option containing the element
|
||||
* is returned. If `f` matches no elements then none is returned.
|
||||
*/
|
||||
pure fn find<T: copy>(v: &[T], f: fn(T) -> bool) -> option<T> {
|
||||
pure fn find<T: copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
|
||||
find_between(v, 0u, len(v), f)
|
||||
}
|
||||
|
||||
|
|
@ -911,7 +911,7 @@ pure fn find<T: copy>(v: &[T], f: fn(T) -> bool) -> option<T> {
|
|||
* the element is returned. If `f` matches no elements then none is returned.
|
||||
*/
|
||||
pure fn find_between<T: copy>(v: &[T], start: uint, end: uint,
|
||||
f: fn(T) -> bool) -> option<T> {
|
||||
f: fn(T) -> bool) -> Option<T> {
|
||||
option::map(position_between(v, start, end, f), |i| v[i])
|
||||
}
|
||||
|
||||
|
|
@ -922,7 +922,7 @@ pure fn find_between<T: copy>(v: &[T], start: uint, end: uint,
|
|||
* `f` returns true then an option containing the element is returned. If `f`
|
||||
* matches no elements then none is returned.
|
||||
*/
|
||||
pure fn rfind<T: copy>(v: &[T], f: fn(T) -> bool) -> option<T> {
|
||||
pure fn rfind<T: copy>(v: &[T], f: fn(T) -> bool) -> Option<T> {
|
||||
rfind_between(v, 0u, len(v), f)
|
||||
}
|
||||
|
||||
|
|
@ -934,12 +934,12 @@ pure fn rfind<T: copy>(v: &[T], f: fn(T) -> bool) -> option<T> {
|
|||
* the element is returned. If `f` matches no elements then none is returned.
|
||||
*/
|
||||
pure fn rfind_between<T: copy>(v: &[T], start: uint, end: uint,
|
||||
f: fn(T) -> bool) -> option<T> {
|
||||
f: fn(T) -> bool) -> Option<T> {
|
||||
option::map(rposition_between(v, start, end, f), |i| v[i])
|
||||
}
|
||||
|
||||
/// Find the first index containing a matching value
|
||||
pure fn position_elem<T>(v: &[T], x: T) -> option<uint> {
|
||||
pure fn position_elem<T>(v: &[T], x: T) -> Option<uint> {
|
||||
position(v, |y| x == y)
|
||||
}
|
||||
|
||||
|
|
@ -950,7 +950,7 @@ pure fn position_elem<T>(v: &[T], x: T) -> option<uint> {
|
|||
* then an option containing the index is returned. If `f` matches no elements
|
||||
* then none is returned.
|
||||
*/
|
||||
pure fn position<T>(v: &[T], f: fn(T) -> bool) -> option<uint> {
|
||||
pure fn position<T>(v: &[T], f: fn(T) -> bool) -> Option<uint> {
|
||||
position_between(v, 0u, len(v), f)
|
||||
}
|
||||
|
||||
|
|
@ -962,16 +962,16 @@ pure fn position<T>(v: &[T], f: fn(T) -> bool) -> option<uint> {
|
|||
* the index is returned. If `f` matches no elements then none is returned.
|
||||
*/
|
||||
pure fn position_between<T>(v: &[T], start: uint, end: uint,
|
||||
f: fn(T) -> bool) -> option<uint> {
|
||||
f: fn(T) -> bool) -> Option<uint> {
|
||||
assert start <= end;
|
||||
assert end <= len(v);
|
||||
let mut i = start;
|
||||
while i < end { if f(v[i]) { return some::<uint>(i); } i += 1u; }
|
||||
return none;
|
||||
while i < end { if f(v[i]) { return Some::<uint>(i); } i += 1u; }
|
||||
return None;
|
||||
}
|
||||
|
||||
/// Find the last index containing a matching value
|
||||
pure fn rposition_elem<T>(v: &[T], x: T) -> option<uint> {
|
||||
pure fn rposition_elem<T>(v: &[T], x: T) -> Option<uint> {
|
||||
rposition(v, |y| x == y)
|
||||
}
|
||||
|
||||
|
|
@ -982,7 +982,7 @@ pure fn rposition_elem<T>(v: &[T], x: T) -> option<uint> {
|
|||
* `f` returns true then an option containing the index is returned. If `f`
|
||||
* matches no elements then none is returned.
|
||||
*/
|
||||
pure fn rposition<T>(v: &[T], f: fn(T) -> bool) -> option<uint> {
|
||||
pure fn rposition<T>(v: &[T], f: fn(T) -> bool) -> Option<uint> {
|
||||
rposition_between(v, 0u, len(v), f)
|
||||
}
|
||||
|
||||
|
|
@ -995,15 +995,15 @@ pure fn rposition<T>(v: &[T], f: fn(T) -> bool) -> option<uint> {
|
|||
* returned.
|
||||
*/
|
||||
pure fn rposition_between<T>(v: &[T], start: uint, end: uint,
|
||||
f: fn(T) -> bool) -> option<uint> {
|
||||
f: fn(T) -> bool) -> Option<uint> {
|
||||
assert start <= end;
|
||||
assert end <= len(v);
|
||||
let mut i = end;
|
||||
while i > start {
|
||||
if f(v[i - 1u]) { return some::<uint>(i - 1u); }
|
||||
if f(v[i - 1u]) { return Some::<uint>(i - 1u); }
|
||||
i -= 1u;
|
||||
}
|
||||
return none;
|
||||
return None;
|
||||
}
|
||||
|
||||
// FIXME: if issue #586 gets implemented, could have a postcondition
|
||||
|
|
@ -1439,18 +1439,18 @@ trait ImmutableVector<T> {
|
|||
pure fn foldr<U: copy>(z: U, p: fn(T, U) -> U) -> U;
|
||||
pure fn iter(f: fn(T));
|
||||
pure fn iteri(f: fn(uint, T));
|
||||
pure fn position(f: fn(T) -> bool) -> option<uint>;
|
||||
pure fn position_elem(x: T) -> option<uint>;
|
||||
pure fn position(f: fn(T) -> bool) -> Option<uint>;
|
||||
pure fn position_elem(x: T) -> Option<uint>;
|
||||
pure fn riter(f: fn(T));
|
||||
pure fn riteri(f: fn(uint, T));
|
||||
pure fn rposition(f: fn(T) -> bool) -> option<uint>;
|
||||
pure fn rposition_elem(x: T) -> option<uint>;
|
||||
pure fn rposition(f: fn(T) -> bool) -> Option<uint>;
|
||||
pure fn rposition_elem(x: T) -> Option<uint>;
|
||||
pure fn map<U>(f: fn(T) -> U) -> ~[U];
|
||||
pure fn mapi<U>(f: fn(uint, T) -> U) -> ~[U];
|
||||
fn map_r<U>(f: fn(x: &T) -> U) -> ~[U];
|
||||
pure fn alli(f: fn(uint, T) -> bool) -> bool;
|
||||
pure fn flat_map<U>(f: fn(T) -> ~[U]) -> ~[U];
|
||||
pure fn filter_map<U: copy>(f: fn(T) -> option<U>) -> ~[U];
|
||||
pure fn filter_map<U: copy>(f: fn(T) -> Option<U>) -> ~[U];
|
||||
}
|
||||
|
||||
/// Extension methods for vectors
|
||||
|
|
@ -1482,10 +1482,10 @@ impl<T> &[T]: ImmutableVector<T> {
|
|||
* elements then none is returned.
|
||||
*/
|
||||
#[inline]
|
||||
pure fn position(f: fn(T) -> bool) -> option<uint> { position(self, f) }
|
||||
pure fn position(f: fn(T) -> bool) -> Option<uint> { position(self, f) }
|
||||
/// Find the first index containing a matching value
|
||||
#[inline]
|
||||
pure fn position_elem(x: T) -> option<uint> { position_elem(self, x) }
|
||||
pure fn position_elem(x: T) -> Option<uint> { position_elem(self, x) }
|
||||
/**
|
||||
* Iterates over a vector in reverse
|
||||
*
|
||||
|
|
@ -1510,10 +1510,10 @@ impl<T> &[T]: ImmutableVector<T> {
|
|||
* returned. If `f` matches no elements then none is returned.
|
||||
*/
|
||||
#[inline]
|
||||
pure fn rposition(f: fn(T) -> bool) -> option<uint> { rposition(self, f) }
|
||||
pure fn rposition(f: fn(T) -> bool) -> Option<uint> { rposition(self, f) }
|
||||
/// Find the last index containing a matching value
|
||||
#[inline]
|
||||
pure fn rposition_elem(x: T) -> option<uint> { rposition_elem(self, x) }
|
||||
pure fn rposition_elem(x: T) -> Option<uint> { rposition_elem(self, x) }
|
||||
/// Apply a function to each element of a vector and return the results
|
||||
#[inline]
|
||||
pure fn map<U>(f: fn(T) -> U) -> ~[U] { map(self, f) }
|
||||
|
|
@ -1557,14 +1557,14 @@ impl<T> &[T]: ImmutableVector<T> {
|
|||
* the resulting vector.
|
||||
*/
|
||||
#[inline]
|
||||
pure fn filter_map<U: copy>(f: fn(T) -> option<U>) -> ~[U] {
|
||||
pure fn filter_map<U: copy>(f: fn(T) -> Option<U>) -> ~[U] {
|
||||
filter_map(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
trait ImmutableCopyableVector<T> {
|
||||
pure fn filter(f: fn(T) -> bool) -> ~[T];
|
||||
pure fn rfind(f: fn(T) -> bool) -> option<T>;
|
||||
pure fn rfind(f: fn(T) -> bool) -> Option<T>;
|
||||
}
|
||||
|
||||
/// Extension methods for vectors
|
||||
|
|
@ -1586,7 +1586,7 @@ impl<T: copy> &[T]: ImmutableCopyableVector<T> {
|
|||
* returned. If `f` matches no elements then none is returned.
|
||||
*/
|
||||
#[inline]
|
||||
pure fn rfind(f: fn(T) -> bool) -> option<T> { rfind(self, f) }
|
||||
pure fn rfind(f: fn(T) -> bool) -> Option<T> { rfind(self, f) }
|
||||
}
|
||||
|
||||
/// Unsafe operations
|
||||
|
|
@ -1682,9 +1682,9 @@ mod unsafe {
|
|||
*/
|
||||
#[inline(always)]
|
||||
unsafe fn set<T>(v: &[mut T], i: uint, +val: T) {
|
||||
let mut box = some(val);
|
||||
let mut box = Some(val);
|
||||
do as_mut_buf(v) |p, _len| {
|
||||
let mut box2 = none;
|
||||
let mut box2 = None;
|
||||
box2 <-> box;
|
||||
rusti::move_val_init(*ptr::mut_offset(p, i),
|
||||
option::unwrap(box2));
|
||||
|
|
@ -1806,7 +1806,7 @@ mod u8 {
|
|||
|
||||
impl<A> &[A]: iter::BaseIter<A> {
|
||||
pure fn each(blk: fn(A) -> bool) { each(self, blk) }
|
||||
pure fn size_hint() -> option<uint> { some(len(self)) }
|
||||
pure fn size_hint() -> Option<uint> { Some(len(self)) }
|
||||
}
|
||||
|
||||
impl<A> &[A]: iter::ExtendedIter<A> {
|
||||
|
|
@ -1818,7 +1818,7 @@ impl<A> &[A]: iter::ExtendedIter<A> {
|
|||
}
|
||||
pure fn contains(x: A) -> bool { iter::contains(self, x) }
|
||||
pure fn count(x: A) -> uint { iter::count(self, x) }
|
||||
pure fn position(f: fn(A) -> bool) -> option<uint> {
|
||||
pure fn position(f: fn(A) -> bool) -> Option<uint> {
|
||||
iter::position(self, f)
|
||||
}
|
||||
}
|
||||
|
|
@ -1839,7 +1839,7 @@ impl<A: copy> &[A]: iter::CopyableIter<A> {
|
|||
|
||||
pure fn min() -> A { iter::min(self) }
|
||||
pure fn max() -> A { iter::max(self) }
|
||||
pure fn find(p: fn(A) -> bool) -> option<A> { iter::find(self, p) }
|
||||
pure fn find(p: fn(A) -> bool) -> Option<A> { iter::find(self, p) }
|
||||
}
|
||||
// ___________________________________________________________________________
|
||||
|
||||
|
|
@ -1856,8 +1856,8 @@ mod tests {
|
|||
|
||||
pure fn is_equal(&&x: uint, &&y:uint) -> bool { return x == y; }
|
||||
|
||||
fn square_if_odd(&&n: uint) -> option<uint> {
|
||||
return if n % 2u == 1u { some(n * n) } else { none };
|
||||
fn square_if_odd(&&n: uint) -> Option<uint> {
|
||||
return if n % 2u == 1u { Some(n * n) } else { None };
|
||||
}
|
||||
|
||||
fn add(&&x: uint, &&y: uint) -> uint { return x + y; }
|
||||
|
|
@ -1954,11 +1954,11 @@ mod tests {
|
|||
#[test]
|
||||
fn test_last() {
|
||||
let mut n = last_opt(~[]);
|
||||
assert (n == none);
|
||||
assert (n == None);
|
||||
n = last_opt(~[1, 2, 3]);
|
||||
assert (n == some(3));
|
||||
assert (n == Some(3));
|
||||
n = last_opt(~[1, 2, 3, 4, 5]);
|
||||
assert (n == some(5));
|
||||
assert (n == Some(5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -2140,10 +2140,10 @@ mod tests {
|
|||
assert (w[1] == 9u);
|
||||
assert (w[2] == 25u);
|
||||
|
||||
fn halve(&&i: int) -> option<int> {
|
||||
fn halve(&&i: int) -> Option<int> {
|
||||
if i % 2 == 0 {
|
||||
return option::some::<int>(i / 2);
|
||||
} else { return option::none::<int>; }
|
||||
return option::Some::<int>(i / 2);
|
||||
} else { return option::None::<int>; }
|
||||
}
|
||||
fn halve_for_sure(&&i: int) -> int { return i / 2; }
|
||||
let all_even: ~[int] = ~[0, 2, 8, 6];
|
||||
|
|
@ -2318,13 +2318,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_position_elem() {
|
||||
assert position_elem(~[], 1) == none;
|
||||
assert position_elem(~[], 1) == None;
|
||||
|
||||
let v1 = ~[1, 2, 3, 3, 2, 5];
|
||||
assert position_elem(v1, 1) == some(0u);
|
||||
assert position_elem(v1, 2) == some(1u);
|
||||
assert position_elem(v1, 5) == some(5u);
|
||||
assert position_elem(v1, 4) == none;
|
||||
assert position_elem(v1, 1) == Some(0u);
|
||||
assert position_elem(v1, 2) == Some(1u);
|
||||
assert position_elem(v1, 5) == Some(5u);
|
||||
assert position_elem(v1, 4) == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -2332,159 +2332,159 @@ mod tests {
|
|||
fn less_than_three(&&i: int) -> bool { return i < 3; }
|
||||
fn is_eighteen(&&i: int) -> bool { return i == 18; }
|
||||
|
||||
assert position(~[], less_than_three) == none;
|
||||
assert position(~[], less_than_three) == None;
|
||||
|
||||
let v1 = ~[5, 4, 3, 2, 1];
|
||||
assert position(v1, less_than_three) == some(3u);
|
||||
assert position(v1, is_eighteen) == none;
|
||||
assert position(v1, less_than_three) == Some(3u);
|
||||
assert position(v1, is_eighteen) == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_position_between() {
|
||||
assert position_between(~[], 0u, 0u, f) == none;
|
||||
assert position_between(~[], 0u, 0u, f) == None;
|
||||
|
||||
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
||||
let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||
|
||||
assert position_between(v, 0u, 0u, f) == none;
|
||||
assert position_between(v, 0u, 1u, f) == none;
|
||||
assert position_between(v, 0u, 2u, f) == some(1u);
|
||||
assert position_between(v, 0u, 3u, f) == some(1u);
|
||||
assert position_between(v, 0u, 4u, f) == some(1u);
|
||||
assert position_between(v, 0u, 0u, f) == None;
|
||||
assert position_between(v, 0u, 1u, f) == None;
|
||||
assert position_between(v, 0u, 2u, f) == Some(1u);
|
||||
assert position_between(v, 0u, 3u, f) == Some(1u);
|
||||
assert position_between(v, 0u, 4u, f) == Some(1u);
|
||||
|
||||
assert position_between(v, 1u, 1u, f) == none;
|
||||
assert position_between(v, 1u, 2u, f) == some(1u);
|
||||
assert position_between(v, 1u, 3u, f) == some(1u);
|
||||
assert position_between(v, 1u, 4u, f) == some(1u);
|
||||
assert position_between(v, 1u, 1u, f) == None;
|
||||
assert position_between(v, 1u, 2u, f) == Some(1u);
|
||||
assert position_between(v, 1u, 3u, f) == Some(1u);
|
||||
assert position_between(v, 1u, 4u, f) == Some(1u);
|
||||
|
||||
assert position_between(v, 2u, 2u, f) == none;
|
||||
assert position_between(v, 2u, 3u, f) == none;
|
||||
assert position_between(v, 2u, 4u, f) == some(3u);
|
||||
assert position_between(v, 2u, 2u, f) == None;
|
||||
assert position_between(v, 2u, 3u, f) == None;
|
||||
assert position_between(v, 2u, 4u, f) == Some(3u);
|
||||
|
||||
assert position_between(v, 3u, 3u, f) == none;
|
||||
assert position_between(v, 3u, 4u, f) == some(3u);
|
||||
assert position_between(v, 3u, 3u, f) == None;
|
||||
assert position_between(v, 3u, 4u, f) == Some(3u);
|
||||
|
||||
assert position_between(v, 4u, 4u, f) == none;
|
||||
assert position_between(v, 4u, 4u, f) == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find() {
|
||||
assert find(~[], f) == none;
|
||||
assert find(~[], f) == None;
|
||||
|
||||
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
||||
fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' }
|
||||
let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||
|
||||
assert find(v, f) == some((1, 'b'));
|
||||
assert find(v, g) == none;
|
||||
assert find(v, f) == Some((1, 'b'));
|
||||
assert find(v, g) == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_between() {
|
||||
assert find_between(~[], 0u, 0u, f) == none;
|
||||
assert find_between(~[], 0u, 0u, f) == None;
|
||||
|
||||
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
||||
let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||
|
||||
assert find_between(v, 0u, 0u, f) == none;
|
||||
assert find_between(v, 0u, 1u, f) == none;
|
||||
assert find_between(v, 0u, 2u, f) == some((1, 'b'));
|
||||
assert find_between(v, 0u, 3u, f) == some((1, 'b'));
|
||||
assert find_between(v, 0u, 4u, f) == some((1, 'b'));
|
||||
assert find_between(v, 0u, 0u, f) == None;
|
||||
assert find_between(v, 0u, 1u, f) == None;
|
||||
assert find_between(v, 0u, 2u, f) == Some((1, 'b'));
|
||||
assert find_between(v, 0u, 3u, f) == Some((1, 'b'));
|
||||
assert find_between(v, 0u, 4u, f) == Some((1, 'b'));
|
||||
|
||||
assert find_between(v, 1u, 1u, f) == none;
|
||||
assert find_between(v, 1u, 2u, f) == some((1, 'b'));
|
||||
assert find_between(v, 1u, 3u, f) == some((1, 'b'));
|
||||
assert find_between(v, 1u, 4u, f) == some((1, 'b'));
|
||||
assert find_between(v, 1u, 1u, f) == None;
|
||||
assert find_between(v, 1u, 2u, f) == Some((1, 'b'));
|
||||
assert find_between(v, 1u, 3u, f) == Some((1, 'b'));
|
||||
assert find_between(v, 1u, 4u, f) == Some((1, 'b'));
|
||||
|
||||
assert find_between(v, 2u, 2u, f) == none;
|
||||
assert find_between(v, 2u, 3u, f) == none;
|
||||
assert find_between(v, 2u, 4u, f) == some((3, 'b'));
|
||||
assert find_between(v, 2u, 2u, f) == None;
|
||||
assert find_between(v, 2u, 3u, f) == None;
|
||||
assert find_between(v, 2u, 4u, f) == Some((3, 'b'));
|
||||
|
||||
assert find_between(v, 3u, 3u, f) == none;
|
||||
assert find_between(v, 3u, 4u, f) == some((3, 'b'));
|
||||
assert find_between(v, 3u, 3u, f) == None;
|
||||
assert find_between(v, 3u, 4u, f) == Some((3, 'b'));
|
||||
|
||||
assert find_between(v, 4u, 4u, f) == none;
|
||||
assert find_between(v, 4u, 4u, f) == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rposition() {
|
||||
assert find(~[], f) == none;
|
||||
assert find(~[], f) == None;
|
||||
|
||||
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
||||
fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' }
|
||||
let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||
|
||||
assert position(v, f) == some(1u);
|
||||
assert position(v, g) == none;
|
||||
assert position(v, f) == Some(1u);
|
||||
assert position(v, g) == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rposition_between() {
|
||||
assert rposition_between(~[], 0u, 0u, f) == none;
|
||||
assert rposition_between(~[], 0u, 0u, f) == None;
|
||||
|
||||
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
||||
let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||
|
||||
assert rposition_between(v, 0u, 0u, f) == none;
|
||||
assert rposition_between(v, 0u, 1u, f) == none;
|
||||
assert rposition_between(v, 0u, 2u, f) == some(1u);
|
||||
assert rposition_between(v, 0u, 3u, f) == some(1u);
|
||||
assert rposition_between(v, 0u, 4u, f) == some(3u);
|
||||
assert rposition_between(v, 0u, 0u, f) == None;
|
||||
assert rposition_between(v, 0u, 1u, f) == None;
|
||||
assert rposition_between(v, 0u, 2u, f) == Some(1u);
|
||||
assert rposition_between(v, 0u, 3u, f) == Some(1u);
|
||||
assert rposition_between(v, 0u, 4u, f) == Some(3u);
|
||||
|
||||
assert rposition_between(v, 1u, 1u, f) == none;
|
||||
assert rposition_between(v, 1u, 2u, f) == some(1u);
|
||||
assert rposition_between(v, 1u, 3u, f) == some(1u);
|
||||
assert rposition_between(v, 1u, 4u, f) == some(3u);
|
||||
assert rposition_between(v, 1u, 1u, f) == None;
|
||||
assert rposition_between(v, 1u, 2u, f) == Some(1u);
|
||||
assert rposition_between(v, 1u, 3u, f) == Some(1u);
|
||||
assert rposition_between(v, 1u, 4u, f) == Some(3u);
|
||||
|
||||
assert rposition_between(v, 2u, 2u, f) == none;
|
||||
assert rposition_between(v, 2u, 3u, f) == none;
|
||||
assert rposition_between(v, 2u, 4u, f) == some(3u);
|
||||
assert rposition_between(v, 2u, 2u, f) == None;
|
||||
assert rposition_between(v, 2u, 3u, f) == None;
|
||||
assert rposition_between(v, 2u, 4u, f) == Some(3u);
|
||||
|
||||
assert rposition_between(v, 3u, 3u, f) == none;
|
||||
assert rposition_between(v, 3u, 4u, f) == some(3u);
|
||||
assert rposition_between(v, 3u, 3u, f) == None;
|
||||
assert rposition_between(v, 3u, 4u, f) == Some(3u);
|
||||
|
||||
assert rposition_between(v, 4u, 4u, f) == none;
|
||||
assert rposition_between(v, 4u, 4u, f) == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rfind() {
|
||||
assert rfind(~[], f) == none;
|
||||
assert rfind(~[], f) == None;
|
||||
|
||||
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
||||
fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' }
|
||||
let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||
|
||||
assert rfind(v, f) == some((3, 'b'));
|
||||
assert rfind(v, g) == none;
|
||||
assert rfind(v, f) == Some((3, 'b'));
|
||||
assert rfind(v, g) == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rfind_between() {
|
||||
assert rfind_between(~[], 0u, 0u, f) == none;
|
||||
assert rfind_between(~[], 0u, 0u, f) == None;
|
||||
|
||||
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
|
||||
let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||
|
||||
assert rfind_between(v, 0u, 0u, f) == none;
|
||||
assert rfind_between(v, 0u, 1u, f) == none;
|
||||
assert rfind_between(v, 0u, 2u, f) == some((1, 'b'));
|
||||
assert rfind_between(v, 0u, 3u, f) == some((1, 'b'));
|
||||
assert rfind_between(v, 0u, 4u, f) == some((3, 'b'));
|
||||
assert rfind_between(v, 0u, 0u, f) == None;
|
||||
assert rfind_between(v, 0u, 1u, f) == None;
|
||||
assert rfind_between(v, 0u, 2u, f) == Some((1, 'b'));
|
||||
assert rfind_between(v, 0u, 3u, f) == Some((1, 'b'));
|
||||
assert rfind_between(v, 0u, 4u, f) == Some((3, 'b'));
|
||||
|
||||
assert rfind_between(v, 1u, 1u, f) == none;
|
||||
assert rfind_between(v, 1u, 2u, f) == some((1, 'b'));
|
||||
assert rfind_between(v, 1u, 3u, f) == some((1, 'b'));
|
||||
assert rfind_between(v, 1u, 4u, f) == some((3, 'b'));
|
||||
assert rfind_between(v, 1u, 1u, f) == None;
|
||||
assert rfind_between(v, 1u, 2u, f) == Some((1, 'b'));
|
||||
assert rfind_between(v, 1u, 3u, f) == Some((1, 'b'));
|
||||
assert rfind_between(v, 1u, 4u, f) == Some((3, 'b'));
|
||||
|
||||
assert rfind_between(v, 2u, 2u, f) == none;
|
||||
assert rfind_between(v, 2u, 3u, f) == none;
|
||||
assert rfind_between(v, 2u, 4u, f) == some((3, 'b'));
|
||||
assert rfind_between(v, 2u, 2u, f) == None;
|
||||
assert rfind_between(v, 2u, 3u, f) == None;
|
||||
assert rfind_between(v, 2u, 4u, f) == Some((3, 'b'));
|
||||
|
||||
assert rfind_between(v, 3u, 3u, f) == none;
|
||||
assert rfind_between(v, 3u, 4u, f) == some((3, 'b'));
|
||||
assert rfind_between(v, 3u, 3u, f) == None;
|
||||
assert rfind_between(v, 3u, 4u, f) == Some((3, 'b'));
|
||||
|
||||
assert rfind_between(v, 4u, 4u, f) == none;
|
||||
assert rfind_between(v, 4u, 4u, f) == None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -470,7 +470,7 @@ mod tests {
|
|||
let arc = ~mutex_arc(false);
|
||||
let arc2 = ~arc.clone();
|
||||
let (c,p) = pipes::oneshot();
|
||||
let (c,p) = (~mut some(c), ~mut some(p));
|
||||
let (c,p) = (~mut Some(c), ~mut Some(p));
|
||||
do task::spawn {
|
||||
// wait until parent gets in
|
||||
pipes::recv_one(option::swap_unwrap(p));
|
||||
|
|
|
|||
|
|
@ -43,12 +43,12 @@ enum c_vec<T> {
|
|||
}
|
||||
|
||||
struct dtor_res {
|
||||
let dtor: option<fn@()>;
|
||||
new(dtor: option<fn@()>) { self.dtor = dtor; }
|
||||
let dtor: Option<fn@()>;
|
||||
new(dtor: Option<fn@()>) { self.dtor = dtor; }
|
||||
drop {
|
||||
match self.dtor {
|
||||
option::none => (),
|
||||
option::some(f) => f()
|
||||
option::None => (),
|
||||
option::Some(f) => f()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ unsafe fn c_vec<T>(base: *mut T, len: uint) -> c_vec<T> {
|
|||
return c_vec_({
|
||||
base: base,
|
||||
len: len,
|
||||
rsrc: @dtor_res(option::none)
|
||||
rsrc: @dtor_res(option::None)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ unsafe fn c_vec_with_dtor<T>(base: *mut T, len: uint, dtor: fn@())
|
|||
return c_vec_({
|
||||
base: base,
|
||||
len: len,
|
||||
rsrc: @dtor_res(option::some(dtor))
|
||||
rsrc: @dtor_res(option::Some(dtor))
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@
|
|||
/// Similar to a mutable option type, but friendlier.
|
||||
|
||||
struct Cell<T> {
|
||||
mut value: option<T>;
|
||||
mut value: Option<T>;
|
||||
}
|
||||
|
||||
/// Creates a new full cell with the given value.
|
||||
fn Cell<T>(+value: T) -> Cell<T> {
|
||||
Cell { value: some(move value) }
|
||||
Cell { value: Some(move value) }
|
||||
}
|
||||
|
||||
fn empty_cell<T>() -> Cell<T> {
|
||||
Cell { value: none }
|
||||
Cell { value: None }
|
||||
}
|
||||
|
||||
impl<T> Cell<T> {
|
||||
|
|
@ -22,7 +22,7 @@ impl<T> Cell<T> {
|
|||
fail ~"attempt to take an empty cell";
|
||||
}
|
||||
|
||||
let mut value = none;
|
||||
let mut value = None;
|
||||
value <-> self.value;
|
||||
return option::unwrap(value);
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ impl<T> Cell<T> {
|
|||
if !self.is_empty() {
|
||||
fail ~"attempt to put a value back into a full cell";
|
||||
}
|
||||
self.value = some(move value);
|
||||
self.value = Some(move value);
|
||||
}
|
||||
|
||||
/// Returns true if the cell is empty and false if the cell is full.
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ struct DuplexStream<T: send, U: send> : channel<T>, recv<U>, selectable {
|
|||
self.port.recv()
|
||||
}
|
||||
|
||||
fn try_recv() -> option<U> {
|
||||
fn try_recv() -> Option<U> {
|
||||
self.port.try_recv()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! A deque. Untested as of yet. Likely buggy
|
||||
|
||||
import option::{some, none};
|
||||
import option::{Some, None};
|
||||
import dvec::{DVec, dvec};
|
||||
|
||||
trait t<T> {
|
||||
|
|
@ -17,7 +17,7 @@ trait t<T> {
|
|||
// FIXME (#2343) eventually, a proper datatype plus an exported impl would
|
||||
// be preferrable.
|
||||
fn create<T: copy>() -> t<T> {
|
||||
type cell<T> = option<T>;
|
||||
type cell<T> = Option<T>;
|
||||
|
||||
let initial_capacity: uint = 32u; // 2^5
|
||||
/**
|
||||
|
|
@ -34,14 +34,14 @@ fn create<T: copy>() -> t<T> {
|
|||
while i < nalloc {
|
||||
if i < nelts {
|
||||
vec::push(rv, elts[(lo + i) % nelts]);
|
||||
} else { vec::push(rv, none); }
|
||||
} else { vec::push(rv, None); }
|
||||
i += 1u;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
fn get<T: copy>(elts: DVec<cell<T>>, i: uint) -> T {
|
||||
match elts.get_elt(i) { some(t) => t, _ => fail }
|
||||
match elts.get_elt(i) { Some(t) => t, _ => fail }
|
||||
}
|
||||
|
||||
type repr<T> = {mut nelts: uint,
|
||||
|
|
@ -61,7 +61,7 @@ fn create<T: copy>() -> t<T> {
|
|||
self.lo = self.elts.len() - 1u;
|
||||
self.hi = self.nelts;
|
||||
}
|
||||
self.elts.set_elt(self.lo, some(t));
|
||||
self.elts.set_elt(self.lo, Some(t));
|
||||
self.nelts += 1u;
|
||||
}
|
||||
fn add_back(t: T) {
|
||||
|
|
@ -70,7 +70,7 @@ fn create<T: copy>() -> t<T> {
|
|||
self.lo = 0u;
|
||||
self.hi = self.nelts;
|
||||
}
|
||||
self.elts.set_elt(self.hi, some(t));
|
||||
self.elts.set_elt(self.hi, Some(t));
|
||||
self.hi = (self.hi + 1u) % self.elts.len();
|
||||
self.nelts += 1u;
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ fn create<T: copy>() -> t<T> {
|
|||
*/
|
||||
fn pop_front() -> T {
|
||||
let t: T = get(self.elts, self.lo);
|
||||
self.elts.set_elt(self.lo, none);
|
||||
self.elts.set_elt(self.lo, None);
|
||||
self.lo = (self.lo + 1u) % self.elts.len();
|
||||
self.nelts -= 1u;
|
||||
return t;
|
||||
|
|
@ -90,7 +90,7 @@ fn create<T: copy>() -> t<T> {
|
|||
self.hi = self.elts.len() - 1u;
|
||||
} else { self.hi -= 1u; }
|
||||
let t: T = get(self.elts, self.hi);
|
||||
self.elts.set_elt(self.hi, none);
|
||||
self.elts.set_elt(self.hi, None);
|
||||
self.nelts -= 1u;
|
||||
return t;
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ fn create<T: copy>() -> t<T> {
|
|||
elts:
|
||||
dvec::from_vec(
|
||||
vec::to_mut(
|
||||
vec::from_elem(initial_capacity, none)))
|
||||
vec::from_elem(initial_capacity, None)))
|
||||
};
|
||||
repr as t::<T>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
// Simple Extensible Binary Markup Language (ebml) reader and writer on a
|
||||
// cursor model. See the specification here:
|
||||
// http://www.matroska.org/technical/specs/rfc/index.html
|
||||
import core::option;
|
||||
import option::{some, none};
|
||||
import core::Option;
|
||||
import option::{Some, None};
|
||||
|
||||
export doc;
|
||||
export doc_at;
|
||||
|
|
@ -85,27 +85,27 @@ fn doc_at(data: @~[u8], start: uint) -> tagged_doc {
|
|||
doc: {data: data, start: elt_size.next, end: end}};
|
||||
}
|
||||
|
||||
fn maybe_get_doc(d: doc, tg: uint) -> option<doc> {
|
||||
fn maybe_get_doc(d: doc, tg: uint) -> Option<doc> {
|
||||
let mut pos = d.start;
|
||||
while pos < d.end {
|
||||
let elt_tag = vuint_at(*d.data, pos);
|
||||
let elt_size = vuint_at(*d.data, elt_tag.next);
|
||||
pos = elt_size.next + elt_size.val;
|
||||
if elt_tag.val == tg {
|
||||
return some::<doc>({
|
||||
return Some::<doc>({
|
||||
data: d.data,
|
||||
start: elt_size.next,
|
||||
end: pos
|
||||
});
|
||||
}
|
||||
}
|
||||
return none::<doc>;
|
||||
return None::<doc>;
|
||||
}
|
||||
|
||||
fn get_doc(d: doc, tg: uint) -> doc {
|
||||
match 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;
|
||||
}
|
||||
|
|
@ -575,12 +575,12 @@ fn test_option_int() {
|
|||
s.emit_i64(v as i64);
|
||||
}
|
||||
|
||||
fn serialize_0<S: serialization::serializer>(s: S, v: option<int>) {
|
||||
fn serialize_0<S: serialization::serializer>(s: S, v: Option<int>) {
|
||||
do s.emit_enum(~"core::option::t") {
|
||||
match 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));
|
||||
}
|
||||
|
|
@ -593,16 +593,16 @@ fn test_option_int() {
|
|||
s.read_i64() as int
|
||||
}
|
||||
|
||||
fn deserialize_0<S: serialization::deserializer>(s: S) -> option<int> {
|
||||
fn deserialize_0<S: serialization::deserializer>(s: S) -> Option<int> {
|
||||
do s.read_enum(~"core::option::t") {
|
||||
do s.read_enum_variant |i| {
|
||||
match i {
|
||||
0 => none,
|
||||
0 => None,
|
||||
1 => {
|
||||
let v0 = do s.read_enum_variant_arg(0u) {
|
||||
deserialize_1(s)
|
||||
};
|
||||
some(v0)
|
||||
Some(v0)
|
||||
}
|
||||
_ => {
|
||||
fail #fmt("deserialize_0: unexpected variant %u", i);
|
||||
|
|
@ -612,7 +612,7 @@ fn test_option_int() {
|
|||
}
|
||||
}
|
||||
|
||||
fn test_v(v: option<int>) {
|
||||
fn test_v(v: Option<int>) {
|
||||
debug!("v == %?", v);
|
||||
let mbuf = io::mem_buffer();
|
||||
let ebml_w = ebml::writer(io::mem_buffer_writer(mbuf));
|
||||
|
|
@ -624,7 +624,7 @@ fn test_option_int() {
|
|||
assert v == v1;
|
||||
}
|
||||
|
||||
test_v(some(22));
|
||||
test_v(none);
|
||||
test_v(some(3));
|
||||
test_v(Some(22));
|
||||
test_v(None);
|
||||
test_v(Some(3));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
* of features.
|
||||
*/
|
||||
|
||||
import option::{some, none};
|
||||
import option::{Some, None};
|
||||
import option = option;
|
||||
|
||||
export treemap;
|
||||
|
|
@ -43,12 +43,12 @@ fn insert<K: copy, V: copy>(m: treemap<K, V>, k: K, v: V) -> treemap<K, V> {
|
|||
}
|
||||
|
||||
/// Find a value based on the key
|
||||
fn find<K, V: copy>(m: treemap<K, V>, k: K) -> option<V> {
|
||||
fn find<K, V: copy>(m: treemap<K, V>, k: K) -> Option<V> {
|
||||
match *m {
|
||||
empty => none,
|
||||
empty => None,
|
||||
node(@kk, @v, left, right) => {
|
||||
if k == kk {
|
||||
some(v)
|
||||
Some(v)
|
||||
} else if k < kk { find(left, k) } else { find(right, k) }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
* import std::getopts::{optopt,optflag,getopts,opt_present,opt_maybe_str,
|
||||
* fail_str};
|
||||
*
|
||||
* fn do_work(in: str, out: option<str>) {
|
||||
* fn do_work(in: str, out: Option<str>) {
|
||||
* // ...
|
||||
* }
|
||||
*
|
||||
|
|
@ -64,7 +64,7 @@
|
|||
|
||||
import core::result::{err, ok};
|
||||
import core::option;
|
||||
import core::option::{some, none};
|
||||
import core::option::{Some, None};
|
||||
export opt;
|
||||
export reqopt;
|
||||
export optopt;
|
||||
|
|
@ -146,7 +146,7 @@ fn name_str(nm: name) -> ~str {
|
|||
};
|
||||
}
|
||||
|
||||
fn find_opt(opts: ~[opt], nm: name) -> option<uint> {
|
||||
fn find_opt(opts: ~[opt], nm: name) -> Option<uint> {
|
||||
vec::position(opts, |opt| opt.name == nm)
|
||||
}
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe {
|
|||
break;
|
||||
} else {
|
||||
let mut names;
|
||||
let mut i_arg = option::none::<~str>;
|
||||
let mut i_arg = option::None::<~str>;
|
||||
if cur[1] == '-' as u8 {
|
||||
let tail = str::slice(cur, 2u, curlen);
|
||||
let tail_eq = str::splitn_char(tail, '=', 1u);
|
||||
|
|
@ -216,11 +216,11 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe {
|
|||
names =
|
||||
~[long(tail_eq[0])];
|
||||
i_arg =
|
||||
option::some::<~str>(tail_eq[1]);
|
||||
option::Some::<~str>(tail_eq[1]);
|
||||
}
|
||||
} else {
|
||||
let mut j = 1u;
|
||||
let mut last_valid_opt_id = option::none;
|
||||
let mut last_valid_opt_id = option::None;
|
||||
names = ~[];
|
||||
while j < curlen {
|
||||
let range = str::char_range_at(cur, j);
|
||||
|
|
@ -234,8 +234,8 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe {
|
|||
*/
|
||||
|
||||
match 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) &&
|
||||
match opts[option::get(last_valid_opt_id)]
|
||||
|
|
@ -245,10 +245,10 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe {
|
|||
no => false
|
||||
};
|
||||
if arg_follows && j + 1 < curlen {
|
||||
i_arg = option::some(str::slice(cur, j, curlen));
|
||||
i_arg = option::Some(str::slice(cur, j, curlen));
|
||||
break;
|
||||
} else {
|
||||
last_valid_opt_id = option::none;
|
||||
last_valid_opt_id = option::None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -260,8 +260,8 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe {
|
|||
for vec::each(names) |nm| {
|
||||
name_pos += 1u;
|
||||
let optid = match 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)))
|
||||
};
|
||||
match opts[optid].hasarg {
|
||||
no => {
|
||||
|
|
@ -312,8 +312,8 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe {
|
|||
|
||||
fn opt_vals(m: matches, nm: ~str) -> ~[optval] {
|
||||
return match find_opt(m.opts, mkname(nm)) {
|
||||
some(id) => m.vals[id],
|
||||
none => {
|
||||
Some(id) => m.vals[id],
|
||||
None => {
|
||||
error!("No option '%s' defined", nm);
|
||||
fail
|
||||
}
|
||||
|
|
@ -331,7 +331,7 @@ fn opt_present(m: matches, nm: ~str) -> bool {
|
|||
fn opts_present(m: matches, names: ~[~str]) -> bool {
|
||||
for vec::each(names) |nm| {
|
||||
match find_opt(m.opts, mkname(nm)) {
|
||||
some(_) => return true,
|
||||
Some(_) => return true,
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
|
@ -381,10 +381,10 @@ fn opt_strs(m: matches, nm: ~str) -> ~[~str] {
|
|||
}
|
||||
|
||||
/// Returns the string argument supplied to a matching option or none
|
||||
fn opt_maybe_str(m: matches, nm: ~str) -> option<~str> {
|
||||
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 match vals[0] { val(s) => some::<~str>(s), _ => none::<~str> };
|
||||
if vec::len::<optval>(vals) == 0u { return None::<~str>; }
|
||||
return match vals[0] { val(s) => Some::<~str>(s), _ => None::<~str> };
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -395,10 +395,10 @@ fn opt_maybe_str(m: matches, nm: ~str) -> option<~str> {
|
|||
* present but no argument was provided, and the argument if the option was
|
||||
* present and an argument was provided.
|
||||
*/
|
||||
fn opt_default(m: matches, nm: ~str, def: ~str) -> option<~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 match vals[0] { val(s) => some::<~str>(s), _ => some::<~str>(def) }
|
||||
if vec::len::<optval>(vals) == 0u { return None::<~str>; }
|
||||
return match vals[0] { val(s) => Some::<~str>(s), _ => Some::<~str>(def) }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -486,8 +486,8 @@ fn eq(value0: json, value1: json) -> bool {
|
|||
let mut equal = true;
|
||||
for d0.each |k, v0| {
|
||||
match 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
|
||||
|
|
@ -613,11 +613,11 @@ impl <A: to_json copy> hashmap<~str, A>: to_json {
|
|||
}
|
||||
}
|
||||
|
||||
impl <A: to_json> option<A>: to_json {
|
||||
impl <A: to_json> Option<A>: to_json {
|
||||
fn to_json() -> json {
|
||||
match self {
|
||||
none => null,
|
||||
some(value) => value.to_json()
|
||||
None => null,
|
||||
Some(value) => value.to_json()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import core::option;
|
||||
import option::*;
|
||||
import option::{some, none};
|
||||
import option::{Some, None};
|
||||
|
||||
enum list<T> {
|
||||
cons(T, @list<T>),
|
||||
|
|
@ -40,15 +40,15 @@ fn foldl<T: copy, U>(z: T, ls: @list<U>, f: fn(T, U) -> T) -> T {
|
|||
* When function `f` returns true then an option containing the element
|
||||
* is returned. If `f` matches no elements then none is returned.
|
||||
*/
|
||||
fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> option<T> {
|
||||
fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> Option<T> {
|
||||
let mut ls = ls;
|
||||
loop {
|
||||
ls = match *ls {
|
||||
cons(hd, tl) => {
|
||||
if f(hd) { return some(hd); }
|
||||
if f(hd) { return Some(hd); }
|
||||
tl
|
||||
}
|
||||
nil => return none
|
||||
nil => return None
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -201,7 +201,7 @@ mod tests {
|
|||
fn test_find_success() {
|
||||
fn match_(&&i: int) -> bool { return i == 2; }
|
||||
let l = from_vec(~[0, 1, 2]);
|
||||
assert (list::find(l, match_) == option::some(2));
|
||||
assert (list::find(l, match_) == option::Some(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -209,8 +209,8 @@ mod tests {
|
|||
fn match_(&&_i: int) -> bool { return false; }
|
||||
let l = from_vec(~[0, 1, 2]);
|
||||
let empty = @list::nil::<int>;
|
||||
assert (list::find(l, match_) == option::none::<int>);
|
||||
assert (list::find(empty, match_) == option::none::<int>);
|
||||
assert (list::find(l, match_) == option::None::<int>);
|
||||
assert (list::find(empty, match_) == option::None::<int>);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ trait map<K: copy, V: copy> {
|
|||
* Get the value for the specified key. If the key does not exist in
|
||||
* the map then returns none.
|
||||
*/
|
||||
fn find(+key: K) -> option<V>;
|
||||
fn find(+key: K) -> Option<V>;
|
||||
|
||||
/**
|
||||
* Remove and return a value from the map. Returns true if the
|
||||
|
|
@ -111,12 +111,12 @@ mod chained {
|
|||
hash: uint;
|
||||
key: K;
|
||||
value: V;
|
||||
mut next: option<@entry<K, V>>;
|
||||
mut next: Option<@entry<K, V>>;
|
||||
}
|
||||
|
||||
struct hashmap_<K, V> {
|
||||
mut count: uint;
|
||||
mut chains: ~[mut option<@entry<K,V>>];
|
||||
mut chains: ~[mut Option<@entry<K,V>>];
|
||||
hasher: hashfn<K>;
|
||||
eqer: eqfn<K>;
|
||||
}
|
||||
|
|
@ -136,12 +136,12 @@ mod chained {
|
|||
let mut comp = 1u; // for logging
|
||||
loop {
|
||||
match 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, \
|
||||
|
|
@ -159,12 +159,12 @@ mod chained {
|
|||
fn search_tbl(k: &K, h: uint) -> search_result<K,V> {
|
||||
let idx = h % vec::len(self.chains);
|
||||
match 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);
|
||||
|
|
@ -183,7 +183,7 @@ mod chained {
|
|||
for self.each_entry |entry| {
|
||||
let idx = entry.hash % n_new_chains;
|
||||
entry.next = new_chains[idx];
|
||||
new_chains[idx] = some(entry);
|
||||
new_chains[idx] = Some(entry);
|
||||
}
|
||||
self.chains = new_chains;
|
||||
}
|
||||
|
|
@ -196,8 +196,8 @@ mod chained {
|
|||
let mut chain = self.chains[i];
|
||||
loop {
|
||||
chain = match chain {
|
||||
none => break,
|
||||
some(entry) => {
|
||||
None => break,
|
||||
Some(entry) => {
|
||||
let next = entry.next;
|
||||
if !blk(entry) { return; }
|
||||
next
|
||||
|
|
@ -231,7 +231,7 @@ mod chained {
|
|||
self.count += 1u;
|
||||
let idx = hash % vec::len(self.chains);
|
||||
let old_chain = self.chains[idx];
|
||||
self.chains[idx] = some(@entry {
|
||||
self.chains[idx] = Some(@entry {
|
||||
hash: hash,
|
||||
key: k,
|
||||
value: v,
|
||||
|
|
@ -248,7 +248,7 @@ mod chained {
|
|||
return true;
|
||||
}
|
||||
found_first(idx, entry) => {
|
||||
self.chains[idx] = some(@entry {
|
||||
self.chains[idx] = Some(@entry {
|
||||
hash: hash,
|
||||
key: k,
|
||||
value: v,
|
||||
|
|
@ -256,7 +256,7 @@ mod chained {
|
|||
return false;
|
||||
}
|
||||
found_after(prev, entry) => {
|
||||
prev.next = some(@entry {
|
||||
prev.next = Some(@entry {
|
||||
hash: hash,
|
||||
key: k,
|
||||
value: v,
|
||||
|
|
@ -266,11 +266,11 @@ mod chained {
|
|||
}
|
||||
}
|
||||
|
||||
fn find(+k: K) -> option<V> {
|
||||
fn find(+k: K) -> Option<V> {
|
||||
match 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -364,8 +364,8 @@ mod chained {
|
|||
}
|
||||
}
|
||||
|
||||
fn chains<K,V>(nchains: uint) -> ~[mut option<@entry<K,V>>] {
|
||||
vec::to_mut(vec::from_elem(nchains, none))
|
||||
fn chains<K,V>(nchains: uint) -> ~[mut Option<@entry<K,V>>] {
|
||||
vec::to_mut(vec::from_elem(nchains, None))
|
||||
}
|
||||
|
||||
fn mk<K, V: copy>(+hasher: hashfn<K>, +eqer: eqfn<K>) -> t<K,V> {
|
||||
|
|
@ -503,7 +503,7 @@ impl<K: copy, V: copy> Managed<LinearMap<K, V>>: map<K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
fn find(+key: K) -> option<V> {
|
||||
fn find(+key: K) -> Option<V> {
|
||||
do self.borrow_const |p| {
|
||||
p.find(&key)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ mod v4 {
|
|||
fn parse_to_ipv4_rep(ip: ~str) -> result::result<ipv4_rep, ~str> {
|
||||
let parts = vec::map(str::split_char(ip, '.'), |s| {
|
||||
match uint::from_str(s) {
|
||||
some(n) if n <= 255u => n,
|
||||
Some(n) if n <= 255u => n,
|
||||
_ => 256u
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -488,7 +488,7 @@ fn accept(new_conn: tcp_new_connection)
|
|||
let client_stream_handle_ptr =
|
||||
(*client_socket_data_ptr).stream_handle_ptr;
|
||||
|
||||
let result_po = core::comm::port::<option<tcp_err_data>>();
|
||||
let result_po = core::comm::port::<Option<tcp_err_data>>();
|
||||
let result_ch = core::comm::chan(result_po);
|
||||
|
||||
// UNSAFE LIBUV INTERACTION BEGIN
|
||||
|
|
@ -511,25 +511,25 @@ fn accept(new_conn: tcp_new_connection)
|
|||
uv::ll::set_data_for_uv_handle(client_stream_handle_ptr,
|
||||
client_socket_data_ptr
|
||||
as *libc::c_void);
|
||||
core::comm::send(result_ch, none);
|
||||
core::comm::send(result_ch, None);
|
||||
}
|
||||
_ => {
|
||||
log(debug, ~"failed to accept client conn");
|
||||
core::comm::send(result_ch, some(
|
||||
core::comm::send(result_ch, Some(
|
||||
uv::ll::get_last_err_data(loop_ptr).to_tcp_err()));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
log(debug, ~"failed to init client stream");
|
||||
core::comm::send(result_ch, some(
|
||||
core::comm::send(result_ch, Some(
|
||||
uv::ll::get_last_err_data(loop_ptr).to_tcp_err()));
|
||||
}
|
||||
}
|
||||
// UNSAFE LIBUV INTERACTION END
|
||||
match core::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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -565,9 +565,9 @@ fn accept(new_conn: tcp_new_connection)
|
|||
*/
|
||||
fn listen(-host_ip: ip::ip_addr, port: uint, backlog: uint,
|
||||
iotask: iotask,
|
||||
on_establish_cb: fn~(comm::Chan<option<tcp_err_data>>),
|
||||
on_establish_cb: fn~(comm::Chan<Option<tcp_err_data>>),
|
||||
+new_connect_cb: fn~(tcp_new_connection,
|
||||
comm::Chan<option<tcp_err_data>>))
|
||||
comm::Chan<Option<tcp_err_data>>))
|
||||
-> result::result<(), tcp_listen_err_data> unsafe {
|
||||
do listen_common(host_ip, port, backlog, iotask, on_establish_cb)
|
||||
// on_connect_cb
|
||||
|
|
@ -582,11 +582,11 @@ fn listen(-host_ip: ip::ip_addr, port: uint, backlog: uint,
|
|||
|
||||
fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
|
||||
iotask: iotask,
|
||||
on_establish_cb: fn~(comm::Chan<option<tcp_err_data>>),
|
||||
on_establish_cb: fn~(comm::Chan<Option<tcp_err_data>>),
|
||||
-on_connect_cb: fn~(*uv::ll::uv_tcp_t))
|
||||
-> result::result<(), tcp_listen_err_data> unsafe {
|
||||
let stream_closed_po = core::comm::port::<()>();
|
||||
let kill_po = core::comm::port::<option<tcp_err_data>>();
|
||||
let kill_po = core::comm::port::<Option<tcp_err_data>>();
|
||||
let kill_ch = core::comm::chan(kill_po);
|
||||
let server_stream = uv::ll::tcp_t();
|
||||
let server_stream_ptr = ptr::addr_of(server_stream);
|
||||
|
|
@ -634,32 +634,32 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
|
|||
match uv::ll::listen(server_stream_ptr,
|
||||
backlog as libc::c_int,
|
||||
tcp_lfc_on_connection_cb) {
|
||||
0i32 => core::comm::send(setup_ch, none),
|
||||
0i32 => core::comm::send(setup_ch, None),
|
||||
_ => {
|
||||
log(debug, ~"failure to uv_listen()");
|
||||
let err_data = uv::ll::get_last_err_data(loop_ptr);
|
||||
core::comm::send(setup_ch, some(err_data));
|
||||
core::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);
|
||||
core::comm::send(setup_ch, some(err_data));
|
||||
core::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);
|
||||
core::comm::send(setup_ch, some(err_data));
|
||||
core::comm::send(setup_ch, Some(err_data));
|
||||
}
|
||||
}
|
||||
};
|
||||
setup_ch.recv()
|
||||
};
|
||||
match setup_result {
|
||||
some(err_data) => {
|
||||
Some(err_data) => {
|
||||
do iotask::interact(iotask) |loop_ptr| unsafe {
|
||||
log(debug, fmt!("tcp::listen post-kill recv hl interact %?",
|
||||
loop_ptr));
|
||||
|
|
@ -684,7 +684,7 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
|
|||
}
|
||||
}
|
||||
}
|
||||
none => {
|
||||
None => {
|
||||
on_establish_cb(kill_ch);
|
||||
let kill_result = core::comm::recv(kill_po);
|
||||
do iotask::interact(iotask) |loop_ptr| unsafe {
|
||||
|
|
@ -696,10 +696,10 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint,
|
|||
stream_closed_po.recv();
|
||||
match kill_result {
|
||||
// some failure post bind/listen
|
||||
some(err_data) => result::err(generic_listen_err(err_data.err_name,
|
||||
Some(err_data) => result::err(generic_listen_err(err_data.err_name,
|
||||
err_data.err_msg)),
|
||||
// clean exit
|
||||
none => result::ok(())
|
||||
None => result::ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -874,11 +874,11 @@ fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint)
|
|||
timer::recv_timeout(
|
||||
iotask, timeout_msecs, result::get(rs_result))
|
||||
} else {
|
||||
some(core::comm::recv(result::get(rs_result)))
|
||||
Some(core::comm::recv(result::get(rs_result)))
|
||||
};
|
||||
log(debug, ~"tcp::read after recv_timeout");
|
||||
match read_result {
|
||||
none => {
|
||||
None => {
|
||||
log(debug, ~"tcp::read: timed out..");
|
||||
let err_data = {
|
||||
err_name: ~"TIMEOUT",
|
||||
|
|
@ -887,7 +887,7 @@ fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint)
|
|||
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
|
||||
|
|
@ -900,25 +900,25 @@ fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint)
|
|||
fn read_stop_common_impl(socket_data: *tcp_socket_data) ->
|
||||
result::result<(), tcp_err_data> unsafe {
|
||||
let stream_handle_ptr = (*socket_data).stream_handle_ptr;
|
||||
let stop_po = core::comm::port::<option<tcp_err_data>>();
|
||||
let stop_po = core::comm::port::<Option<tcp_err_data>>();
|
||||
let stop_ch = core::comm::chan(stop_po);
|
||||
do iotask::interact((*socket_data).iotask) |loop_ptr| unsafe {
|
||||
log(debug, ~"in interact cb for tcp::read_stop");
|
||||
match uv::ll::read_stop(stream_handle_ptr as *uv::ll::uv_stream_t) {
|
||||
0i32 => {
|
||||
log(debug, ~"successfully called uv_read_stop");
|
||||
core::comm::send(stop_ch, none);
|
||||
core::comm::send(stop_ch, None);
|
||||
}
|
||||
_ => {
|
||||
log(debug, ~"failure in calling uv_read_stop");
|
||||
let err_data = uv::ll::get_last_err_data(loop_ptr);
|
||||
core::comm::send(stop_ch, some(err_data.to_tcp_err()));
|
||||
core::comm::send(stop_ch, Some(err_data.to_tcp_err()));
|
||||
}
|
||||
}
|
||||
};
|
||||
match core::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(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -927,7 +927,7 @@ fn read_start_common_impl(socket_data: *tcp_socket_data)
|
|||
-> result::result<comm::Port<
|
||||
result::result<~[u8], tcp_err_data>>, tcp_err_data> unsafe {
|
||||
let stream_handle_ptr = (*socket_data).stream_handle_ptr;
|
||||
let start_po = core::comm::port::<option<uv::ll::uv_err_data>>();
|
||||
let start_po = core::comm::port::<Option<uv::ll::uv_err_data>>();
|
||||
let start_ch = core::comm::chan(start_po);
|
||||
log(debug, ~"in tcp::read_start before interact loop");
|
||||
do iotask::interact((*socket_data).iotask) |loop_ptr| unsafe {
|
||||
|
|
@ -937,18 +937,18 @@ fn read_start_common_impl(socket_data: *tcp_socket_data)
|
|||
on_tcp_read_cb) {
|
||||
0i32 => {
|
||||
log(debug, ~"success doing uv_read_start");
|
||||
core::comm::send(start_ch, none);
|
||||
core::comm::send(start_ch, None);
|
||||
}
|
||||
_ => {
|
||||
log(debug, ~"error attempting uv_read_start");
|
||||
let err_data = uv::ll::get_last_err_data(loop_ptr);
|
||||
core::comm::send(start_ch, some(err_data));
|
||||
core::comm::send(start_ch, Some(err_data));
|
||||
}
|
||||
}
|
||||
};
|
||||
match core::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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1005,7 +1005,7 @@ enum tcp_new_connection {
|
|||
type tcp_listen_fc_data = {
|
||||
server_stream_ptr: *uv::ll::uv_tcp_t,
|
||||
stream_closed_ch: comm::Chan<()>,
|
||||
kill_ch: comm::Chan<option<tcp_err_data>>,
|
||||
kill_ch: comm::Chan<Option<tcp_err_data>>,
|
||||
on_connect_cb: fn~(*uv::ll::uv_tcp_t),
|
||||
iotask: iotask,
|
||||
mut active: bool
|
||||
|
|
@ -1028,7 +1028,7 @@ extern fn tcp_lfc_on_connection_cb(handle: *uv::ll::uv_tcp_t,
|
|||
_ => {
|
||||
let loop_ptr = uv::ll::get_loop_for_uv_handle(handle);
|
||||
core::comm::send(kill_ch,
|
||||
some(uv::ll::get_last_err_data(loop_ptr)
|
||||
Some(uv::ll::get_last_err_data(loop_ptr)
|
||||
.to_tcp_err()));
|
||||
(*server_data_ptr).active = false;
|
||||
}
|
||||
|
|
@ -1505,7 +1505,7 @@ mod test {
|
|||
if result::is_err(accept_result) {
|
||||
log(debug, ~"SERVER: error accept connection");
|
||||
let err_data = result::get_err(accept_result);
|
||||
core::comm::send(kill_ch, some(err_data));
|
||||
core::comm::send(kill_ch, Some(err_data));
|
||||
log(debug,
|
||||
~"SERVER/WORKER: send on err cont ch");
|
||||
cont_ch.send(());
|
||||
|
|
@ -1528,12 +1528,12 @@ mod test {
|
|||
log(debug, ~"SERVER: before write");
|
||||
tcp_write_single(sock, str::to_bytes(resp));
|
||||
log(debug, ~"SERVER: after write.. die");
|
||||
core::comm::send(kill_ch, none);
|
||||
core::comm::send(kill_ch, None);
|
||||
}
|
||||
result::err(err_data) => {
|
||||
log(debug, fmt!("SERVER: error recvd: %s %s",
|
||||
err_data.err_name, err_data.err_msg));
|
||||
core::comm::send(kill_ch, some(err_data));
|
||||
core::comm::send(kill_ch, Some(err_data));
|
||||
server_ch.send(~"");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,29 +15,29 @@ export encode_form_urlencoded, decode_form_urlencoded;
|
|||
|
||||
type url = {
|
||||
scheme: ~str,
|
||||
user: option<userinfo>,
|
||||
user: Option<userinfo>,
|
||||
host: ~str,
|
||||
port: option<~str>,
|
||||
port: Option<~str>,
|
||||
path: ~str,
|
||||
query: query,
|
||||
fragment: option<~str>
|
||||
fragment: Option<~str>
|
||||
};
|
||||
|
||||
type userinfo = {
|
||||
user: ~str,
|
||||
pass: option<~str>
|
||||
pass: Option<~str>
|
||||
};
|
||||
|
||||
type query = ~[(~str, ~str)];
|
||||
|
||||
fn url(-scheme: ~str, -user: option<userinfo>, -host: ~str,
|
||||
-port: option<~str>, -path: ~str, -query: query,
|
||||
-fragment: option<~str>) -> url {
|
||||
fn url(-scheme: ~str, -user: Option<userinfo>, -host: ~str,
|
||||
-port: Option<~str>, -path: ~str, -query: query,
|
||||
-fragment: Option<~str>) -> url {
|
||||
{ scheme: scheme, user: user, host: host, port: port,
|
||||
path: path, query: query, fragment: fragment }
|
||||
}
|
||||
|
||||
fn userinfo(-user: ~str, -pass: option<~str>) -> userinfo {
|
||||
fn userinfo(-user: ~str, -pass: Option<~str>) -> userinfo {
|
||||
{user: user, pass: pass}
|
||||
}
|
||||
|
||||
|
|
@ -215,8 +215,8 @@ fn decode_form_urlencoded(s: ~[u8]) ->
|
|||
'&' | ';' => {
|
||||
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
|
||||
|
|
@ -250,8 +250,8 @@ fn decode_form_urlencoded(s: ~[u8]) ->
|
|||
|
||||
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
|
||||
|
|
@ -292,9 +292,9 @@ fn split_char_first(s: ~str, c: char) -> (~str, ~str) {
|
|||
fn userinfo_from_str(uinfo: ~str) -> userinfo {
|
||||
let (user, p) = split_char_first(uinfo, ':');
|
||||
let pass = if str::len(p) == 0 {
|
||||
option::none
|
||||
option::None
|
||||
} else {
|
||||
option::some(p)
|
||||
option::Some(p)
|
||||
};
|
||||
return userinfo(user, pass);
|
||||
}
|
||||
|
|
@ -358,10 +358,10 @@ fn get_scheme(rawurl: ~str) -> result::result<(~str, ~str), @~str> {
|
|||
|
||||
// returns userinfo, host, port, and unparsed part, or an error
|
||||
fn get_authority(rawurl: ~str) ->
|
||||
result::result<(option<userinfo>, ~str, option<~str>, ~str), @~str> {
|
||||
result::result<(Option<userinfo>, ~str, Option<~str>, ~str), @~str> {
|
||||
if !str::starts_with(rawurl, ~"//") {
|
||||
// there is no authority.
|
||||
return result::ok((option::none, ~"", option::none, copy rawurl));
|
||||
return result::ok((option::None, ~"", option::None, copy rawurl));
|
||||
}
|
||||
|
||||
enum state {
|
||||
|
|
@ -381,9 +381,9 @@ fn get_authority(rawurl: ~str) ->
|
|||
let mut st : state = start;
|
||||
let mut in : input = digit; // most restricted, start here.
|
||||
|
||||
let mut userinfo : option<userinfo> = option::none;
|
||||
let mut userinfo : Option<userinfo> = option::None;
|
||||
let mut host : ~str = ~"";
|
||||
let mut port : option::option<~str> = option::none;
|
||||
let mut port : option::Option<~str> = option::None;
|
||||
|
||||
let mut colon_count = 0;
|
||||
let mut pos : uint = 0, begin : uint = 2, end : uint = len;
|
||||
|
|
@ -462,15 +462,15 @@ fn get_authority(rawurl: ~str) ->
|
|||
match st {
|
||||
start => {
|
||||
let user = str::slice(rawurl, begin, i);
|
||||
userinfo = option::some({user : user,
|
||||
pass: option::none});
|
||||
userinfo = option::Some({user : user,
|
||||
pass: option::None});
|
||||
st = in_host;
|
||||
}
|
||||
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)});
|
||||
userinfo = option::Some({user: user,
|
||||
pass: option::Some(pass)});
|
||||
st = in_host;
|
||||
}
|
||||
_ => {
|
||||
|
|
@ -510,7 +510,7 @@ fn get_authority(rawurl: ~str) ->
|
|||
return result::err(@~"Non-digit characters in port.");
|
||||
}
|
||||
host = str::slice(rawurl, begin, pos);
|
||||
port = option::some(str::slice(rawurl, pos+1, end));
|
||||
port = option::Some(str::slice(rawurl, pos+1, end));
|
||||
}
|
||||
ip6_host | in_host => {
|
||||
host = str::slice(rawurl, begin, end);
|
||||
|
|
@ -519,7 +519,7 @@ fn get_authority(rawurl: ~str) ->
|
|||
if in != digit {
|
||||
return result::err(@~"Non-digit characters in port.");
|
||||
}
|
||||
port = option::some(str::slice(rawurl, pos+1, end));
|
||||
port = option::Some(str::slice(rawurl, pos+1, end));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -562,21 +562,21 @@ fn get_path(rawurl: ~str, authority : bool) ->
|
|||
|
||||
// returns the parsed query and the fragment, if present
|
||||
fn get_query_fragment(rawurl: ~str) ->
|
||||
result::result<(query, option<~str>), @~str> {
|
||||
result::result<(query, Option<~str>), @~str> {
|
||||
if !str::starts_with(rawurl, ~"?") {
|
||||
if str::starts_with(rawurl, ~"#") {
|
||||
let f = decode_component(str::slice(rawurl,
|
||||
1,
|
||||
str::len(rawurl)));
|
||||
return result::ok((~[], option::some(f)));
|
||||
return result::ok((~[], option::Some(f)));
|
||||
} else {
|
||||
return result::ok((~[], option::none));
|
||||
return result::ok((~[], option::None));
|
||||
}
|
||||
}
|
||||
let (q, r) = split_char_first(str::slice(rawurl, 1,
|
||||
str::len(rawurl)), '#');
|
||||
let f = if str::len(r) != 0 {
|
||||
option::some(decode_component(r)) } else { option::none };
|
||||
option::Some(decode_component(r)) } else { option::None };
|
||||
return result::ok((query_from_str(q), f));
|
||||
}
|
||||
|
||||
|
|
@ -696,8 +696,8 @@ mod tests {
|
|||
fn test_get_authority() {
|
||||
let (u, h, p, r) = result::unwrap(get_authority(
|
||||
~"//user:pass@rust-lang.org/something"));
|
||||
assert u == option::some({user: ~"user",
|
||||
pass: option::some(~"pass")});
|
||||
assert u == option::Some({user: ~"user",
|
||||
pass: option::Some(~"pass")});
|
||||
assert h == ~"rust-lang.org";
|
||||
assert option::is_none(p);
|
||||
assert r == ~"/something";
|
||||
|
|
@ -706,7 +706,7 @@ mod tests {
|
|||
~"//rust-lang.org:8000?something"));
|
||||
assert option::is_none(u);
|
||||
assert h == ~"rust-lang.org";
|
||||
assert p == option::some(~"8000");
|
||||
assert p == option::Some(~"8000");
|
||||
assert r == ~"?something";
|
||||
|
||||
let (u, h, p, r) = result::unwrap(get_authority(
|
||||
|
|
@ -724,13 +724,13 @@ mod tests {
|
|||
let (_, h, p, _) = result::unwrap(get_authority(
|
||||
~"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah"));
|
||||
assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334";
|
||||
assert p == option::some(~"8000");
|
||||
assert p == option::Some(~"8000");
|
||||
|
||||
let (u, h, p, _) = result::unwrap(get_authority(
|
||||
~"//us:p@2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah"));
|
||||
assert u == option::some({user: ~"us", pass : option::some(~"p")});
|
||||
assert u == option::Some({user: ~"us", pass : option::Some(~"p")});
|
||||
assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334";
|
||||
assert p == option::some(~"8000");
|
||||
assert p == option::Some(~"8000");
|
||||
|
||||
// invalid authorities;
|
||||
assert result::is_err(get_authority(
|
||||
|
|
|
|||
|
|
@ -200,8 +200,8 @@ fn bal(rope:rope) -> rope {
|
|||
match (rope) {
|
||||
node::empty => return rope,
|
||||
node::content(x) => match (node::bal(x)) {
|
||||
option::none => rope,
|
||||
option::some(y) => node::content(y)
|
||||
option::None => rope,
|
||||
option::Some(y) => node::content(y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -436,7 +436,7 @@ mod iterator {
|
|||
node::content(x) => return node::leaf_iterator::start(x)
|
||||
}
|
||||
}
|
||||
fn next(it: node::leaf_iterator::t) -> option<node::leaf> {
|
||||
fn next(it: node::leaf_iterator::t) -> Option<node::leaf> {
|
||||
return node::leaf_iterator::next(it);
|
||||
}
|
||||
}
|
||||
|
|
@ -447,7 +447,7 @@ mod iterator {
|
|||
node::content(x) => return node::char_iterator::start(x)
|
||||
}
|
||||
}
|
||||
fn next(it: node::char_iterator::t) -> option<char> {
|
||||
fn next(it: node::char_iterator::t) -> Option<char> {
|
||||
return node::char_iterator::next(it)
|
||||
}
|
||||
}
|
||||
|
|
@ -801,8 +801,8 @@ mod node {
|
|||
let it = leaf_iterator::start(node);
|
||||
loop {
|
||||
match (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);
|
||||
|
|
@ -851,24 +851,24 @@ mod node {
|
|||
*
|
||||
* # Return value
|
||||
*
|
||||
* * `option::none` if no transformation happened
|
||||
* * `option::None` if no transformation happened
|
||||
* * `option::some(x)` otherwise, in which case `x` has the same contents
|
||||
* as `node` bot lower height and/or fragmentation.
|
||||
*/
|
||||
fn bal(node: @node) -> option<@node> {
|
||||
if height(node) < hint_max_node_height { return option::none; }
|
||||
fn bal(node: @node) -> Option<@node> {
|
||||
if height(node) < hint_max_node_height { return option::None; }
|
||||
//1. Gather all leaves as a forest
|
||||
let mut forest = ~[mut];
|
||||
let it = leaf_iterator::start(node);
|
||||
loop {
|
||||
match (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
|
||||
let root = @*tree_from_forest_destructive(forest);
|
||||
return option::some(root);
|
||||
return option::Some(root);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1019,14 +1019,14 @@ mod node {
|
|||
let mut result = 0;
|
||||
while result == 0 {
|
||||
match ((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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1121,8 +1121,8 @@ mod node {
|
|||
}
|
||||
}
|
||||
|
||||
fn next(it: t) -> option<leaf> {
|
||||
if it.stackpos < 0 { return option::none; }
|
||||
fn next(it: t) -> Option<leaf> {
|
||||
if it.stackpos < 0 { return option::None; }
|
||||
loop {
|
||||
let current = it.stack[it.stackpos];
|
||||
it.stackpos -= 1;
|
||||
|
|
@ -1133,7 +1133,7 @@ mod node {
|
|||
it.stackpos += 1;
|
||||
it.stack[it.stackpos] = x.left;
|
||||
}
|
||||
leaf(x) => return option::some(x)
|
||||
leaf(x) => return option::Some(x)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -1142,14 +1142,14 @@ mod node {
|
|||
mod char_iterator {
|
||||
type t = {
|
||||
leaf_iterator: leaf_iterator::t,
|
||||
mut leaf: option<leaf>,
|
||||
mut leaf: Option<leaf>,
|
||||
mut leaf_byte_pos: uint
|
||||
};
|
||||
|
||||
fn start(node: @node) -> t {
|
||||
return {
|
||||
leaf_iterator: leaf_iterator::start(node),
|
||||
mut leaf: option::none,
|
||||
mut leaf: option::None,
|
||||
mut leaf_byte_pos: 0u
|
||||
}
|
||||
}
|
||||
|
|
@ -1157,34 +1157,34 @@ mod node {
|
|||
fn empty() -> t {
|
||||
return {
|
||||
leaf_iterator: leaf_iterator::empty(),
|
||||
mut leaf: option::none,
|
||||
mut leaf: option::None,
|
||||
mut leaf_byte_pos: 0u
|
||||
}
|
||||
}
|
||||
|
||||
fn next(it: t) -> option<char> {
|
||||
fn next(it: t) -> Option<char> {
|
||||
loop {
|
||||
match (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);
|
||||
match (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> {
|
||||
fn get_current_or_next_leaf(it: t) -> Option<leaf> {
|
||||
match (it.leaf) {
|
||||
option::some(_) => return it.leaf,
|
||||
option::none => {
|
||||
option::Some(_) => return it.leaf,
|
||||
option::None => {
|
||||
let next = leaf_iterator::next(it.leaf_iterator);
|
||||
match (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;
|
||||
|
|
@ -1194,20 +1194,20 @@ mod node {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_next_char_in_leaf(it: t) -> option<char> {
|
||||
fn get_next_char_in_leaf(it: t) -> Option<char> {
|
||||
match 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;
|
||||
return option::none
|
||||
it.leaf = option::None;
|
||||
return option::None
|
||||
} else {
|
||||
let {ch, next} =
|
||||
str::char_range_at(*aleaf.content,
|
||||
it.leaf_byte_pos + aleaf.byte_offset);
|
||||
it.leaf_byte_pos = next - aleaf.byte_offset;
|
||||
return option::some(ch)
|
||||
return option::Some(ch)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1275,11 +1275,11 @@ mod tests {
|
|||
let mut equal = true;
|
||||
while equal {
|
||||
match (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; }
|
||||
|
|
@ -1302,8 +1302,8 @@ mod tests {
|
|||
let it = iterator::char::start(r);
|
||||
loop {
|
||||
match (node::char_iterator::next(it)) {
|
||||
option::none => break,
|
||||
option::some(_) => len += 1u
|
||||
option::None => break,
|
||||
option::Some(_) => len += 1u
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -241,13 +241,13 @@ fn deserialize_bool<D: deserializer>(d: D) -> bool {
|
|||
d.read_bool()
|
||||
}
|
||||
|
||||
fn serialize_option<S: serializer,T>(s: S, v: option<T>, st: fn(T)) {
|
||||
fn serialize_Option<S: serializer,T>(s: S, v: Option<T>, st: fn(T)) {
|
||||
do s.emit_enum(~"option") {
|
||||
match 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) {
|
||||
Some(v) => do s.emit_enum_variant(~"some", 1u, 1u) {
|
||||
do s.emit_enum_variant_arg(0u) {
|
||||
st(v)
|
||||
}
|
||||
|
|
@ -256,13 +256,13 @@ fn serialize_option<S: serializer,T>(s: S, v: option<T>, st: fn(T)) {
|
|||
}
|
||||
}
|
||||
|
||||
fn deserialize_option<D: deserializer,T: copy>(d: D, st: fn() -> T)
|
||||
-> option<T> {
|
||||
fn deserialize_Option<D: deserializer,T: copy>(d: D, st: fn() -> T)
|
||||
-> Option<T> {
|
||||
do d.read_enum(~"option") {
|
||||
do d.read_enum_variant |i| {
|
||||
match i {
|
||||
0 => none,
|
||||
1 => some(d.read_enum_variant_arg(0u, || st() )),
|
||||
0 => None,
|
||||
1 => Some(d.read_enum_variant_arg(0u, || st() )),
|
||||
_ => fail(#fmt("Bad variant for option: %u", i))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@
|
|||
* are O(highest integer key).
|
||||
*/
|
||||
import core::option;
|
||||
import core::option::{some, none};
|
||||
import core::option::{Some, None};
|
||||
import dvec::{DVec, dvec};
|
||||
import map::map;
|
||||
|
||||
// FIXME (#2347): Should not be @; there's a bug somewhere in rustc that
|
||||
// requires this to be.
|
||||
type smallintmap_<T: copy> = {v: DVec<option<T>>};
|
||||
type smallintmap_<T: copy> = {v: DVec<Option<T>>};
|
||||
|
||||
enum smallintmap<T:copy> {
|
||||
smallintmap_(@smallintmap_<T>)
|
||||
|
|
@ -28,16 +28,16 @@ fn mk<T: copy>() -> smallintmap<T> {
|
|||
#[inline(always)]
|
||||
fn insert<T: copy>(self: smallintmap<T>, key: uint, val: T) {
|
||||
//io::println(fmt!("%?", key));
|
||||
self.v.grow_set_elt(key, none, some(val));
|
||||
self.v.grow_set_elt(key, None, Some(val));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for the specified key. If the key does not exist
|
||||
* in the map then returns none
|
||||
*/
|
||||
pure fn find<T: copy>(self: smallintmap<T>, key: uint) -> option<T> {
|
||||
pure fn find<T: copy>(self: smallintmap<T>, key: uint) -> Option<T> {
|
||||
if key < self.v.len() { return self.v.get_elt(key); }
|
||||
return none::<T>;
|
||||
return None::<T>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -49,11 +49,11 @@ pure fn find<T: copy>(self: smallintmap<T>, key: uint) -> option<T> {
|
|||
*/
|
||||
pure fn get<T: copy>(self: smallintmap<T>, key: uint) -> T {
|
||||
match find(self, key) {
|
||||
none => {
|
||||
None => {
|
||||
error!("smallintmap::get(): key not present");
|
||||
fail;
|
||||
}
|
||||
some(v) => return v
|
||||
Some(v) => return v
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ impl<V: copy> smallintmap<V>: map::map<uint, V> {
|
|||
let mut sz = 0u;
|
||||
for self.v.each |item| {
|
||||
match item {
|
||||
some(_) => sz += 1u,
|
||||
Some(_) => sz += 1u,
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
|
@ -85,7 +85,7 @@ impl<V: copy> smallintmap<V>: map::map<uint, V> {
|
|||
return false;
|
||||
}
|
||||
let old = self.v.get_elt(key);
|
||||
self.v.set_elt(key, none);
|
||||
self.v.set_elt(key, None);
|
||||
old.is_some()
|
||||
}
|
||||
fn clear() {
|
||||
|
|
@ -98,14 +98,14 @@ impl<V: copy> smallintmap<V>: map::map<uint, V> {
|
|||
contains_key(self, *key)
|
||||
}
|
||||
fn get(+key: uint) -> V { get(self, key) }
|
||||
fn find(+key: uint) -> option<V> { find(self, key) }
|
||||
fn find(+key: uint) -> Option<V> { find(self, key) }
|
||||
fn rehash() { fail }
|
||||
fn each(it: fn(+key: uint, +value: V) -> bool) {
|
||||
let mut idx = 0u, l = self.v.len();
|
||||
while idx < l {
|
||||
match self.v.get_elt(idx) {
|
||||
some(elt) => if !it(idx, elt) { break },
|
||||
none => ()
|
||||
Some(elt) => if !it(idx, elt) { break },
|
||||
None => ()
|
||||
}
|
||||
idx += 1u;
|
||||
}
|
||||
|
|
@ -120,8 +120,8 @@ impl<V: copy> smallintmap<V>: map::map<uint, V> {
|
|||
let mut idx = 0u, l = self.v.len();
|
||||
while idx < l {
|
||||
match self.v.get_elt(idx) {
|
||||
some(elt) => if !it(&idx, &elt) { break },
|
||||
none => ()
|
||||
Some(elt) => if !it(&idx, &elt) { break },
|
||||
None => ()
|
||||
}
|
||||
idx += 1u;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ fn new_sem_and_signal(count: int, num_condvars: uint)
|
|||
#[doc(hidden)]
|
||||
impl<Q: send> &sem<Q> {
|
||||
fn acquire() {
|
||||
let mut waiter_nobe = none;
|
||||
let mut waiter_nobe = None;
|
||||
unsafe {
|
||||
do (**self).with |state| {
|
||||
state.count -= 1;
|
||||
|
|
@ -98,7 +98,7 @@ impl<Q: send> &sem<Q> {
|
|||
// Create waiter nobe.
|
||||
let (signal_end, wait_end) = pipes::oneshot();
|
||||
// Tell outer scope we need to block.
|
||||
waiter_nobe = some(wait_end);
|
||||
waiter_nobe = Some(wait_end);
|
||||
// Enqueue ourself.
|
||||
state.waiters.tail.send(signal_end);
|
||||
}
|
||||
|
|
@ -126,11 +126,11 @@ impl<Q: send> &sem<Q> {
|
|||
#[doc(hidden)]
|
||||
impl &sem<()> {
|
||||
fn access<U>(blk: fn() -> U) -> U {
|
||||
let mut release = none;
|
||||
let mut release = None;
|
||||
unsafe {
|
||||
do task::unkillable {
|
||||
self.acquire();
|
||||
release = some(sem_release(self));
|
||||
release = Some(sem_release(self));
|
||||
}
|
||||
}
|
||||
blk()
|
||||
|
|
@ -139,11 +139,11 @@ impl &sem<()> {
|
|||
#[doc(hidden)]
|
||||
impl &sem<~[mut waitqueue]> {
|
||||
fn access<U>(blk: fn() -> U) -> U {
|
||||
let mut release = none;
|
||||
let mut release = None;
|
||||
unsafe {
|
||||
do task::unkillable {
|
||||
self.acquire();
|
||||
release = some(sem_and_signal_release(self));
|
||||
release = Some(sem_and_signal_release(self));
|
||||
}
|
||||
}
|
||||
blk()
|
||||
|
|
@ -191,10 +191,10 @@ impl &condvar {
|
|||
fn wait_on(condvar_id: uint) {
|
||||
// Create waiter nobe.
|
||||
let (signal_end, wait_end) = pipes::oneshot();
|
||||
let mut wait_end = some(wait_end);
|
||||
let mut signal_end = some(signal_end);
|
||||
let mut reacquire = none;
|
||||
let mut out_of_bounds = none;
|
||||
let mut wait_end = Some(wait_end);
|
||||
let mut signal_end = Some(signal_end);
|
||||
let mut reacquire = None;
|
||||
let mut out_of_bounds = None;
|
||||
unsafe {
|
||||
do task::unkillable {
|
||||
// Release lock, 'atomically' enqueuing ourselves in so doing.
|
||||
|
|
@ -209,7 +209,7 @@ impl &condvar {
|
|||
let signal_end = option::swap_unwrap(&mut signal_end);
|
||||
state.blocked[condvar_id].tail.send(signal_end);
|
||||
} else {
|
||||
out_of_bounds = some(vec::len(state.blocked));
|
||||
out_of_bounds = Some(vec::len(state.blocked));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -218,7 +218,7 @@ impl &condvar {
|
|||
// unkillably reacquire the lock needs to happen atomically
|
||||
// wrt enqueuing.
|
||||
if out_of_bounds.is_none() {
|
||||
reacquire = some(sem_and_signal_reacquire(self.sem));
|
||||
reacquire = Some(sem_and_signal_reacquire(self.sem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -248,14 +248,14 @@ impl &condvar {
|
|||
fn signal() -> bool { self.signal_on(0) }
|
||||
/// As signal, but with a specified condvar_id. See wait_on.
|
||||
fn signal_on(condvar_id: uint) -> bool {
|
||||
let mut out_of_bounds = none;
|
||||
let mut out_of_bounds = None;
|
||||
let mut result = false;
|
||||
unsafe {
|
||||
do (**self.sem).with |state| {
|
||||
if condvar_id < vec::len(state.blocked) {
|
||||
result = signal_waitqueue(&state.blocked[condvar_id]);
|
||||
} else {
|
||||
out_of_bounds = some(vec::len(state.blocked));
|
||||
out_of_bounds = Some(vec::len(state.blocked));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -268,18 +268,18 @@ impl &condvar {
|
|||
fn broadcast() -> uint { self.broadcast_on(0) }
|
||||
/// As broadcast, but with a specified condvar_id. See wait_on.
|
||||
fn broadcast_on(condvar_id: uint) -> uint {
|
||||
let mut out_of_bounds = none;
|
||||
let mut queue = none;
|
||||
let mut out_of_bounds = None;
|
||||
let mut queue = None;
|
||||
unsafe {
|
||||
do (**self.sem).with |state| {
|
||||
if condvar_id < vec::len(state.blocked) {
|
||||
// To avoid :broadcast_heavy, we make a new waitqueue,
|
||||
// swap it out with the old one, and broadcast on the
|
||||
// old one outside of the little-lock.
|
||||
queue = some(util::replace(&mut state.blocked[condvar_id],
|
||||
queue = Some(util::replace(&mut state.blocked[condvar_id],
|
||||
new_waitqueue()));
|
||||
} else {
|
||||
out_of_bounds = some(vec::len(state.blocked));
|
||||
out_of_bounds = Some(vec::len(state.blocked));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -294,16 +294,16 @@ impl &condvar {
|
|||
// something else next on success.
|
||||
#[inline(always)]
|
||||
#[doc(hidden)]
|
||||
fn check_cvar_bounds<U>(out_of_bounds: option<uint>, id: uint, act: &str,
|
||||
fn check_cvar_bounds<U>(out_of_bounds: Option<uint>, id: uint, act: &str,
|
||||
blk: fn() -> U) -> U {
|
||||
match out_of_bounds {
|
||||
some(0) =>
|
||||
Some(0) =>
|
||||
fail fmt!("%s with illegal ID %u - this lock has no condvars!",
|
||||
act, id),
|
||||
some(length) =>
|
||||
Some(length) =>
|
||||
fail fmt!("%s with illegal ID %u - ID must be less than %u",
|
||||
act, id, length),
|
||||
none => blk()
|
||||
None => blk()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -438,7 +438,7 @@ impl &rwlock {
|
|||
* tasks may run concurrently with this one.
|
||||
*/
|
||||
fn read<U>(blk: fn() -> U) -> U {
|
||||
let mut release = none;
|
||||
let mut release = None;
|
||||
unsafe {
|
||||
do task::unkillable {
|
||||
do (&self.order_lock).access {
|
||||
|
|
@ -458,7 +458,7 @@ impl &rwlock {
|
|||
}
|
||||
}
|
||||
}
|
||||
release = some(rwlock_release_read(self));
|
||||
release = Some(rwlock_release_read(self));
|
||||
}
|
||||
}
|
||||
blk()
|
||||
|
|
@ -524,14 +524,14 @@ impl &rwlock {
|
|||
fn write_downgrade<U>(blk: fn(+rwlock_write_mode) -> U) -> U {
|
||||
// Implementation slightly different from the slicker 'write's above.
|
||||
// The exit path is conditional on whether the caller downgrades.
|
||||
let mut _release = none;
|
||||
let mut _release = None;
|
||||
unsafe {
|
||||
do task::unkillable {
|
||||
(&self.order_lock).acquire();
|
||||
(&self.access_lock).acquire();
|
||||
(&self.order_lock).release();
|
||||
}
|
||||
_release = some(rwlock_release_downgrade(self));
|
||||
_release = Some(rwlock_release_downgrade(self));
|
||||
}
|
||||
blk(rwlock_write_mode { lock: self })
|
||||
}
|
||||
|
|
@ -723,7 +723,7 @@ mod tests {
|
|||
let s = ~semaphore(1);
|
||||
let s2 = ~s.clone();
|
||||
let (c,p) = pipes::stream();
|
||||
let child_data = ~mut some((s2,c));
|
||||
let child_data = ~mut Some((s2,c));
|
||||
do s.access {
|
||||
let (s2,c) = option::swap_unwrap(child_data);
|
||||
do task::spawn {
|
||||
|
|
@ -900,7 +900,7 @@ mod tests {
|
|||
let mut sibling_convos = ~[];
|
||||
for 2.times {
|
||||
let (c,p) = pipes::stream();
|
||||
let c = ~mut some(c);
|
||||
let c = ~mut Some(c);
|
||||
vec::push(sibling_convos, p);
|
||||
let mi = ~m2.clone();
|
||||
// spawn sibling task
|
||||
|
|
@ -1234,7 +1234,7 @@ mod tests {
|
|||
let x = ~rwlock();
|
||||
let y = ~rwlock();
|
||||
do x.write_downgrade |xwrite| {
|
||||
let mut xopt = some(xwrite);
|
||||
let mut xopt = Some(xwrite);
|
||||
do y.write_downgrade |_ywrite| {
|
||||
y.downgrade(option::swap_unwrap(&mut xopt));
|
||||
error!("oops, y.downgrade(x) should have failed!");
|
||||
|
|
|
|||
|
|
@ -1,28 +1,28 @@
|
|||
//! Temporary files and directories
|
||||
|
||||
import core::option;
|
||||
import option::{none, some};
|
||||
import option::{None, Some};
|
||||
import rand;
|
||||
|
||||
fn mkdtemp(tmpdir: &Path, suffix: &str) -> option<Path> {
|
||||
fn mkdtemp(tmpdir: &Path, suffix: &str) -> Option<Path> {
|
||||
let r = rand::rng();
|
||||
let mut i = 0u;
|
||||
while (i < 1000u) {
|
||||
let p = tmpdir.push(r.gen_str(16u) +
|
||||
str::from_slice(suffix));
|
||||
if os::make_dir(&p, 0x1c0i32) { // FIXME: u+rwx (#2349)
|
||||
return some(p);
|
||||
return Some(p);
|
||||
}
|
||||
i += 1u;
|
||||
}
|
||||
return none;
|
||||
return None;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mkdtemp() {
|
||||
let r = mkdtemp(&Path("."), "foobar");
|
||||
match r {
|
||||
some(p) => {
|
||||
Some(p) => {
|
||||
os::remove_dir(&p);
|
||||
assert(str::ends_with(p.to_str(), "foobar"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! Simple ANSI color library
|
||||
|
||||
import core::option;
|
||||
import core::Option;
|
||||
|
||||
// FIXME (#2807): Windows support.
|
||||
|
||||
|
|
@ -36,13 +36,13 @@ fn color_supported() -> bool {
|
|||
let supported_terms = ~[~"xterm-color", ~"xterm",
|
||||
~"screen-bce", ~"xterm-256color"];
|
||||
return match 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
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,8 +60,8 @@ fn test_main(args: ~[~str], tests: ~[test_desc]) {
|
|||
if !run_tests_console(opts, tests) { fail ~"Some tests failed"; }
|
||||
}
|
||||
|
||||
type test_opts = {filter: option<~str>, run_ignored: bool,
|
||||
logfile: option<~str>};
|
||||
type test_opts = {filter: Option<~str>, run_ignored: bool,
|
||||
logfile: Option<~str>};
|
||||
|
||||
type opt_res = Either<test_opts, ~str>;
|
||||
|
||||
|
|
@ -77,8 +77,8 @@ fn parse_opts(args: ~[~str]) -> opt_res {
|
|||
|
||||
let filter =
|
||||
if vec::len(matches.free) > 0u {
|
||||
option::some(matches.free[0])
|
||||
} else { option::none };
|
||||
option::Some(matches.free[0])
|
||||
} else { option::None };
|
||||
|
||||
let run_ignored = getopts::opt_present(matches, ~"ignored");
|
||||
let logfile = getopts::opt_maybe_str(matches, ~"logfile");
|
||||
|
|
@ -93,7 +93,7 @@ enum test_result { tr_ok, tr_failed, tr_ignored, }
|
|||
|
||||
type console_test_state =
|
||||
@{out: io::Writer,
|
||||
log_out: option<io::Writer>,
|
||||
log_out: Option<io::Writer>,
|
||||
use_color: bool,
|
||||
mut total: uint,
|
||||
mut passed: uint,
|
||||
|
|
@ -115,8 +115,8 @@ fn run_tests_console(opts: test_opts,
|
|||
te_wait(test) => st.out.write_str(fmt!("test %s ... ", test.name)),
|
||||
te_result(test, result) => {
|
||||
match st.log_out {
|
||||
some(f) => write_log(f, result, test),
|
||||
none => ()
|
||||
Some(f) => write_log(f, result, test),
|
||||
None => ()
|
||||
}
|
||||
match result {
|
||||
tr_ok => {
|
||||
|
|
@ -141,14 +141,14 @@ fn run_tests_console(opts: test_opts,
|
|||
}
|
||||
|
||||
let log_out = match opts.logfile {
|
||||
some(path) => match io::file_writer(&Path(path),
|
||||
Some(path) => match io::file_writer(&Path(path),
|
||||
~[io::Create, io::Truncate]) {
|
||||
result::ok(w) => some(w),
|
||||
result::ok(w) => Some(w),
|
||||
result::err(s) => {
|
||||
fail(fmt!("can't open output file: %s", s))
|
||||
}
|
||||
},
|
||||
none => none
|
||||
None => None
|
||||
};
|
||||
|
||||
let st =
|
||||
|
|
@ -243,7 +243,7 @@ fn should_sort_failures_before_printing_them() {
|
|||
|
||||
let st =
|
||||
@{out: writer,
|
||||
log_out: option::none,
|
||||
log_out: option::None,
|
||||
use_color: false,
|
||||
mut total: 0u,
|
||||
mut passed: 0u,
|
||||
|
|
@ -337,15 +337,15 @@ fn filter_tests(opts: test_opts,
|
|||
} else {
|
||||
let filter_str =
|
||||
match opts.filter {
|
||||
option::some(f) => f,
|
||||
option::none => ~""
|
||||
option::Some(f) => f,
|
||||
option::None => ~""
|
||||
};
|
||||
|
||||
fn filter_fn(test: test_desc, filter_str: ~str) ->
|
||||
option<test_desc> {
|
||||
Option<test_desc> {
|
||||
if str::contains(test.name, filter_str) {
|
||||
return option::some(copy test);
|
||||
} else { return option::none; }
|
||||
return option::Some(copy test);
|
||||
} else { return option::None; }
|
||||
}
|
||||
|
||||
vec::filter_map(filtered, |x| filter_fn(x, filter_str))
|
||||
|
|
@ -355,13 +355,13 @@ fn filter_tests(opts: test_opts,
|
|||
filtered = if !opts.run_ignored {
|
||||
filtered
|
||||
} else {
|
||||
fn filter(test: test_desc) -> option<test_desc> {
|
||||
fn filter(test: test_desc) -> Option<test_desc> {
|
||||
if test.ignore {
|
||||
return option::some({name: test.name,
|
||||
return option::Some({name: test.name,
|
||||
fn: copy test.fn,
|
||||
ignore: false,
|
||||
should_fail: test.should_fail});
|
||||
} else { return option::none; }
|
||||
} else { return option::None; }
|
||||
};
|
||||
|
||||
vec::filter_map(filtered, |x| filter(x))
|
||||
|
|
@ -388,9 +388,9 @@ fn run_test(+test: test_desc, monitor_ch: comm::Chan<monitor_msg>) {
|
|||
|
||||
do task::spawn {
|
||||
let testfn = copy test.fn;
|
||||
let mut result_future = none; // task::future_result(builder);
|
||||
let mut result_future = None; // task::future_result(builder);
|
||||
task::task().unlinked().future_result(|+r| {
|
||||
result_future = some(r);
|
||||
result_future = Some(r);
|
||||
}).spawn(testfn);
|
||||
let task_result = future::get(&option::unwrap(result_future));
|
||||
let test_result = calc_result(test, task_result == task::Success);
|
||||
|
|
@ -501,8 +501,8 @@ mod tests {
|
|||
// When we run ignored tests the test filter should filter out all the
|
||||
// unignored tests and flip the ignore flag on the rest to false
|
||||
|
||||
let opts = {filter: option::none, run_ignored: true,
|
||||
logfile: option::none};
|
||||
let opts = {filter: option::None, run_ignored: true,
|
||||
logfile: option::None};
|
||||
let tests =
|
||||
~[{name: ~"1", fn: fn~() { }, ignore: true, should_fail: false},
|
||||
{name: ~"2", fn: fn~() { }, ignore: false, should_fail: false}];
|
||||
|
|
@ -515,8 +515,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn sort_tests() {
|
||||
let opts = {filter: option::none, run_ignored: false,
|
||||
logfile: option::none};
|
||||
let opts = {filter: option::None, run_ignored: false,
|
||||
logfile: option::None};
|
||||
|
||||
let names =
|
||||
~[~"sha1::test", ~"int::test_to_str", ~"int::test_pow",
|
||||
|
|
|
|||
|
|
@ -159,23 +159,23 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
|
|||
}
|
||||
|
||||
fn match_strs(ss: &str, pos: uint, strs: &[(~str, i32)])
|
||||
-> option<(i32, uint)> {
|
||||
-> Option<(i32, uint)> {
|
||||
let mut i = 0u;
|
||||
let len = vec::len(strs);
|
||||
while i < len {
|
||||
let (needle, value) = strs[i];
|
||||
|
||||
if match_str(ss, pos, needle) {
|
||||
return some((value, pos + str::len(needle)));
|
||||
return Some((value, pos + str::len(needle)));
|
||||
}
|
||||
i += 1u;
|
||||
}
|
||||
|
||||
none
|
||||
None
|
||||
}
|
||||
|
||||
fn match_digits(ss: &str, pos: uint, digits: uint, ws: bool)
|
||||
-> option<(i32, uint)> {
|
||||
-> Option<(i32, uint)> {
|
||||
let mut pos = pos;
|
||||
let mut value = 0_i32;
|
||||
|
||||
|
|
@ -189,12 +189,12 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
|
|||
value = value * 10_i32 + (ch as i32 - '0' as i32);
|
||||
}
|
||||
' ' if ws => (),
|
||||
_ => return none
|
||||
_ => return None
|
||||
}
|
||||
i += 1u;
|
||||
}
|
||||
|
||||
some((value, pos))
|
||||
Some((value, pos))
|
||||
}
|
||||
|
||||
fn parse_char(s: &str, pos: uint, c: char) -> result<uint, ~str> {
|
||||
|
|
@ -221,8 +221,8 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
|
|||
(~"Friday", 5_i32),
|
||||
(~"Saturday", 6_i32)
|
||||
]) {
|
||||
some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
|
||||
none => err(~"Invalid day")
|
||||
Some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
|
||||
None => err(~"Invalid day")
|
||||
},
|
||||
'a' => match match_strs(s, pos, ~[
|
||||
(~"Sun", 0_i32),
|
||||
|
|
@ -233,8 +233,8 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
|
|||
(~"Fri", 5_i32),
|
||||
(~"Sat", 6_i32)
|
||||
]) {
|
||||
some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
|
||||
none => err(~"Invalid day")
|
||||
Some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
|
||||
None => err(~"Invalid day")
|
||||
},
|
||||
'B' => match match_strs(s, pos, ~[
|
||||
(~"January", 0_i32),
|
||||
|
|
@ -250,8 +250,8 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
|
|||
(~"November", 10_i32),
|
||||
(~"December", 11_i32)
|
||||
]) {
|
||||
some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) }
|
||||
none => err(~"Invalid month")
|
||||
Some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) }
|
||||
None => err(~"Invalid month")
|
||||
},
|
||||
'b' | 'h' => match match_strs(s, pos, ~[
|
||||
(~"Jan", 0_i32),
|
||||
|
|
@ -267,16 +267,16 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
|
|||
(~"Nov", 10_i32),
|
||||
(~"Dec", 11_i32)
|
||||
]) {
|
||||
some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) }
|
||||
none => err(~"Invalid month")
|
||||
Some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) }
|
||||
None => err(~"Invalid month")
|
||||
},
|
||||
'C' => match match_digits(s, pos, 2u, false) {
|
||||
some(item) => {
|
||||
Some(item) => {
|
||||
let (v, pos) = item;
|
||||
tm.tm_year += (v * 100_i32) - 1900_i32;
|
||||
ok(pos)
|
||||
}
|
||||
none => err(~"Invalid year")
|
||||
None => err(~"Invalid year")
|
||||
},
|
||||
'c' => {
|
||||
parse_type(s, pos, 'a', tm)
|
||||
|
|
@ -297,12 +297,12 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
|
|||
.chain(|pos| parse_type(s, pos, 'y', tm))
|
||||
}
|
||||
'd' => match 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")
|
||||
Some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) }
|
||||
None => err(~"Invalid day of the month")
|
||||
},
|
||||
'e' => match 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")
|
||||
Some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) }
|
||||
None => err(~"Invalid day of the month")
|
||||
},
|
||||
'F' => {
|
||||
parse_type(s, pos, 'Y', tm)
|
||||
|
|
@ -314,80 +314,80 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
|
|||
'H' => {
|
||||
// FIXME (#2350): range check.
|
||||
match 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' => {
|
||||
// FIXME (#2350): range check.
|
||||
match 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' => {
|
||||
// FIXME (#2350): range check.
|
||||
match 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' => {
|
||||
// FIXME (#2350): range check.
|
||||
match 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' => {
|
||||
// FIXME (#2350): range check.
|
||||
match 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' => {
|
||||
// FIXME (#2350): range check.
|
||||
match 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' => {
|
||||
// FIXME (#2350): range check.
|
||||
match 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' => match 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")
|
||||
Some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) }
|
||||
None => err(~"Invalid hour")
|
||||
},
|
||||
'p' => match 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")
|
||||
Some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) }
|
||||
None => err(~"Invalid hour")
|
||||
},
|
||||
'R' => {
|
||||
parse_type(s, pos, 'H', tm)
|
||||
|
|
@ -406,12 +406,12 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
|
|||
'S' => {
|
||||
// FIXME (#2350): range check.
|
||||
match 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' {}
|
||||
|
|
@ -426,12 +426,12 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
|
|||
'u' => {
|
||||
// FIXME (#2350): range check.
|
||||
match 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' => {
|
||||
|
|
@ -445,8 +445,8 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
|
|||
'w' => {
|
||||
// FIXME (#2350): range check.
|
||||
match 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' {}
|
||||
|
|
@ -454,23 +454,23 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
|
|||
'Y' => {
|
||||
// FIXME (#2350): range check.
|
||||
match 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' => {
|
||||
// FIXME (#2350): range check.
|
||||
match 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' => {
|
||||
|
|
@ -497,7 +497,7 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
|
|||
|
||||
if ch == '+' || ch == '-' {
|
||||
match match_digits(s, next, 4u, false) {
|
||||
some(item) => {
|
||||
Some(item) => {
|
||||
let (v, pos) = item;
|
||||
if v == 0_i32 {
|
||||
tm.tm_gmtoff = 0_i32;
|
||||
|
|
@ -506,7 +506,7 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> {
|
|||
|
||||
ok(pos)
|
||||
}
|
||||
none => err(~"Invalid zone offset")
|
||||
None => err(~"Invalid zone offset")
|
||||
}
|
||||
} else {
|
||||
err(~"Invalid zone offset")
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ fn sleep(iotask: iotask, msecs: uint) {
|
|||
*/
|
||||
fn recv_timeout<T: copy send>(iotask: iotask,
|
||||
msecs: uint,
|
||||
wait_po: comm::Port<T>) -> option<T> {
|
||||
wait_po: comm::Port<T>) -> Option<T> {
|
||||
let timeout_po = comm::port::<()>();
|
||||
let timeout_ch = comm::chan(timeout_po);
|
||||
delayed_send(iotask, msecs, timeout_ch, ());
|
||||
|
|
@ -113,9 +113,9 @@ fn recv_timeout<T: copy send>(iotask: iotask,
|
|||
|left_val| {
|
||||
log(debug, fmt!("recv_time .. left_val %?",
|
||||
left_val));
|
||||
none
|
||||
None
|
||||
}, |right_val| {
|
||||
some(*right_val)
|
||||
Some(*right_val)
|
||||
}, &core::comm::select2(timeout_po, wait_po)
|
||||
)
|
||||
}
|
||||
|
|
@ -249,7 +249,7 @@ mod test {
|
|||
};
|
||||
|
||||
match recv_timeout(hl_loop, 1u, test_po) {
|
||||
none => successes += 1,
|
||||
None => successes += 1,
|
||||
_ => failures += 1
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
* red-black tree or something else.
|
||||
*/
|
||||
|
||||
import core::option::{some, none};
|
||||
import option = core::option;
|
||||
import core::option::{Some, None};
|
||||
import Option = core::Option;
|
||||
|
||||
export treemap;
|
||||
export insert;
|
||||
|
|
@ -16,7 +16,7 @@ export traverse;
|
|||
|
||||
type treemap<K, V> = @mut tree_edge<K, V>;
|
||||
|
||||
type tree_edge<K, V> = option<@tree_node<K, V>>;
|
||||
type tree_edge<K, V> = Option<@tree_node<K, V>>;
|
||||
|
||||
enum tree_node<K, V> = {
|
||||
key: K,
|
||||
|
|
@ -26,19 +26,19 @@ enum tree_node<K, V> = {
|
|||
};
|
||||
|
||||
/// Create a treemap
|
||||
fn treemap<K, V>() -> treemap<K, V> { @mut none }
|
||||
fn treemap<K, V>() -> treemap<K, V> { @mut None }
|
||||
|
||||
/// Insert a value into the map
|
||||
fn insert<K: copy, V: copy>(m: &mut tree_edge<K, V>, k: K, v: V) {
|
||||
match copy *m {
|
||||
none => {
|
||||
*m = some(@tree_node({key: k,
|
||||
None => {
|
||||
*m = Some(@tree_node({key: k,
|
||||
mut value: v,
|
||||
mut left: none,
|
||||
mut right: none}));
|
||||
mut left: None,
|
||||
mut right: None}));
|
||||
return;
|
||||
}
|
||||
some(node) => {
|
||||
Some(node) => {
|
||||
if k == node.key {
|
||||
node.value = v;
|
||||
} else if k < node.key {
|
||||
|
|
@ -51,14 +51,14 @@ fn insert<K: copy, V: copy>(m: &mut tree_edge<K, V>, k: K, v: V) {
|
|||
}
|
||||
|
||||
/// Find a value based on the key
|
||||
fn find<K: copy, V: copy>(m: &const tree_edge<K, V>, k: K) -> option<V> {
|
||||
fn find<K: copy, V: copy>(m: &const tree_edge<K, V>, k: K) -> Option<V> {
|
||||
match copy *m {
|
||||
none => none,
|
||||
None => None,
|
||||
|
||||
// FIXME (#2808): was that an optimization?
|
||||
some(node) => {
|
||||
Some(node) => {
|
||||
if k == node.key {
|
||||
some(node.value)
|
||||
Some(node.value)
|
||||
} else if k < node.key {
|
||||
find(&const node.left, k)
|
||||
} else {
|
||||
|
|
@ -71,8 +71,8 @@ fn find<K: copy, V: copy>(m: &const tree_edge<K, V>, k: K) -> option<V> {
|
|||
/// Visit all pairs in the map in order.
|
||||
fn traverse<K, V: copy>(m: &const tree_edge<K, V>, f: fn(K, V)) {
|
||||
match 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);
|
||||
|
|
@ -97,19 +97,19 @@ mod tests {
|
|||
fn insert_find() {
|
||||
let m = treemap();
|
||||
insert(m, 1, 2);
|
||||
assert (find(m, 1) == some(2));
|
||||
assert (find(m, 1) == Some(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_empty() {
|
||||
let m = treemap::<int, int>(); assert (find(m, 1) == none);
|
||||
let m = treemap::<int, int>(); assert (find(m, 1) == None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_not_found() {
|
||||
let m = treemap();
|
||||
insert(m, 1, 2);
|
||||
assert (find(m, 2) == none);
|
||||
assert (find(m, 2) == None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -138,7 +138,7 @@ mod tests {
|
|||
insert(m, k1, ~"foo");
|
||||
insert(m, k2, ~"bar");
|
||||
|
||||
assert (find(m, k2) == some(~"bar"));
|
||||
assert (find(m, k1) == some(~"foo"));
|
||||
assert (find(m, k2) == Some(~"bar"));
|
||||
assert (find(m, k1) == Some(~"foo"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
import codemap::{span, filename};
|
||||
import std::serialization::{serializer,
|
||||
deserializer,
|
||||
serialize_option,
|
||||
deserialize_option,
|
||||
serialize_Option,
|
||||
deserialize_Option,
|
||||
serialize_uint,
|
||||
deserialize_uint,
|
||||
serialize_int,
|
||||
|
|
@ -40,16 +40,16 @@ macro_rules! interner_key (
|
|||
|
||||
fn serialize_ident<S: serializer>(s: S, i: ident) {
|
||||
let intr = match unsafe{task::local_data_get(interner_key!())}{
|
||||
none => fail ~"serialization: TLS interner not set up",
|
||||
some(intr) => intr
|
||||
None => fail ~"serialization: TLS interner not set up",
|
||||
Some(intr) => intr
|
||||
};
|
||||
|
||||
s.emit_str(*(*intr).get(i));
|
||||
}
|
||||
fn deserialize_ident<D: deserializer>(d: D) -> ident {
|
||||
let intr = match unsafe{task::local_data_get(interner_key!())}{
|
||||
none => fail ~"deserialization: TLS interner not set up",
|
||||
some(intr) => intr
|
||||
None => fail ~"deserialization: TLS interner not set up",
|
||||
Some(intr) => intr
|
||||
};
|
||||
|
||||
(*intr).intern(@d.read_str())
|
||||
|
|
@ -59,13 +59,13 @@ type ident = token::str_num;
|
|||
|
||||
// Functions may or may not have names.
|
||||
#[auto_serialize]
|
||||
type fn_ident = option<ident>;
|
||||
type fn_ident = Option<ident>;
|
||||
|
||||
#[auto_serialize]
|
||||
type path = {span: span,
|
||||
global: bool,
|
||||
idents: ~[ident],
|
||||
rp: option<@region>,
|
||||
rp: Option<@region>,
|
||||
types: ~[@ty]};
|
||||
|
||||
#[auto_serialize]
|
||||
|
|
@ -162,7 +162,7 @@ type blk = spanned<blk_>;
|
|||
#[auto_serialize]
|
||||
type blk_ = {view_items: ~[@view_item],
|
||||
stmts: ~[@stmt],
|
||||
expr: option<@expr>,
|
||||
expr: Option<@expr>,
|
||||
id: node_id,
|
||||
rules: blk_check_mode};
|
||||
|
||||
|
|
@ -185,13 +185,13 @@ enum pat_ {
|
|||
pat_wild,
|
||||
// A pat_ident may either be a new bound variable,
|
||||
// or a nullary enum (in which case the second field
|
||||
// is none).
|
||||
// is None).
|
||||
// In the nullary enum case, the parser can't determine
|
||||
// which it is. The resolver determines this, and
|
||||
// records this pattern's node_id in an auxiliary
|
||||
// set (of "pat_idents that refer to nullary enums")
|
||||
pat_ident(binding_mode, @path, option<@pat>),
|
||||
pat_enum(@path, option<~[@pat]>), // "none" means a * pattern where
|
||||
pat_ident(binding_mode, @path, Option<@pat>),
|
||||
pat_enum(@path, Option<~[@pat]>), // "none" means a * pattern where
|
||||
// we don't bind the fields to names
|
||||
pat_rec(~[field_pat], bool),
|
||||
pat_struct(@path, ~[field_pat], bool),
|
||||
|
|
@ -216,7 +216,7 @@ enum proto {
|
|||
#[auto_serialize]
|
||||
enum vstore {
|
||||
// FIXME (#2112): Change uint to @expr (actually only constant exprs)
|
||||
vstore_fixed(option<uint>), // [1,2,3,4]/_ or 4
|
||||
vstore_fixed(Option<uint>), // [1,2,3,4]/_ or 4
|
||||
vstore_uniq, // ~[1,2,3,4]
|
||||
vstore_box, // @[1,2,3,4]
|
||||
vstore_slice(@region) // &[1,2,3,4](foo)?
|
||||
|
|
@ -297,7 +297,7 @@ type initializer = {op: init_op, expr: @expr};
|
|||
// a refinement on pat.
|
||||
#[auto_serialize]
|
||||
type local_ = {is_mutbl: bool, ty: @ty, pat: @pat,
|
||||
init: option<initializer>, id: node_id};
|
||||
init: Option<initializer>, id: node_id};
|
||||
|
||||
#[auto_serialize]
|
||||
type local = spanned<local_>;
|
||||
|
|
@ -309,7 +309,7 @@ type decl = spanned<decl_>;
|
|||
enum decl_ { decl_local(~[@local]), decl_item(@item), }
|
||||
|
||||
#[auto_serialize]
|
||||
type arm = {pats: ~[@pat], guard: option<@expr>, body: blk};
|
||||
type arm = {pats: ~[@pat], guard: Option<@expr>, body: blk};
|
||||
|
||||
#[auto_serialize]
|
||||
type field_ = {mutbl: mutability, ident: ident, expr: @expr};
|
||||
|
|
@ -335,19 +335,19 @@ enum alt_mode { alt_check, alt_exhaustive, }
|
|||
enum expr_ {
|
||||
expr_vstore(@expr, vstore),
|
||||
expr_vec(~[@expr], mutability),
|
||||
expr_rec(~[field], option<@expr>),
|
||||
expr_rec(~[field], Option<@expr>),
|
||||
expr_call(@expr, ~[@expr], bool), // True iff last argument is a block
|
||||
expr_tup(~[@expr]),
|
||||
expr_binary(binop, @expr, @expr),
|
||||
expr_unary(unop, @expr),
|
||||
expr_lit(@lit),
|
||||
expr_cast(@expr, @ty),
|
||||
expr_if(@expr, blk, option<@expr>),
|
||||
expr_if(@expr, blk, Option<@expr>),
|
||||
expr_while(@expr, blk),
|
||||
/* Conditionless loop (can be exited with break, cont, ret, or fail)
|
||||
Same semantics as while(true) { body }, but typestate knows that the
|
||||
(implicit) condition is always true. */
|
||||
expr_loop(blk, option<ident>),
|
||||
expr_loop(blk, Option<ident>),
|
||||
expr_match(@expr, ~[arm]),
|
||||
expr_fn(proto, fn_decl, blk, capture_clause),
|
||||
expr_fn_block(fn_decl, blk, capture_clause),
|
||||
|
|
@ -369,10 +369,10 @@ enum expr_ {
|
|||
expr_index(@expr, @expr),
|
||||
expr_path(@path),
|
||||
expr_addr_of(mutability, @expr),
|
||||
expr_fail(option<@expr>),
|
||||
expr_break(option<ident>),
|
||||
expr_again(option<ident>),
|
||||
expr_ret(option<@expr>),
|
||||
expr_fail(Option<@expr>),
|
||||
expr_break(Option<ident>),
|
||||
expr_again(Option<ident>),
|
||||
expr_ret(Option<@expr>),
|
||||
expr_log(log_level, @expr, @expr),
|
||||
|
||||
/* just an assert */
|
||||
|
|
@ -381,7 +381,7 @@ enum expr_ {
|
|||
expr_mac(mac),
|
||||
|
||||
// A struct literal expression.
|
||||
expr_struct(@path, ~[field], option<@expr>),
|
||||
expr_struct(@path, ~[field], Option<@expr>),
|
||||
|
||||
// A vector literal constructed from one repeated element.
|
||||
expr_repeat(@expr /* element */, @expr /* count */, mutability)
|
||||
|
|
@ -420,7 +420,7 @@ enum token_tree {
|
|||
tt_tok(span, token::token),
|
||||
tt_delim(~[token_tree]),
|
||||
// These only make sense for right-hand-sides of MBE macros
|
||||
tt_seq(span, ~[token_tree], option<token::token>, bool),
|
||||
tt_seq(span, ~[token_tree], Option<token::token>, bool),
|
||||
tt_nonterminal(span, ident)
|
||||
}
|
||||
|
||||
|
|
@ -485,7 +485,7 @@ enum matcher_ {
|
|||
match_tok(token::token),
|
||||
// match repetitions of a sequence: body, separator, zero ok?,
|
||||
// lo, hi position-in-match-array used:
|
||||
match_seq(~[matcher], option<token::token>, bool, uint, uint),
|
||||
match_seq(~[matcher], Option<token::token>, bool, uint, uint),
|
||||
// parse a Rust NT: name to bind, name of NT, position in match array:
|
||||
match_nonterminal(ident, ident, uint)
|
||||
}
|
||||
|
|
@ -494,13 +494,13 @@ enum matcher_ {
|
|||
type mac = spanned<mac_>;
|
||||
|
||||
#[auto_serialize]
|
||||
type mac_arg = option<@expr>;
|
||||
type mac_arg = Option<@expr>;
|
||||
|
||||
#[auto_serialize]
|
||||
type mac_body_ = {span: span};
|
||||
|
||||
#[auto_serialize]
|
||||
type mac_body = option<mac_body_>;
|
||||
type mac_body = Option<mac_body_>;
|
||||
|
||||
#[auto_serialize]
|
||||
enum mac_ {
|
||||
|
|
@ -593,7 +593,7 @@ enum ty_ {
|
|||
ty_fn(proto, purity, @~[ty_param_bound], fn_decl),
|
||||
ty_tup(~[@ty]),
|
||||
ty_path(@path, node_id),
|
||||
ty_fixed_length(@ty, option<uint>),
|
||||
ty_fixed_length(@ty, Option<uint>),
|
||||
ty_mac(mac),
|
||||
// ty_infer means the type should be inferred instead of it having been
|
||||
// specified. This should only appear at the "top level" of a type and not
|
||||
|
|
@ -672,11 +672,11 @@ enum variant_kind {
|
|||
}
|
||||
|
||||
#[auto_serialize]
|
||||
enum enum_def = { variants: ~[variant], common: option<@struct_def> };
|
||||
enum enum_def = { variants: ~[variant], common: Option<@struct_def> };
|
||||
|
||||
#[auto_serialize]
|
||||
type variant_ = {name: ident, attrs: ~[attribute], kind: variant_kind,
|
||||
id: node_id, disr_expr: option<@expr>, vis: visibility};
|
||||
id: node_id, disr_expr: Option<@expr>, vis: visibility};
|
||||
|
||||
#[auto_serialize]
|
||||
type variant = spanned<variant_>;
|
||||
|
|
@ -770,9 +770,9 @@ type struct_def = {
|
|||
methods: ~[@method], /* methods */
|
||||
/* (not including ctor or dtor) */
|
||||
/* ctor is optional, and will soon go away */
|
||||
ctor: option<class_ctor>,
|
||||
ctor: Option<class_ctor>,
|
||||
/* dtor is optional */
|
||||
dtor: option<class_dtor>
|
||||
dtor: Option<class_dtor>
|
||||
};
|
||||
|
||||
#[auto_serialize]
|
||||
|
|
|
|||
|
|
@ -295,10 +295,10 @@ fn map_stmt(stmt: @stmt, cx: ctx, v: vt) {
|
|||
|
||||
fn node_id_to_str(map: map, id: node_id, itr: ident_interner) -> ~str {
|
||||
match map.find(id) {
|
||||
none => {
|
||||
None => {
|
||||
fmt!("unknown node (id=%d)", id)
|
||||
}
|
||||
some(node_item(item, path)) => {
|
||||
Some(node_item(item, path)) => {
|
||||
let path_str = path_ident_to_str(*path, item.ident, itr);
|
||||
let item_str = match item.node {
|
||||
item_const(*) => ~"const",
|
||||
|
|
@ -314,48 +314,48 @@ fn node_id_to_str(map: map, id: node_id, itr: ident_interner) -> ~str {
|
|||
};
|
||||
fmt!("%s %s (id=%?)", item_str, path_str, 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, itr), abi, id)
|
||||
}
|
||||
some(node_method(m, impl_did, path)) => {
|
||||
Some(node_method(m, impl_did, path)) => {
|
||||
fmt!("method %s in %s (id=%?)",
|
||||
*itr.get(m.ident), path_to_str(*path, itr), 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=%?)",
|
||||
*itr.get(m.ident), path_to_str(*path, itr), id)
|
||||
}
|
||||
some(node_variant(variant, def_id, path)) => {
|
||||
Some(node_variant(variant, def_id, path)) => {
|
||||
fmt!("variant %s in %s (id=%?)",
|
||||
*itr.get(variant.node.name), path_to_str(*path, itr), id)
|
||||
}
|
||||
some(node_expr(expr)) => {
|
||||
Some(node_expr(expr)) => {
|
||||
fmt!("expr %s (id=%?)", pprust::expr_to_str(expr, itr), id)
|
||||
}
|
||||
some(node_stmt(stmt)) => {
|
||||
Some(node_stmt(stmt)) => {
|
||||
fmt!("stmt %s (id=%?)",
|
||||
pprust::stmt_to_str(*stmt, itr), 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, itr), 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")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ pure fn dummy_spanned<T>(+t: T) -> spanned<T> {
|
|||
|
||||
/* assuming that we're not in macro expansion */
|
||||
pure fn mk_sp(lo: uint, hi: uint) -> span {
|
||||
{lo: lo, hi: hi, expn_info: none}
|
||||
{lo: lo, hi: hi, expn_info: None}
|
||||
}
|
||||
|
||||
// make this a const, once the compiler supports it
|
||||
|
|
@ -93,19 +93,19 @@ pure fn binop_to_str(op: binop) -> ~str {
|
|||
}
|
||||
}
|
||||
|
||||
pure fn binop_to_method_name(op: binop) -> option<~str> {
|
||||
pure fn binop_to_method_name(op: binop) -> Option<~str> {
|
||||
match 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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -184,7 +184,7 @@ pure fn float_ty_to_str(t: float_ty) -> ~str {
|
|||
|
||||
fn is_exported(i: ident, m: _mod) -> bool {
|
||||
let mut local = false;
|
||||
let mut parent_enum : option<ident> = none;
|
||||
let mut parent_enum : Option<ident> = None;
|
||||
for m.items.each |it| {
|
||||
if it.ident == i { local = true; }
|
||||
match it.node {
|
||||
|
|
@ -192,7 +192,7 @@ fn is_exported(i: ident, m: _mod) -> bool {
|
|||
for enum_definition.variants.each |v| {
|
||||
if v.node.name == i {
|
||||
local = true;
|
||||
parent_enum = some(/* FIXME (#2543) */ copy it.ident);
|
||||
parent_enum = Some(/* FIXME (#2543) */ copy it.ident);
|
||||
}
|
||||
},
|
||||
_ => ()
|
||||
|
|
@ -209,7 +209,7 @@ fn is_exported(i: ident, m: _mod) -> bool {
|
|||
ast::view_path_simple(id, _, _) => {
|
||||
if id == i { return true; }
|
||||
match parent_enum {
|
||||
some(parent_enum_id) => {
|
||||
Some(parent_enum_id) => {
|
||||
if id == parent_enum_id { return true; }
|
||||
}
|
||||
_ => ()
|
||||
|
|
@ -270,11 +270,11 @@ fn new_def_hash<V: copy>() -> std::map::hashmap<ast::def_id, V> {
|
|||
}
|
||||
|
||||
fn block_from_expr(e: @expr) -> blk {
|
||||
let blk_ = default_block(~[], option::some::<@expr>(e), e.id);
|
||||
let blk_ = default_block(~[], option::Some::<@expr>(e), e.id);
|
||||
return {node: blk_, span: e.span};
|
||||
}
|
||||
|
||||
fn default_block(+stmts1: ~[@stmt], expr1: option<@expr>, id1: node_id) ->
|
||||
fn default_block(+stmts1: ~[@stmt], expr1: Option<@expr>, id1: node_id) ->
|
||||
blk_ {
|
||||
{view_items: ~[], stmts: stmts1,
|
||||
expr: expr1, id: id1, rules: default_blk}
|
||||
|
|
@ -282,18 +282,18 @@ fn default_block(+stmts1: ~[@stmt], expr1: option<@expr>, id1: node_id) ->
|
|||
|
||||
fn ident_to_path(s: span, +i: ident) -> @path {
|
||||
@{span: s, global: false, idents: ~[i],
|
||||
rp: none, types: ~[]}
|
||||
rp: None, types: ~[]}
|
||||
}
|
||||
|
||||
pure fn is_unguarded(&&a: arm) -> bool {
|
||||
match a.guard {
|
||||
none => true,
|
||||
None => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
pure fn unguarded_pat(a: arm) -> option<~[@pat]> {
|
||||
if is_unguarded(a) { some(/* FIXME (#2543) */ copy a.pats) } else { none }
|
||||
pure fn unguarded_pat(a: arm) -> Option<~[@pat]> {
|
||||
if is_unguarded(a) { Some(/* FIXME (#2543) */ copy a.pats) } else { None }
|
||||
}
|
||||
|
||||
fn public_methods(ms: ~[@method]) -> ~[@method] {
|
||||
|
|
@ -583,10 +583,10 @@ pure fn is_item_impl(item: @ast::item) -> bool {
|
|||
fn walk_pat(pat: @pat, it: fn(@pat)) {
|
||||
it(pat);
|
||||
match pat.node {
|
||||
pat_ident(_, _, some(p)) => walk_pat(p, it),
|
||||
pat_ident(_, _, Some(p)) => walk_pat(p, it),
|
||||
pat_rec(fields, _) | pat_struct(_, fields, _) =>
|
||||
for fields.each |f| { walk_pat(f.pat, it) },
|
||||
pat_enum(_, some(s)) | pat_tup(s) => for s.each |p| {
|
||||
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),
|
||||
|
|
|
|||
|
|
@ -124,21 +124,21 @@ fn get_meta_item_name(meta: @ast::meta_item) -> ~str {
|
|||
* Gets the string value if the meta_item is a meta_name_value variant
|
||||
* containing a string, otherwise none
|
||||
*/
|
||||
fn get_meta_item_value_str(meta: @ast::meta_item) -> option<~str> {
|
||||
fn get_meta_item_value_str(meta: @ast::meta_item) -> Option<~str> {
|
||||
match meta.node {
|
||||
ast::meta_name_value(_, v) => match v.node {
|
||||
ast::lit_str(s) => option::some(*s),
|
||||
_ => option::none
|
||||
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]> {
|
||||
fn get_meta_item_list(meta: @ast::meta_item) -> Option<~[@ast::meta_item]> {
|
||||
match 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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -146,13 +146,13 @@ fn get_meta_item_list(meta: @ast::meta_item) -> option<~[@ast::meta_item]> {
|
|||
* If the meta item is a nam-value type with a string value then returns
|
||||
* a tuple containing the name and string value, otherwise `none`
|
||||
*/
|
||||
fn get_name_value_str_pair(item: @ast::meta_item) -> option<(~str, ~str)> {
|
||||
fn get_name_value_str_pair(item: @ast::meta_item) -> Option<(~str, ~str)> {
|
||||
match attr::get_meta_item_value_str(item) {
|
||||
some(value) => {
|
||||
Some(value) => {
|
||||
let name = attr::get_meta_item_name(item);
|
||||
some((name, value))
|
||||
Some((name, value))
|
||||
}
|
||||
none => none
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -163,10 +163,10 @@ fn get_name_value_str_pair(item: @ast::meta_item) -> option<(~str, ~str)> {
|
|||
fn find_attrs_by_name(attrs: ~[ast::attribute], name: ~str) ->
|
||||
~[ast::attribute] {
|
||||
let filter = (
|
||||
fn@(a: ast::attribute) -> option<ast::attribute> {
|
||||
fn@(a: ast::attribute) -> Option<ast::attribute> {
|
||||
if get_attr_name(a) == name {
|
||||
option::some(a)
|
||||
} else { option::none }
|
||||
option::Some(a)
|
||||
} else { option::None }
|
||||
}
|
||||
);
|
||||
return vec::filter_map(attrs, filter);
|
||||
|
|
@ -175,10 +175,10 @@ fn find_attrs_by_name(attrs: ~[ast::attribute], name: ~str) ->
|
|||
/// Searcha list of meta items and return only those with a specific name
|
||||
fn find_meta_items_by_name(metas: ~[@ast::meta_item], name: ~str) ->
|
||||
~[@ast::meta_item] {
|
||||
let filter = fn@(&&m: @ast::meta_item) -> option<@ast::meta_item> {
|
||||
let filter = fn@(&&m: @ast::meta_item) -> Option<@ast::meta_item> {
|
||||
if get_meta_item_name(m) == name {
|
||||
option::some(m)
|
||||
} else { option::none }
|
||||
option::Some(m)
|
||||
} else { option::None }
|
||||
};
|
||||
return vec::filter_map(metas, filter);
|
||||
}
|
||||
|
|
@ -225,40 +225,40 @@ fn attrs_contains_name(attrs: ~[ast::attribute], name: ~str) -> bool {
|
|||
}
|
||||
|
||||
fn first_attr_value_str_by_name(attrs: ~[ast::attribute], name: ~str)
|
||||
-> option<~str> {
|
||||
-> Option<~str> {
|
||||
|
||||
let mattrs = find_attrs_by_name(attrs, name);
|
||||
if vec::len(mattrs) > 0u {
|
||||
return get_meta_item_value_str(attr_meta(mattrs[0]));
|
||||
}
|
||||
return option::none;
|
||||
return option::None;
|
||||
}
|
||||
|
||||
fn last_meta_item_by_name(items: ~[@ast::meta_item], name: ~str)
|
||||
-> option<@ast::meta_item> {
|
||||
-> Option<@ast::meta_item> {
|
||||
|
||||
let items = attr::find_meta_items_by_name(items, name);
|
||||
vec::last_opt(items)
|
||||
}
|
||||
|
||||
fn last_meta_item_value_str_by_name(items: ~[@ast::meta_item], name: ~str)
|
||||
-> option<~str> {
|
||||
-> Option<~str> {
|
||||
|
||||
match last_meta_item_by_name(items, name) {
|
||||
some(item) => match attr::get_meta_item_value_str(item) {
|
||||
some(value) => some(value),
|
||||
none => none
|
||||
Some(item) => match attr::get_meta_item_value_str(item) {
|
||||
Some(value) => Some(value),
|
||||
None => None
|
||||
},
|
||||
none => none
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
fn last_meta_item_list_by_name(items: ~[@ast::meta_item], name: ~str)
|
||||
-> option<~[@ast::meta_item]> {
|
||||
-> Option<~[@ast::meta_item]> {
|
||||
|
||||
match 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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -290,9 +290,9 @@ fn remove_meta_items_by_name(items: ~[@ast::meta_item], name: ~str) ->
|
|||
|
||||
return vec::filter_map(items, |item| {
|
||||
if get_meta_item_name(item) != name {
|
||||
option::some(/* FIXME (#2543) */ copy item)
|
||||
option::Some(/* FIXME (#2543) */ copy item)
|
||||
} else {
|
||||
option::none
|
||||
option::None
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -312,19 +312,19 @@ fn find_linkage_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] {
|
|||
|
||||
fn foreign_abi(attrs: ~[ast::attribute]) -> Either<~str, ast::foreign_abi> {
|
||||
return match 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)
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ fn lookup_byte_pos(map: codemap, pos: uint) -> loc {
|
|||
}
|
||||
|
||||
fn lookup_char_pos_adj(map: codemap, pos: uint)
|
||||
-> {filename: ~str, line: uint, col: uint, file: option<filemap>}
|
||||
-> {filename: ~str, line: uint, col: uint, file: Option<filemap>}
|
||||
{
|
||||
let loc = lookup_char_pos(map, pos);
|
||||
match (loc.file.substr) {
|
||||
|
|
@ -129,7 +129,7 @@ fn lookup_char_pos_adj(map: codemap, pos: uint)
|
|||
{filename: /* FIXME (#2543) */ copy loc.file.name,
|
||||
line: loc.line,
|
||||
col: loc.col,
|
||||
file: some(loc.file)}
|
||||
file: Some(loc.file)}
|
||||
}
|
||||
fss_internal(sp) => {
|
||||
lookup_char_pos_adj(map, sp.lo + (pos - loc.file.start_pos.ch))
|
||||
|
|
@ -138,7 +138,7 @@ fn lookup_char_pos_adj(map: codemap, pos: uint)
|
|||
{filename: /* FIXME (#2543) */ copy eloc.filename,
|
||||
line: eloc.line + loc.line - 1u,
|
||||
col: if loc.line == 1u {eloc.col + loc.col} else {loc.col},
|
||||
file: none}
|
||||
file: None}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -158,9 +158,9 @@ fn adjust_span(map: codemap, sp: span) -> span {
|
|||
|
||||
enum expn_info_ {
|
||||
expanded_from({call_site: span,
|
||||
callie: {name: ~str, span: option<span>}})
|
||||
callie: {name: ~str, span: Option<span>}})
|
||||
}
|
||||
type expn_info = option<@expn_info_>;
|
||||
type expn_info = Option<@expn_info_>;
|
||||
type span = {lo: uint, hi: uint, expn_info: expn_info};
|
||||
|
||||
fn span_to_str_no_adj(sp: span, cm: codemap) -> ~str {
|
||||
|
|
@ -197,8 +197,8 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
|
|||
fn get_line(fm: filemap, line: int) -> ~str unsafe {
|
||||
let begin: uint = fm.lines[line].byte - fm.start_pos.byte;
|
||||
let end = match 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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export codemap_span_handler, codemap_handler;
|
|||
export ice_msg;
|
||||
export expect;
|
||||
|
||||
type emitter = fn@(cmsp: option<(codemap::codemap, span)>,
|
||||
type emitter = fn@(cmsp: Option<(codemap::codemap, span)>,
|
||||
msg: ~str, lvl: level);
|
||||
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ trait handler {
|
|||
fn note(msg: ~str);
|
||||
fn bug(msg: ~str) -> !;
|
||||
fn unimpl(msg: ~str) -> !;
|
||||
fn emit(cmsp: option<(codemap::codemap, span)>, msg: ~str, lvl: level);
|
||||
fn emit(cmsp: Option<(codemap::codemap, span)>, msg: ~str, lvl: level);
|
||||
}
|
||||
|
||||
type handler_t = @{
|
||||
|
|
@ -48,18 +48,18 @@ type codemap_t = @{
|
|||
|
||||
impl codemap_t: span_handler {
|
||||
fn span_fatal(sp: span, msg: ~str) -> ! {
|
||||
self.handler.emit(some((self.cm, sp)), msg, fatal);
|
||||
self.handler.emit(Some((self.cm, sp)), msg, fatal);
|
||||
fail;
|
||||
}
|
||||
fn span_err(sp: span, msg: ~str) {
|
||||
self.handler.emit(some((self.cm, sp)), msg, error);
|
||||
self.handler.emit(Some((self.cm, sp)), msg, error);
|
||||
self.handler.bump_err_count();
|
||||
}
|
||||
fn span_warn(sp: span, msg: ~str) {
|
||||
self.handler.emit(some((self.cm, sp)), msg, warning);
|
||||
self.handler.emit(Some((self.cm, sp)), msg, warning);
|
||||
}
|
||||
fn span_note(sp: span, msg: ~str) {
|
||||
self.handler.emit(some((self.cm, sp)), msg, note);
|
||||
self.handler.emit(Some((self.cm, sp)), msg, note);
|
||||
}
|
||||
fn span_bug(sp: span, msg: ~str) -> ! {
|
||||
self.span_fatal(sp, ice_msg(msg));
|
||||
|
|
@ -74,11 +74,11 @@ impl codemap_t: span_handler {
|
|||
|
||||
impl handler_t: handler {
|
||||
fn fatal(msg: ~str) -> ! {
|
||||
self.emit(none, msg, fatal);
|
||||
self.emit(None, msg, fatal);
|
||||
fail;
|
||||
}
|
||||
fn err(msg: ~str) {
|
||||
self.emit(none, msg, error);
|
||||
self.emit(None, msg, error);
|
||||
self.bump_err_count();
|
||||
}
|
||||
fn bump_err_count() {
|
||||
|
|
@ -98,16 +98,16 @@ impl handler_t: handler {
|
|||
self.fatal(s);
|
||||
}
|
||||
fn warn(msg: ~str) {
|
||||
self.emit(none, msg, warning);
|
||||
self.emit(None, msg, warning);
|
||||
}
|
||||
fn note(msg: ~str) {
|
||||
self.emit(none, msg, note);
|
||||
self.emit(None, msg, note);
|
||||
}
|
||||
fn bug(msg: ~str) -> ! {
|
||||
self.fatal(ice_msg(msg));
|
||||
}
|
||||
fn unimpl(msg: ~str) -> ! { self.bug(~"unimplemented " + msg); }
|
||||
fn emit(cmsp: option<(codemap::codemap, span)>, msg: ~str, lvl: level) {
|
||||
fn emit(cmsp: Option<(codemap::codemap, span)>, msg: ~str, lvl: level) {
|
||||
self.emit(cmsp, msg, lvl);
|
||||
}
|
||||
}
|
||||
|
|
@ -120,12 +120,12 @@ fn mk_span_handler(handler: handler, cm: codemap::codemap) -> span_handler {
|
|||
@{ handler: handler, cm: cm } as span_handler
|
||||
}
|
||||
|
||||
fn mk_handler(emitter: option<emitter>) -> handler {
|
||||
fn mk_handler(emitter: Option<emitter>) -> handler {
|
||||
|
||||
let emit = match emitter {
|
||||
some(e) => e,
|
||||
none => {
|
||||
let f = fn@(cmsp: option<(codemap::codemap, span)>,
|
||||
Some(e) => e,
|
||||
None => {
|
||||
let f = fn@(cmsp: Option<(codemap::codemap, span)>,
|
||||
msg: ~str, t: level) {
|
||||
emit(cmsp, msg, t);
|
||||
};
|
||||
|
|
@ -180,10 +180,10 @@ fn print_diagnostic(topic: ~str, lvl: level, msg: ~str) {
|
|||
io::stderr().write_str(fmt!(" %s\n", msg));
|
||||
}
|
||||
|
||||
fn emit(cmsp: option<(codemap::codemap, span)>,
|
||||
fn emit(cmsp: Option<(codemap::codemap, span)>,
|
||||
msg: ~str, lvl: level) {
|
||||
match 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);
|
||||
|
|
@ -191,7 +191,7 @@ fn emit(cmsp: option<(codemap::codemap, span)>,
|
|||
highlight_lines(cm, sp, lines);
|
||||
print_macro_backtrace(cm, sp);
|
||||
}
|
||||
none => {
|
||||
None => {
|
||||
print_diagnostic(~"", lvl, msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -265,9 +265,9 @@ fn print_macro_backtrace(cm: codemap::codemap, sp: span) {
|
|||
}
|
||||
|
||||
fn expect<T: copy>(diag: span_handler,
|
||||
opt: option<T>, msg: fn() -> ~str) -> T {
|
||||
opt: Option<T>, msg: fn() -> ~str) -> T {
|
||||
match opt {
|
||||
some(t) => t,
|
||||
none => diag.handler().bug(msg())
|
||||
Some(t) => t,
|
||||
None => diag.handler().bug(msg())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -164,12 +164,12 @@ impl ext_ctxt: ext_ctxt_helpers {
|
|||
}
|
||||
|
||||
fn path(span: span, strs: ~[ast::ident]) -> @ast::path {
|
||||
@{span: span, global: false, idents: strs, rp: none, types: ~[]}
|
||||
@{span: span, global: false, idents: strs, rp: None, types: ~[]}
|
||||
}
|
||||
|
||||
fn path_tps(span: span, strs: ~[ast::ident],
|
||||
tps: ~[@ast::ty]) -> @ast::path {
|
||||
@{span: span, global: false, idents: strs, rp: none, types: tps}
|
||||
@{span: span, global: false, idents: strs, rp: None, types: tps}
|
||||
}
|
||||
|
||||
fn ty_path(span: span, strs: ~[ast::ident],
|
||||
|
|
@ -215,7 +215,7 @@ impl ext_ctxt: ext_ctxt_helpers {
|
|||
fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk {
|
||||
{node: {view_items: ~[],
|
||||
stmts: stmts,
|
||||
expr: none,
|
||||
expr: None,
|
||||
id: self.next_id(),
|
||||
rules: ast::default_blk},
|
||||
span: span}
|
||||
|
|
@ -224,7 +224,7 @@ impl ext_ctxt: ext_ctxt_helpers {
|
|||
fn expr_blk(expr: @ast::expr) -> ast::blk {
|
||||
{node: {view_items: ~[],
|
||||
stmts: ~[],
|
||||
expr: some(expr),
|
||||
expr: Some(expr),
|
||||
id: self.next_id(),
|
||||
rules: ast::default_blk},
|
||||
span: expr.span}
|
||||
|
|
@ -232,11 +232,11 @@ impl ext_ctxt: ext_ctxt_helpers {
|
|||
|
||||
fn binder_pat(span: span, nm: ast::ident) -> @ast::pat {
|
||||
let path = @{span: span, global: false, idents: ~[nm],
|
||||
rp: none, types: ~[]};
|
||||
rp: None, types: ~[]};
|
||||
@{id: self.next_id(),
|
||||
node: ast::pat_ident(ast::bind_by_implicit_ref,
|
||||
path,
|
||||
none),
|
||||
None),
|
||||
span: span}
|
||||
}
|
||||
|
||||
|
|
@ -374,7 +374,7 @@ fn ser_variant(cx: ext_ctxt,
|
|||
let body_blk = cx.blk(span, stmts);
|
||||
let body = cx.blk(span, ~[cx.stmt(bodyfn(s, body_blk))]);
|
||||
|
||||
{pats: ~[pat], guard: none, body: body}
|
||||
{pats: ~[pat], guard: None, body: body}
|
||||
}
|
||||
|
||||
fn ser_lambda(cx: ext_ctxt, tps: ser_tps_map, ty: @ast::ty,
|
||||
|
|
@ -387,7 +387,7 @@ fn is_vec_or_str(ty: @ast::ty) -> bool {
|
|||
ast::ty_vec(_) => true,
|
||||
// This may be wrong if the user has shadowed (!) str
|
||||
ast::ty_path(@{span: _, global: _, idents: ids,
|
||||
rp: none, types: _}, _)
|
||||
rp: None, types: _}, _)
|
||||
if ids == ~[parse::token::special_idents::str] => true,
|
||||
_ => false
|
||||
}
|
||||
|
|
@ -493,8 +493,8 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
|
|||
let ident = path.idents[0];
|
||||
|
||||
match 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)
|
||||
|
|
@ -684,7 +684,7 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map,
|
|||
expr: #ast{ $(d).read_rec_field($(f), $(i), $(l))} },
|
||||
span: fld.span}
|
||||
};
|
||||
let fld_expr = cx.expr(ty.span, ast::expr_rec(fields, none));
|
||||
let fld_expr = cx.expr(ty.span, ast::expr_rec(fields, None));
|
||||
let fld_lambda = cx.lambda(cx.expr_blk(fld_expr));
|
||||
#ast{ $(d).read_rec($(fld_lambda)) }
|
||||
}
|
||||
|
|
@ -720,8 +720,8 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map,
|
|||
let ident = path.idents[0];
|
||||
|
||||
match 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)
|
||||
|
|
@ -850,10 +850,10 @@ fn ser_enum(cx: ext_ctxt, tps: ser_tps_map, e_name: ast::ident,
|
|||
if vec::is_empty(pats) {
|
||||
ast::pat_ident(ast::bind_by_implicit_ref,
|
||||
cx.path(v_span, ~[v_name]),
|
||||
none)
|
||||
None)
|
||||
} else {
|
||||
ast::pat_enum(cx.path(v_span, ~[v_name]),
|
||||
some(pats))
|
||||
Some(pats))
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -928,17 +928,17 @@ fn deser_enum(cx: ext_ctxt, tps: deser_tps_map, e_name: ast::ident,
|
|||
{pats: ~[@{id: cx.next_id(),
|
||||
node: ast::pat_lit(cx.lit_uint(v_span, vidx)),
|
||||
span: v_span}],
|
||||
guard: none,
|
||||
guard: None,
|
||||
body: cx.expr_blk(body)}
|
||||
};
|
||||
|
||||
let impossible_case = {pats: ~[@{id: cx.next_id(),
|
||||
node: ast::pat_wild,
|
||||
span: e_span}],
|
||||
guard: none,
|
||||
guard: None,
|
||||
// FIXME #3198: proper error message
|
||||
body: cx.expr_blk(cx.expr(e_span,
|
||||
ast::expr_fail(none)))};
|
||||
ast::expr_fail(None)))};
|
||||
arms += ~[impossible_case];
|
||||
|
||||
// Generate code like:
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import std::map::str_hash;
|
|||
type syntax_expander_ =
|
||||
fn@(ext_ctxt, span, ast::mac_arg, ast::mac_body) -> @ast::expr;
|
||||
// second argument is the origin of the macro, if user-defined
|
||||
type syntax_expander = {expander: syntax_expander_, span: option<span>};
|
||||
type syntax_expander = {expander: syntax_expander_, span: Option<span>};
|
||||
|
||||
type macro_def = {name: ~str, ext: syntax_extension};
|
||||
|
||||
|
|
@ -32,12 +32,12 @@ type macro_definer =
|
|||
type item_decorator =
|
||||
fn@(ext_ctxt, span, ast::meta_item, ~[@ast::item]) -> ~[@ast::item];
|
||||
|
||||
type syntax_expander_tt = {expander: syntax_expander_tt_, span: option<span>};
|
||||
type syntax_expander_tt = {expander: syntax_expander_tt_, span: Option<span>};
|
||||
type syntax_expander_tt_ = fn@(ext_ctxt, span, ~[ast::token_tree])
|
||||
-> mac_result;
|
||||
|
||||
type syntax_expander_tt_item
|
||||
= {expander: syntax_expander_tt_item_, span: option<span>};
|
||||
= {expander: syntax_expander_tt_item_, span: Option<span>};
|
||||
type syntax_expander_tt_item_
|
||||
= fn@(ext_ctxt, span, ast::ident, ~[ast::token_tree]) -> mac_result;
|
||||
|
||||
|
|
@ -67,12 +67,12 @@ enum syntax_extension {
|
|||
// AST nodes into full ASTs
|
||||
fn syntax_expander_table() -> hashmap<~str, syntax_extension> {
|
||||
fn builtin(f: syntax_expander_) -> syntax_extension
|
||||
{normal({expander: f, span: none})}
|
||||
{normal({expander: f, span: None})}
|
||||
fn builtin_expr_tt(f: syntax_expander_tt_) -> syntax_extension {
|
||||
expr_tt({expander: f, span: none})
|
||||
expr_tt({expander: f, span: None})
|
||||
}
|
||||
fn builtin_item_tt(f: syntax_expander_tt_item_) -> syntax_extension {
|
||||
item_tt({expander: f, span: none})
|
||||
item_tt({expander: f, span: None})
|
||||
}
|
||||
let syntax_expanders = str_hash::<syntax_extension>();
|
||||
syntax_expanders.insert(~"macro",
|
||||
|
|
@ -166,7 +166,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
|
|||
match ei {
|
||||
expanded_from({call_site: cs, callie: callie}) => {
|
||||
self.backtrace =
|
||||
some(@expanded_from({
|
||||
Some(@expanded_from({
|
||||
call_site: {lo: cs.lo, hi: cs.hi,
|
||||
expn_info: self.backtrace},
|
||||
callie: callie}));
|
||||
|
|
@ -175,7 +175,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
|
|||
}
|
||||
fn bt_pop() {
|
||||
match 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")
|
||||
|
|
@ -225,7 +225,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
|
|||
let imp : ctxt_repr = {
|
||||
parse_sess: parse_sess,
|
||||
cfg: cfg,
|
||||
mut backtrace: none,
|
||||
mut backtrace: None,
|
||||
mut mod_path: ~[],
|
||||
mut trace_mac: false
|
||||
};
|
||||
|
|
@ -255,22 +255,22 @@ fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ast::ident {
|
|||
|
||||
fn get_mac_args_no_max(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
min: uint, name: ~str) -> ~[@ast::expr] {
|
||||
return get_mac_args(cx, sp, arg, min, none, name);
|
||||
return get_mac_args(cx, sp, arg, min, None, name);
|
||||
}
|
||||
|
||||
fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
min: uint, max: option<uint>, name: ~str) -> ~[@ast::expr] {
|
||||
min: uint, max: Option<uint>, name: ~str) -> ~[@ast::expr] {
|
||||
match arg {
|
||||
some(expr) => match expr.node {
|
||||
Some(expr) => match expr.node {
|
||||
ast::expr_vec(elts, _) => {
|
||||
let elts_len = vec::len(elts);
|
||||
match max {
|
||||
some(max) if ! (min <= elts_len && elts_len <= 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) => {
|
||||
None if ! (min <= elts_len) => {
|
||||
cx.span_fatal(sp, fmt!("#%s needs at least %u arguments.",
|
||||
name, min));
|
||||
}
|
||||
|
|
@ -281,7 +281,7 @@ fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
|||
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -289,8 +289,8 @@ fn get_mac_body(cx: ext_ctxt, sp: span, args: ast::mac_body)
|
|||
-> ast::mac_body_
|
||||
{
|
||||
match (args) {
|
||||
some(body) => body,
|
||||
none => cx.span_fatal(sp, ~"missing macro body")
|
||||
Some(body) => body,
|
||||
None => cx.span_fatal(sp, ~"missing macro body")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -306,16 +306,16 @@ fn tt_args_to_original_flavor(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree])
|
|||
|
||||
// these spans won't matter, anyways
|
||||
fn ms(m: matcher_) -> matcher {
|
||||
{node: m, span: {lo: 0u, hi: 0u, expn_info: none}}
|
||||
{node: m, span: {lo: 0u, hi: 0u, expn_info: None}}
|
||||
}
|
||||
let arg_nm = cx.parse_sess().interner.gensym(@~"arg");
|
||||
|
||||
let argument_gram = ~[ms(match_seq(~[
|
||||
ms(match_nonterminal(arg_nm, parse::token::special_idents::expr, 0u))
|
||||
], some(parse::token::COMMA), true, 0u, 1u))];
|
||||
], Some(parse::token::COMMA), true, 0u, 1u))];
|
||||
|
||||
let arg_reader = new_tt_reader(cx.parse_sess().span_diagnostic,
|
||||
cx.parse_sess().interner, none, arg);
|
||||
cx.parse_sess().interner, None, arg);
|
||||
let args =
|
||||
match parse_or_else(cx.parse_sess(), cx.cfg(), arg_reader as reader,
|
||||
argument_gram).get(arg_nm) {
|
||||
|
|
@ -331,7 +331,7 @@ fn tt_args_to_original_flavor(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree])
|
|||
_ => fail ~"badly-structured parse result"
|
||||
};
|
||||
|
||||
return some(@{id: parse::next_node_id(cx.parse_sess()),
|
||||
return Some(@{id: parse::next_node_id(cx.parse_sess()),
|
||||
callee_id: parse::next_node_id(cx.parse_sess()),
|
||||
node: ast::expr_vec(args, ast::m_imm), span: sp});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ fn mk_unary(cx: ext_ctxt, sp: span, op: ast::unop, e: @ast::expr)
|
|||
fn mk_path(cx: ext_ctxt, sp: span, idents: ~[ast::ident]) ->
|
||||
@ast::expr {
|
||||
let path = @{span: sp, global: false, idents: idents,
|
||||
rp: none, types: ~[]};
|
||||
rp: None, types: ~[]};
|
||||
let pathexpr = ast::expr_path(path);
|
||||
mk_expr(cx, sp, pathexpr)
|
||||
}
|
||||
|
|
@ -75,7 +75,7 @@ fn mk_uniq_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) ->
|
|||
}
|
||||
fn mk_fixed_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) ->
|
||||
@ast::expr {
|
||||
mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::vstore_fixed(none))
|
||||
mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::vstore_fixed(None))
|
||||
}
|
||||
fn mk_base_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr {
|
||||
let lit = ast::lit_str(@s);
|
||||
|
|
@ -96,7 +96,7 @@ fn mk_rec_e(cx: ext_ctxt, sp: span,
|
|||
{node: {mutbl: ast::m_imm, ident: ident, expr: val}, span: sp};
|
||||
vec::push(astfields, astfield);
|
||||
}
|
||||
let recexpr = ast::expr_rec(astfields, option::none::<@ast::expr>);
|
||||
let recexpr = ast::expr_rec(astfields, option::None::<@ast::expr>);
|
||||
mk_expr(cx, sp, recexpr)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,6 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
|||
return @{id: cx.next_id(),
|
||||
callee_id: cx.next_id(),
|
||||
node: ast::expr_path(@{span: sp, global: false, idents: ~[res],
|
||||
rp: none, types: ~[]}),
|
||||
rp: None, types: ~[]}),
|
||||
span: sp};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,15 +10,15 @@ export expand_syntax_ext;
|
|||
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args(cx, sp, arg, 1u, option::some(1u), ~"env");
|
||||
let args = get_mac_args(cx, sp, arg, 1u, option::Some(1u), ~"env");
|
||||
|
||||
// FIXME (#2248): if this was more thorough it would manufacture an
|
||||
// option<str> rather than just an maybe-empty string.
|
||||
// Option<str> rather than just an maybe-empty string.
|
||||
|
||||
let var = expr_to_str(cx, args[0], ~"#env requires a string");
|
||||
match 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,16 +29,16 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
|
|||
the macro names be hygienic */
|
||||
let extname = cx.parse_sess().interner.get(pth.idents[0]);
|
||||
match 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,
|
||||
|
|
@ -49,17 +49,17 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
|
|||
|
||||
(fully_expanded, s)
|
||||
}
|
||||
some(macro_defining(ext)) => {
|
||||
Some(macro_defining(ext)) => {
|
||||
let named_extension = ext(cx, mac.span, args, body);
|
||||
exts.insert(named_extension.name, named_extension.ext);
|
||||
(ast::expr_rec(~[], none), s)
|
||||
(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");
|
||||
}
|
||||
|
|
@ -74,11 +74,11 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
|
|||
the macro names be hygienic */
|
||||
let extname = cx.parse_sess().interner.get(pth.idents[0]);
|
||||
match 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 = match exp(cx, mac.span, tts) {
|
||||
mr_expr(e) => e,
|
||||
_ => cx.span_fatal(
|
||||
|
|
@ -94,11 +94,11 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
|
|||
|
||||
(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);
|
||||
let expanded = exp(cx, mac.span, arg, none);
|
||||
let expanded = exp(cx, mac.span, arg, None);
|
||||
|
||||
cx.bt_push(expanded_from({call_site: s,
|
||||
callie: {name: *extname, span: exp_sp}}));
|
||||
|
|
@ -151,9 +151,9 @@ fn expand_mod_items(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
|
|||
ast::meta_list(n, _) => n
|
||||
};
|
||||
match exts.find(mname) {
|
||||
none | some(normal(_)) | some(macro_defining(_))
|
||||
| some(expr_tt(_)) | some(item_tt(*)) => items,
|
||||
some(item_decorator(dec_fn)) => {
|
||||
None | Some(normal(_)) | Some(macro_defining(_))
|
||||
| Some(expr_tt(_)) | Some(item_tt(*)) => items,
|
||||
Some(item_decorator(dec_fn)) => {
|
||||
dec_fn(cx, attr.span, attr.node.value, items)
|
||||
}
|
||||
}
|
||||
|
|
@ -167,8 +167,8 @@ fn expand_mod_items(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
|
|||
// When we enter a module, record it, for the sake of `module!`
|
||||
fn expand_item(exts: hashmap<~str, syntax_extension>,
|
||||
cx: ext_ctxt, &&it: @ast::item, fld: ast_fold,
|
||||
orig: fn@(&&@ast::item, ast_fold) -> option<@ast::item>)
|
||||
-> option<@ast::item>
|
||||
orig: fn@(&&@ast::item, ast_fold) -> Option<@ast::item>)
|
||||
-> Option<@ast::item>
|
||||
{
|
||||
let is_mod = match it.node {
|
||||
ast::item_mod(_) | ast::item_foreign_mod(_) => true,
|
||||
|
|
@ -176,17 +176,17 @@ fn expand_item(exts: hashmap<~str, syntax_extension>,
|
|||
};
|
||||
let maybe_it = match it.node {
|
||||
ast::item_mac(*) => expand_item_mac(exts, cx, it, fld),
|
||||
_ => some(it)
|
||||
_ => Some(it)
|
||||
};
|
||||
|
||||
match 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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -195,16 +195,16 @@ fn expand_item(exts: hashmap<~str, syntax_extension>,
|
|||
// logic as for expression-position macro invocations.
|
||||
fn expand_item_mac(exts: hashmap<~str, syntax_extension>,
|
||||
cx: ext_ctxt, &&it: @ast::item,
|
||||
fld: ast_fold) -> option<@ast::item> {
|
||||
fld: ast_fold) -> Option<@ast::item> {
|
||||
match it.node {
|
||||
item_mac({node: mac_invoc_tt(pth, tts), span}) => {
|
||||
let extname = cx.parse_sess().interner.get(pth.idents[0]);
|
||||
match 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,
|
||||
|
|
@ -216,7 +216,7 @@ fn expand_item_mac(exts: hashmap<~str, syntax_extension>,
|
|||
*extname),
|
||||
mr_def(mdef) => {
|
||||
exts.insert(mdef.name, mdef.ext);
|
||||
none
|
||||
None
|
||||
}
|
||||
};
|
||||
cx.bt_pop();
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
|||
}
|
||||
let unsupported = ~"conversion not supported in #fmt string";
|
||||
match cnv.param {
|
||||
option::none => (),
|
||||
option::None => (),
|
||||
_ => cx.span_unimpl(sp, unsupported)
|
||||
}
|
||||
for cnv.flags.each |f| {
|
||||
|
|
@ -192,7 +192,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
|||
}
|
||||
fn log_conv(c: conv) {
|
||||
match c.param {
|
||||
some(p) => { log(debug, ~"param: " + int::to_str(p, 10u)); }
|
||||
Some(p) => { log(debug, ~"param: " + int::to_str(p, 10u)); }
|
||||
_ => debug!("param: none")
|
||||
}
|
||||
for c.flags.each |f| {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import option;
|
|||
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args(cx,sp,arg,1u,option::some(1u),~"ident_to_str");
|
||||
let args = get_mac_args(cx,sp,arg,1u,option::Some(1u),~"ident_to_str");
|
||||
|
||||
return mk_uniq_str(cx, sp, *cx.parse_sess().interner.get(
|
||||
expr_to_ident(cx, args[0u], ~"expected an ident")));
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, tt: ~[ast::token_tree])
|
|||
|
||||
//trivial expression
|
||||
return mr_expr(@{id: cx.next_id(), callee_id: cx.next_id(),
|
||||
node: ast::expr_rec(~[], option::none), span: sp});
|
||||
node: ast::expr_rec(~[], option::None), span: sp});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident,
|
|||
let sess = cx.parse_sess();
|
||||
let cfg = cx.cfg();
|
||||
let tt_rdr = new_tt_reader(cx.parse_sess().span_diagnostic,
|
||||
cx.parse_sess().interner, none, tt);
|
||||
cx.parse_sess().interner, None, tt);
|
||||
let rdr = tt_rdr as reader;
|
||||
let rust_parser = parser(sess, cfg, rdr.dup(), SOURCE_FILE);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ fn path(ids: ~[ident], span: span) -> @ast::path {
|
|||
@{span: span,
|
||||
global: false,
|
||||
idents: ids,
|
||||
rp: none,
|
||||
rp: None,
|
||||
types: ~[]}
|
||||
}
|
||||
|
||||
fn empty_span() -> span {
|
||||
{lo: 0, hi: 0, expn_info: none}
|
||||
{lo: 0, hi: 0, expn_info: None}
|
||||
}
|
||||
|
||||
trait append_types {
|
||||
|
|
@ -90,7 +90,7 @@ trait ext_ctxt_ast_builder {
|
|||
|
||||
impl ext_ctxt: ext_ctxt_ast_builder {
|
||||
fn ty_option(ty: @ast::ty) -> @ast::ty {
|
||||
self.ty_path_ast_builder(path(~[self.ident_of(~"option")],
|
||||
self.ty_path_ast_builder(path(~[self.ident_of(~"Option")],
|
||||
self.empty_span())
|
||||
.add_ty(ty))
|
||||
}
|
||||
|
|
@ -125,9 +125,9 @@ impl ext_ctxt: ext_ctxt_ast_builder {
|
|||
node: ast::pat_ident(ast::bind_by_implicit_ref,
|
||||
path(~[ident],
|
||||
self.empty_span()),
|
||||
none),
|
||||
None),
|
||||
span: self.empty_span()},
|
||||
init: some({op: ast::init_move,
|
||||
init: Some({op: ast::init_move,
|
||||
expr: e}),
|
||||
id: self.next_id()},
|
||||
span: self.empty_span()}]),
|
||||
|
|
@ -143,7 +143,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
|
|||
fn rec(+fields: ~[ast::field]) -> @ast::expr {
|
||||
@{id: self.next_id(),
|
||||
callee_id: self.next_id(),
|
||||
node: ast::expr_rec(fields, none),
|
||||
node: ast::expr_rec(fields, None),
|
||||
span: self.empty_span()}
|
||||
}
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
|
|||
fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk {
|
||||
let blk = {view_items: ~[],
|
||||
stmts: stmts,
|
||||
expr: some(e),
|
||||
expr: Some(e),
|
||||
id: self.next_id(),
|
||||
rules: ast::default_blk};
|
||||
|
||||
|
|
@ -258,7 +258,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
|
|||
attrs: ~[],
|
||||
kind: ast::tuple_variant_kind(args),
|
||||
id: self.next_id(),
|
||||
disr_expr: none,
|
||||
disr_expr: None,
|
||||
vis: ast::public},
|
||||
span: span}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ impl ext_ctxt: proto::visitor<(), (), ()> {
|
|||
fn visit_message(name: ~str, _span: span, _tys: &[@ast::ty],
|
||||
this: state, next: next_state) {
|
||||
match 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
|
||||
|
|
@ -65,7 +65,7 @@ impl ext_ctxt: proto::visitor<(), (), ()> {
|
|||
}
|
||||
}
|
||||
}
|
||||
none => ()
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -82,10 +82,10 @@ fn analyze(proto: protocol, _cx: ext_ctxt) {
|
|||
// *proto.name,
|
||||
// states));
|
||||
|
||||
proto.bounded = some(false);
|
||||
proto.bounded = Some(false);
|
||||
}
|
||||
else {
|
||||
debug!("protocol %s is bounded. yay!", proto.name);
|
||||
proto.bounded = some(true);
|
||||
proto.bounded = Some(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ impl parser: proto_parser {
|
|||
let proto = protocol(id, self.span);
|
||||
|
||||
self.parse_seq_to_before_end(token::EOF,
|
||||
{sep: none, trailing_sep_allowed: false},
|
||||
{sep: None, trailing_sep_allowed: false},
|
||||
|self| self.parse_state(proto));
|
||||
|
||||
return proto;
|
||||
|
|
@ -47,7 +47,7 @@ impl parser: proto_parser {
|
|||
// parse the messages
|
||||
self.parse_unspanned_seq(
|
||||
token::LBRACE, token::RBRACE,
|
||||
{sep: some(token::COMMA), trailing_sep_allowed: true},
|
||||
{sep: Some(token::COMMA), trailing_sep_allowed: true},
|
||||
|self| self.parse_message(state));
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ impl parser: proto_parser {
|
|||
let args = if self.token == token::LPAREN {
|
||||
self.parse_unspanned_seq(token::LPAREN,
|
||||
token::RPAREN,
|
||||
{sep: some(token::COMMA),
|
||||
{sep: Some(token::COMMA),
|
||||
trailing_sep_allowed: true},
|
||||
|p| p.parse_ty(false))
|
||||
}
|
||||
|
|
@ -71,17 +71,17 @@ impl parser: proto_parser {
|
|||
let ntys = if self.token == token::LT {
|
||||
self.parse_unspanned_seq(token::LT,
|
||||
token::GT,
|
||||
{sep: some(token::COMMA),
|
||||
{sep: Some(token::COMMA),
|
||||
trailing_sep_allowed: true},
|
||||
|p| p.parse_ty(false))
|
||||
}
|
||||
else { ~[] };
|
||||
some({state: name, tys: ntys})
|
||||
Some({state: name, tys: ntys})
|
||||
}
|
||||
token::NOT => {
|
||||
// -> !
|
||||
self.bump();
|
||||
none
|
||||
None
|
||||
}
|
||||
_ => self.fatal(~"invalid next state")
|
||||
};
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ impl message: gen_send {
|
|||
debug!("pipec: gen_send");
|
||||
match self {
|
||||
message(_id, span, tys, this,
|
||||
some({state: next, tys: next_tys})) => {
|
||||
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();
|
||||
|
|
@ -126,7 +126,7 @@ impl message: gen_send {
|
|||
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()));
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ impl state: to_type_decls {
|
|||
let message(name, span, tys, this, next) = m;
|
||||
|
||||
let tys = match next {
|
||||
some({state: next, tys: next_tys}) => {
|
||||
Some({state: next, tys: next_tys}) => {
|
||||
let next = this.proto.get_state(next);
|
||||
let next_name = cx.str_of(next.data_name());
|
||||
|
||||
|
|
@ -222,7 +222,7 @@ impl state: to_type_decls {
|
|||
cx.ident_of(next_name)], span)
|
||||
.add_tys(next_tys)))
|
||||
}
|
||||
none => tys
|
||||
None => tys
|
||||
};
|
||||
|
||||
let v = cx.variant(cx.ident_of(name), span, tys);
|
||||
|
|
@ -233,7 +233,7 @@ impl state: to_type_decls {
|
|||
~[cx.item_enum_poly(name,
|
||||
self.span,
|
||||
ast::enum_def({ variants: items_msg,
|
||||
common: none }),
|
||||
common: None }),
|
||||
self.ty_params)]
|
||||
}
|
||||
|
||||
|
|
@ -368,7 +368,7 @@ impl protocol: gen_init {
|
|||
for (copy self.states).each |s| {
|
||||
for s.ty_params.each |tp| {
|
||||
match params.find(|tpp| tp.ident == tpp.ident) {
|
||||
none => vec::push(params, tp),
|
||||
None => vec::push(params, tp),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
|
@ -384,7 +384,7 @@ impl protocol: gen_init {
|
|||
let fields = do (copy self.states).map_to_vec |s| {
|
||||
for s.ty_params.each |tp| {
|
||||
match params.find(|tpp| tp.ident == tpp.ident) {
|
||||
none => vec::push(params, tp),
|
||||
None => vec::push(params, tp),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
|
@ -488,8 +488,8 @@ impl ext_ctxt: ext_ctxt_parse_utils {
|
|||
~[],
|
||||
self.parse_sess());
|
||||
match res {
|
||||
some(ast) => ast,
|
||||
none => {
|
||||
Some(ast) => ast,
|
||||
None => {
|
||||
error!("Parse error with ```\n%s\n```", s);
|
||||
fail
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ impl direction {
|
|||
}
|
||||
}
|
||||
|
||||
type next_state = option<{state: ~str, tys: ~[@ast::ty]}>;
|
||||
type next_state = Option<{state: ~str, tys: ~[@ast::ty]}>;
|
||||
|
||||
enum message {
|
||||
// name, span, data, current state, next state
|
||||
|
|
@ -93,7 +93,7 @@ impl state {
|
|||
fn reachable(f: fn(state) -> bool) {
|
||||
for self.messages.each |m| {
|
||||
match m {
|
||||
message(_, _, _, _, some({state: id, _})) => {
|
||||
message(_, _, _, _, Some({state: id, _})) => {
|
||||
let state = self.proto.get_state(id);
|
||||
if !f(state) { break }
|
||||
}
|
||||
|
|
@ -114,13 +114,13 @@ struct protocol_ {
|
|||
let span: span;
|
||||
let states: DVec<state>;
|
||||
|
||||
let mut bounded: option<bool>;
|
||||
let mut bounded: Option<bool>;
|
||||
|
||||
new(name: ~str, span: span) {
|
||||
self.name = name;
|
||||
self.span = span;
|
||||
self.states = dvec();
|
||||
self.bounded = none;
|
||||
self.bounded = None;
|
||||
}
|
||||
|
||||
/// Get a state.
|
||||
|
|
@ -131,7 +131,7 @@ struct protocol_ {
|
|||
fn get_state_by_id(id: uint) -> state { self.states[id] }
|
||||
|
||||
fn has_state(name: ~str) -> bool {
|
||||
self.states.find(|i| i.name == name) != none
|
||||
self.states.find(|i| i.name == name) != None
|
||||
}
|
||||
|
||||
fn filename() -> ~str {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ fn id_ext(cx: ext_ctxt, str: ~str) -> ast::ident {
|
|||
trait qq_helper {
|
||||
fn span() -> span;
|
||||
fn visit(aq_ctxt, vt<aq_ctxt>);
|
||||
fn extract_mac() -> option<ast::mac_>;
|
||||
fn extract_mac() -> Option<ast::mac_>;
|
||||
fn mk_parse_fn(ext_ctxt,span) -> @ast::expr;
|
||||
fn get_fold_fn() -> ~str;
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ trait qq_helper {
|
|||
impl @ast::crate: qq_helper {
|
||||
fn span() -> span {self.span}
|
||||
fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_crate(*self, cx, v);}
|
||||
fn extract_mac() -> option<ast::mac_> {fail}
|
||||
fn extract_mac() -> Option<ast::mac_> {fail}
|
||||
fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr {
|
||||
mk_path(cx, sp,
|
||||
ids_ext(cx, ~[~"syntax", ~"ext", ~"qquote", ~"parse_crate"]))
|
||||
|
|
@ -56,10 +56,10 @@ impl @ast::crate: qq_helper {
|
|||
impl @ast::expr: qq_helper {
|
||||
fn span() -> span {self.span}
|
||||
fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_expr(self, cx, v);}
|
||||
fn extract_mac() -> option<ast::mac_> {
|
||||
fn extract_mac() -> Option<ast::mac_> {
|
||||
match (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 {
|
||||
|
|
@ -71,10 +71,10 @@ impl @ast::expr: qq_helper {
|
|||
impl @ast::ty: qq_helper {
|
||||
fn span() -> span {self.span}
|
||||
fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_ty(self, cx, v);}
|
||||
fn extract_mac() -> option<ast::mac_> {
|
||||
fn extract_mac() -> Option<ast::mac_> {
|
||||
match (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 {
|
||||
|
|
@ -86,7 +86,7 @@ impl @ast::ty: qq_helper {
|
|||
impl @ast::item: qq_helper {
|
||||
fn span() -> span {self.span}
|
||||
fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_item(self, cx, v);}
|
||||
fn extract_mac() -> option<ast::mac_> {fail}
|
||||
fn extract_mac() -> Option<ast::mac_> {fail}
|
||||
fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr {
|
||||
mk_path(cx, sp,
|
||||
ids_ext(cx, ~[~"syntax", ~"ext", ~"qquote", ~"parse_item"]))
|
||||
|
|
@ -96,7 +96,7 @@ impl @ast::item: qq_helper {
|
|||
impl @ast::stmt: qq_helper {
|
||||
fn span() -> span {self.span}
|
||||
fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_stmt(self, cx, v);}
|
||||
fn extract_mac() -> option<ast::mac_> {fail}
|
||||
fn extract_mac() -> Option<ast::mac_> {fail}
|
||||
fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr {
|
||||
mk_path(cx, sp,
|
||||
ids_ext(cx, ~[~"syntax", ~"ext", ~"qquote", ~"parse_stmt"]))
|
||||
|
|
@ -106,7 +106,7 @@ impl @ast::stmt: qq_helper {
|
|||
impl @ast::pat: qq_helper {
|
||||
fn span() -> span {self.span}
|
||||
fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_pat(self, cx, v);}
|
||||
fn extract_mac() -> option<ast::mac_> {fail}
|
||||
fn extract_mac() -> Option<ast::mac_> {fail}
|
||||
fn mk_parse_fn(cx: ext_ctxt, sp: span) -> @ast::expr {
|
||||
mk_path(cx, sp, ids_ext(cx, ~[~"syntax", ~"ext", ~"qquote",
|
||||
~"parse_pat"]))
|
||||
|
|
@ -135,7 +135,7 @@ fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt
|
|||
fn visit_aq<T:qq_helper>(node: T, constr: ~str, &&cx: aq_ctxt, v: vt<aq_ctxt>)
|
||||
{
|
||||
match (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,
|
||||
|
|
@ -194,8 +194,8 @@ fn parse_pat(p: parser) -> @ast::pat { p.parse_pat(true) }
|
|||
|
||||
fn parse_item(p: parser) -> @ast::item {
|
||||
match 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"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@ import ast::{ident, path, ty, blk_, expr, expr_path,
|
|||
|
||||
export add_new_extension;
|
||||
|
||||
fn path_to_ident(pth: @path) -> option<ident> {
|
||||
fn path_to_ident(pth: @path) -> Option<ident> {
|
||||
if vec::len(pth.idents) == 1u && vec::len(pth.types) == 0u {
|
||||
return some(pth.idents[0u]);
|
||||
return Some(pth.idents[0u]);
|
||||
}
|
||||
return none;
|
||||
return None;
|
||||
}
|
||||
|
||||
//a vec of binders might be a little big.
|
||||
|
|
@ -57,23 +57,23 @@ fn match_error(cx: ext_ctxt, m: matchable, expected: ~str) -> ! {
|
|||
// If we want better match failure error messages (like in Fortifying Syntax),
|
||||
// we'll want to return something indicating amount of progress and location
|
||||
// of failure instead of `none`.
|
||||
type match_result = option<arb_depth<matchable>>;
|
||||
type match_result = Option<arb_depth<matchable>>;
|
||||
type selector = fn@(matchable) -> match_result;
|
||||
|
||||
fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) ->
|
||||
{pre: ~[@expr], rep: option<@expr>, post: ~[@expr]} {
|
||||
{pre: ~[@expr], rep: Option<@expr>, post: ~[@expr]} {
|
||||
let mut idx: uint = 0u;
|
||||
let mut res = none;
|
||||
let mut res = None;
|
||||
for elts.each |elt| {
|
||||
match elt.node {
|
||||
expr_mac(m) => match m.node {
|
||||
ast::mac_ellipsis => {
|
||||
if res != none {
|
||||
if res != None {
|
||||
cx.span_fatal(m.span, ~"only one ellipsis allowed");
|
||||
}
|
||||
res =
|
||||
some({pre: vec::slice(elts, 0u, idx - 1u),
|
||||
rep: some(elts[idx - 1u]),
|
||||
Some({pre: vec::slice(elts, 0u, idx - 1u),
|
||||
rep: Some(elts[idx - 1u]),
|
||||
post: vec::slice(elts, idx + 1u, vec::len(elts))});
|
||||
}
|
||||
_ => ()
|
||||
|
|
@ -83,29 +83,29 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) ->
|
|||
idx += 1u;
|
||||
}
|
||||
return match 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]> {
|
||||
fn option_flatten_map<T: copy, U: copy>(f: fn@(T) -> Option<U>, v: ~[T]) ->
|
||||
Option<~[U]> {
|
||||
let mut res = ~[];
|
||||
for v.each |elem| {
|
||||
match f(elem) {
|
||||
none => return none,
|
||||
some(fv) => vec::push(res, fv)
|
||||
None => return None,
|
||||
Some(fv) => vec::push(res, fv)
|
||||
}
|
||||
}
|
||||
return some(res);
|
||||
return Some(res);
|
||||
}
|
||||
|
||||
fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result {
|
||||
match ad {
|
||||
leaf(x) => return f(x),
|
||||
seq(ads, span) => match option_flatten_map(|x| a_d_map(x, f), *ads) {
|
||||
none => return none,
|
||||
some(ts) => return some(seq(@ts, span))
|
||||
None => return None,
|
||||
Some(ts) => return Some(seq(@ts, span))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -113,8 +113,8 @@ fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result {
|
|||
fn compose_sels(s1: selector, s2: selector) -> selector {
|
||||
fn scomp(s1: selector, s2: selector, m: matchable) -> match_result {
|
||||
return match 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) };
|
||||
|
|
@ -140,7 +140,7 @@ fn pattern_to_selectors(cx: ext_ctxt, e: @expr) -> binders {
|
|||
//this oughta return binders instead, but macro args are a sequence of
|
||||
//expressions, rather than a single expression
|
||||
fn trivial_selector(m: matchable) -> match_result {
|
||||
return some(leaf(m));
|
||||
return Some(leaf(m));
|
||||
}
|
||||
p_t_s_rec(cx, match_expr(e), trivial_selector, res);
|
||||
return res;
|
||||
|
|
@ -152,22 +152,22 @@ fn pattern_to_selectors(cx: ext_ctxt, e: @expr) -> binders {
|
|||
bindings. Most of the work is done in p_t_s, which generates the
|
||||
selectors. */
|
||||
|
||||
fn use_selectors_to_bind(b: binders, e: @expr) -> option<bindings> {
|
||||
fn use_selectors_to_bind(b: binders, e: @expr) -> Option<bindings> {
|
||||
let res = uint_hash::<arb_depth<matchable>>();
|
||||
//need to do this first, to check vec lengths.
|
||||
for b.literal_ast_matchers.each |sel| {
|
||||
match sel(match_expr(e)) { none => return none, _ => () }
|
||||
match sel(match_expr(e)) { None => return None, _ => () }
|
||||
}
|
||||
let mut never_mind: bool = false;
|
||||
for b.real_binders.each |key, val| {
|
||||
match 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`
|
||||
if never_mind { return none; }
|
||||
return some(res);
|
||||
if never_mind { return None; }
|
||||
return Some(res);
|
||||
}
|
||||
|
||||
/* use the bindings on the body to generate the expanded code */
|
||||
|
|
@ -217,18 +217,18 @@ pure fn follow(m: arb_depth<matchable>, idx_path: &[uint]) ->
|
|||
return res;
|
||||
}
|
||||
|
||||
fn follow_for_trans(cx: ext_ctxt, mmaybe: option<arb_depth<matchable>>,
|
||||
idx_path: @mut ~[uint]) -> option<matchable> {
|
||||
fn follow_for_trans(cx: ext_ctxt, mmaybe: Option<arb_depth<matchable>>,
|
||||
idx_path: @mut ~[uint]) -> Option<matchable> {
|
||||
match mmaybe {
|
||||
none => return none,
|
||||
some(m) => {
|
||||
None => return None,
|
||||
Some(m) => {
|
||||
return match follow(m, *idx_path) {
|
||||
seq(_, sp) => {
|
||||
cx.span_fatal(sp,
|
||||
~"syntax matched under ... but not " +
|
||||
~"used that way.")
|
||||
}
|
||||
leaf(m) => return some(m)
|
||||
leaf(m) => return Some(m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -268,9 +268,9 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
|||
{pre: pre, rep: repeat_me_maybe, post: post} => {
|
||||
let mut res = vec::map(pre, recur);
|
||||
match repeat_me_maybe {
|
||||
none => (),
|
||||
some(repeat_me) => {
|
||||
let mut repeat: option<{rep_count: uint, name: ident}> = none;
|
||||
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| {
|
||||
|
|
@ -280,10 +280,10 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
|||
leaf(_) => (),
|
||||
seq(ms, _) => {
|
||||
match repeat {
|
||||
none => {
|
||||
repeat = some({rep_count: vec::len(*ms), name: fv});
|
||||
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 = wrong_occurs(cx, fv, len,
|
||||
|
|
@ -296,12 +296,12 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
|||
}
|
||||
};
|
||||
match 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 {
|
||||
|
|
@ -326,9 +326,9 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
|||
fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
||||
&&i: ident, _fld: ast_fold) -> ident {
|
||||
return match 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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -338,13 +338,13 @@ fn transcribe_path(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
|||
// Don't substitute into qualified names.
|
||||
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { return p; }
|
||||
match 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: ~[]}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -361,17 +361,17 @@ fn transcribe_expr(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
|||
(e, s);
|
||||
}
|
||||
match 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,
|
||||
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)
|
||||
|
|
@ -386,14 +386,14 @@ fn transcribe_type(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
|||
return match t {
|
||||
ast::ty_path(pth, _) => {
|
||||
match path_to_ident(pth) {
|
||||
some(id) => {
|
||||
Some(id) => {
|
||||
match 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)
|
||||
|
|
@ -410,16 +410,16 @@ fn transcribe_block(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
|
|||
-> (blk_, span)
|
||||
{
|
||||
return match block_to_ident(blk) {
|
||||
some(id) => {
|
||||
Some(id) => {
|
||||
match 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -435,7 +435,7 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
|
|||
expr_path(p_pth) => p_t_s_r_path(cx, p_pth, s, b),
|
||||
expr_vec(p_elts, _) => {
|
||||
match 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 {
|
||||
|
|
@ -448,7 +448,7 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
|
|||
~"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");
|
||||
}
|
||||
|
|
@ -466,7 +466,7 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
|
|||
match_result {
|
||||
return match m {
|
||||
match_expr(e) => {
|
||||
if e == pat { some(leaf(match_exact)) } else { none }
|
||||
if e == pat { Some(leaf(match_exact)) } else { None }
|
||||
}
|
||||
_ => cx.bug(~"broken traversal in p_t_s_r")
|
||||
}
|
||||
|
|
@ -487,8 +487,8 @@ fn specialize_match(m: matchable) -> matchable {
|
|||
match e.node {
|
||||
expr_path(pth) => {
|
||||
match 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
|
||||
|
|
@ -501,10 +501,10 @@ fn specialize_match(m: matchable) -> matchable {
|
|||
/* pattern_to_selectors helper functions */
|
||||
fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) {
|
||||
match path_to_ident(p) {
|
||||
some(p_id) => {
|
||||
Some(p_id) => {
|
||||
fn select(cx: ext_ctxt, m: matchable) -> match_result {
|
||||
return match m {
|
||||
match_expr(e) => some(leaf(specialize_match(m))),
|
||||
match_expr(e) => Some(leaf(specialize_match(m))),
|
||||
_ => cx.bug(~"broken traversal in p_t_s_r")
|
||||
}
|
||||
}
|
||||
|
|
@ -513,18 +513,18 @@ fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) {
|
|||
}
|
||||
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; }
|
||||
fn block_to_ident(blk: blk_) -> Option<ident> {
|
||||
if vec::len(blk.stmts) != 0u { return None; }
|
||||
return match blk.expr {
|
||||
some(expr) => match expr.node {
|
||||
Some(expr) => match expr.node {
|
||||
expr_path(pth) => path_to_ident(pth),
|
||||
_ => none
|
||||
_ => None
|
||||
},
|
||||
none => none
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -534,7 +534,7 @@ fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, _s: selector, _b: binders) {
|
|||
return match m {
|
||||
match_expr(e) => match e.node {
|
||||
expr_mac(mac) => fn_m(mac),
|
||||
_ => none
|
||||
_ => None
|
||||
},
|
||||
_ => cx.bug(~"broken traversal in p_t_s_r")
|
||||
}
|
||||
|
|
@ -568,9 +568,9 @@ fn p_t_s_r_ellipses(cx: ext_ctxt, repeat_me: @expr, offset: uint, s: selector,
|
|||
|
||||
// using repeat_me.span is a little wacky, but the
|
||||
// error we want to report is one in the macro def
|
||||
some(seq(@elts, repeat_me.span))
|
||||
Some(seq(@elts, repeat_me.span))
|
||||
}
|
||||
_ => none
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
_ => cx.bug(~"broken traversal in p_t_s_r")
|
||||
|
|
@ -591,13 +591,13 @@ fn p_t_s_r_length(cx: ext_ctxt, len: uint, at_least: bool, s: selector,
|
|||
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 }
|
||||
Some(leaf(match_exact))
|
||||
} else { None }
|
||||
}
|
||||
_ => none
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
_ => none
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
b.literal_ast_matchers.push(
|
||||
|
|
@ -613,9 +613,9 @@ fn p_t_s_r_actual_vector(cx: ext_ctxt, elts: ~[@expr], _repeat_after: bool,
|
|||
match_expr(e) => {
|
||||
match e.node {
|
||||
expr_vec(arg_elts, _) => {
|
||||
some(leaf(match_expr(arg_elts[idx])))
|
||||
Some(leaf(match_expr(arg_elts[idx])))
|
||||
}
|
||||
_ => none
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
_ => cx.bug(~"broken traversal in p_t_s_r")
|
||||
|
|
@ -631,7 +631,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
|||
_body: ast::mac_body) -> base::macro_def {
|
||||
let args = get_mac_args_no_max(cx, sp, arg, 0u, ~"macro");
|
||||
|
||||
let mut macro_name: option<~str> = none;
|
||||
let mut macro_name: Option<~str> = None;
|
||||
let mut clauses: ~[@clause] = ~[];
|
||||
for args.each |arg| {
|
||||
match arg.node {
|
||||
|
|
@ -648,23 +648,23 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
|||
match mac.node {
|
||||
mac_invoc(pth, invoc_arg, body) => {
|
||||
match path_to_ident(pth) {
|
||||
some(id) => {
|
||||
Some(id) => {
|
||||
let id_str = cx.str_of(id);
|
||||
match macro_name {
|
||||
none => macro_name = some(id_str),
|
||||
some(other_id) => if id_str != other_id {
|
||||
None => macro_name = Some(id_str),
|
||||
Some(other_id) => if id_str != other_id {
|
||||
cx.span_fatal(pth.span,
|
||||
~"macro name must be " +
|
||||
~"consistent");
|
||||
}
|
||||
}
|
||||
},
|
||||
none => cx.span_fatal(pth.span,
|
||||
None => cx.span_fatal(pth.span,
|
||||
~"macro name must not be a path")
|
||||
}
|
||||
let arg = match invoc_arg {
|
||||
some(arg) => arg,
|
||||
none => cx.span_fatal(mac.span,
|
||||
Some(arg) => arg,
|
||||
None => cx.span_fatal(mac.span,
|
||||
~"macro must have arguments")
|
||||
};
|
||||
vec::push(clauses,
|
||||
|
|
@ -698,23 +698,23 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
|||
|
||||
return {name:
|
||||
match macro_name {
|
||||
some(id) => id,
|
||||
none => cx.span_fatal(sp, ~"macro definition must have " +
|
||||
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)})};
|
||||
ext: normal({expander: ext, span: Some(option::get(arg).span)})};
|
||||
|
||||
fn generic_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body,
|
||||
clauses: ~[@clause]) -> @expr {
|
||||
let arg = match 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| {
|
||||
match 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");
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ export expand_include_bin;
|
|||
/* line!(): expands to the current line number */
|
||||
fn expand_line(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), ~"line");
|
||||
get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"line");
|
||||
let loc = codemap::lookup_char_pos(cx.codemap(), sp.lo);
|
||||
return mk_uint(cx, sp, loc.line);
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ fn expand_line(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
|||
/* col!(): expands to the current column number */
|
||||
fn expand_col(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), ~"col");
|
||||
get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"col");
|
||||
let loc = codemap::lookup_char_pos(cx.codemap(), sp.lo);
|
||||
return mk_uint(cx, sp, loc.col);
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ fn expand_col(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
|||
* out if we wanted. */
|
||||
fn expand_file(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), ~"file");
|
||||
get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"file");
|
||||
let { file: @{ name: filename, _ }, _ } =
|
||||
codemap::lookup_char_pos(cx.codemap(), sp.lo);
|
||||
return mk_uniq_str(cx, sp, filename);
|
||||
|
|
@ -42,21 +42,21 @@ fn expand_file(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
|||
|
||||
fn expand_stringify(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args(cx, sp, arg, 1u, option::some(1u), ~"stringify");
|
||||
let args = get_mac_args(cx, sp, arg, 1u, option::Some(1u), ~"stringify");
|
||||
let s = pprust::expr_to_str(args[0], cx.parse_sess().interner);
|
||||
return mk_uniq_str(cx, sp, s);
|
||||
}
|
||||
|
||||
fn expand_mod(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body)
|
||||
-> @ast::expr {
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), ~"file");
|
||||
get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"file");
|
||||
return mk_uniq_str(cx, sp,
|
||||
str::connect(cx.mod_path().map(|x| cx.str_of(x)), ~"::"));
|
||||
}
|
||||
|
||||
fn expand_include(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args(cx, sp, arg, 1u, option::some(1u), ~"include");
|
||||
let args = get_mac_args(cx, sp, arg, 1u, option::Some(1u), ~"include");
|
||||
let file = expr_to_str(cx, args[0], ~"#include_str requires a string");
|
||||
let p = parse::new_parser_from_file(cx.parse_sess(), cx.cfg(),
|
||||
&res_rel_file(cx, sp, &Path(file)),
|
||||
|
|
@ -66,7 +66,7 @@ fn expand_include(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
|||
|
||||
fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args(cx,sp,arg,1u,option::some(1u),~"include_str");
|
||||
let args = get_mac_args(cx,sp,arg,1u,option::Some(1u),~"include_str");
|
||||
|
||||
let file = expr_to_str(cx, args[0], ~"#include_str requires a string");
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
|||
|
||||
fn expand_include_bin(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args(cx,sp,arg,1u,option::some(1u),~"include_bin");
|
||||
let args = get_mac_args(cx,sp,arg,1u,option::Some(1u),~"include_bin");
|
||||
|
||||
let file = expr_to_str(cx, args[0], ~"#include_bin requires a string");
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ fn expand_trace_macros(cx: ext_ctxt, sp: span,
|
|||
let sess = cx.parse_sess();
|
||||
let cfg = cx.cfg();
|
||||
let tt_rdr = new_tt_reader(cx.parse_sess().span_diagnostic,
|
||||
cx.parse_sess().interner, none, tt);
|
||||
cx.parse_sess().interner, None, tt);
|
||||
let rdr = tt_rdr as reader;
|
||||
let rust_parser = parser(sess, cfg, rdr.dup(), SOURCE_FILE);
|
||||
|
||||
|
|
|
|||
|
|
@ -85,19 +85,19 @@ eof: [a $( a )* a b ·]
|
|||
nonempty body. */
|
||||
|
||||
enum matcher_pos_up { /* to break a circularity */
|
||||
matcher_pos_up(option<matcher_pos>)
|
||||
matcher_pos_up(Option<matcher_pos>)
|
||||
}
|
||||
|
||||
fn is_some(&&mpu: matcher_pos_up) -> bool {
|
||||
match mpu {
|
||||
matcher_pos_up(none) => false,
|
||||
matcher_pos_up(None) => false,
|
||||
_ => true
|
||||
}
|
||||
}
|
||||
|
||||
type matcher_pos = ~{
|
||||
elts: ~[ast::matcher], // maybe should be /&? Need to understand regions.
|
||||
sep: option<token>,
|
||||
sep: Option<token>,
|
||||
mut idx: uint,
|
||||
mut up: matcher_pos_up, // mutable for swapping only
|
||||
matches: ~[DVec<@named_match>],
|
||||
|
|
@ -107,7 +107,7 @@ type matcher_pos = ~{
|
|||
|
||||
fn copy_up(&& mpu: matcher_pos_up) -> matcher_pos {
|
||||
match mpu {
|
||||
matcher_pos_up(some(mp)) => copy mp,
|
||||
matcher_pos_up(Some(mp)) => copy mp,
|
||||
_ => fail
|
||||
}
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ fn count_names(ms: &[matcher]) -> uint {
|
|||
}
|
||||
|
||||
#[allow(non_implicitly_copyable_typarams)]
|
||||
fn initial_matcher_pos(ms: ~[matcher], sep: option<token>, lo: uint)
|
||||
fn initial_matcher_pos(ms: ~[matcher], sep: Option<token>, lo: uint)
|
||||
-> matcher_pos {
|
||||
let mut match_idx_hi = 0u;
|
||||
for ms.each() |elt| {
|
||||
|
|
@ -136,7 +136,7 @@ fn initial_matcher_pos(ms: ~[matcher], sep: option<token>, lo: uint)
|
|||
}
|
||||
}
|
||||
}
|
||||
~{elts: ms, sep: sep, mut idx: 0u, mut up: matcher_pos_up(none),
|
||||
~{elts: ms, sep: sep, mut idx: 0u, mut up: matcher_pos_up(None),
|
||||
matches: copy vec::from_fn(count_names(ms), |_i| dvec::dvec()),
|
||||
match_lo: 0u, match_hi: match_idx_hi, sp_lo: lo}
|
||||
}
|
||||
|
|
@ -208,7 +208,7 @@ fn parse_or_else(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader,
|
|||
fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
|
||||
-> parse_result {
|
||||
let mut cur_eis = ~[];
|
||||
vec::push(cur_eis, initial_matcher_pos(ms, none, rdr.peek().sp.lo));
|
||||
vec::push(cur_eis, initial_matcher_pos(ms, None, rdr.peek().sp.lo));
|
||||
|
||||
loop {
|
||||
let mut bb_eis = ~[]; // black-box parsed by parser.rs
|
||||
|
|
@ -263,7 +263,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
|
|||
|
||||
// the *_t vars are workarounds for the lack of unary move
|
||||
match 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;
|
||||
|
|
@ -300,7 +300,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
|
|||
let ei_t <- ei;
|
||||
vec::push(cur_eis, ~{
|
||||
elts: matchers, sep: sep, mut idx: 0u,
|
||||
mut up: matcher_pos_up(some(ei_t)),
|
||||
mut up: matcher_pos_up(Some(ei_t)),
|
||||
matches: matches,
|
||||
match_lo: match_idx_lo, match_hi: match_idx_hi,
|
||||
sp_lo: sp.lo
|
||||
|
|
@ -381,8 +381,8 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
|
|||
fn parse_nt(p: parser, name: ~str) -> nonterminal {
|
||||
match name {
|
||||
~"item" => match p.parse_item(~[]) {
|
||||
some(i) => token::nt_item(i),
|
||||
none => p.fatal(~"expected an item keyword")
|
||||
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(~[])),
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
|||
arg: ~[ast::token_tree]) -> base::mac_result {
|
||||
// these spans won't matter, anyways
|
||||
fn ms(m: matcher_) -> matcher {
|
||||
{node: m, span: {lo: 0u, hi: 0u, expn_info: none}}
|
||||
{node: m, span: {lo: 0u, hi: 0u, expn_info: None}}
|
||||
}
|
||||
|
||||
let lhs_nm = cx.parse_sess().interner.gensym(@~"lhs");
|
||||
|
|
@ -28,15 +28,15 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
|||
ms(match_nonterminal(lhs_nm, special_idents::matchers, 0u)),
|
||||
ms(match_tok(FAT_ARROW)),
|
||||
ms(match_nonterminal(rhs_nm, special_idents::tt, 1u)),
|
||||
], some(SEMI), false, 0u, 2u)),
|
||||
], Some(SEMI), false, 0u, 2u)),
|
||||
//to phase into semicolon-termination instead of
|
||||
//semicolon-separation
|
||||
ms(match_seq(~[ms(match_tok(SEMI))], none, true, 2u, 2u))];
|
||||
ms(match_seq(~[ms(match_tok(SEMI))], None, true, 2u, 2u))];
|
||||
|
||||
|
||||
// Parse the macro_rules! invocation (`none` is for no interpolations):
|
||||
let arg_reader = new_tt_reader(cx.parse_sess().span_diagnostic,
|
||||
cx.parse_sess().interner, none, arg);
|
||||
cx.parse_sess().interner, None, arg);
|
||||
let argument_map = parse_or_else(cx.parse_sess(), cx.cfg(),
|
||||
arg_reader as reader, argument_gram);
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
|||
}
|
||||
|
||||
// Which arm's failure should we report? (the one furthest along)
|
||||
let mut best_fail_spot = {lo: 0u, hi: 0u, expn_info: none};
|
||||
let mut best_fail_spot = {lo: 0u, hi: 0u, expn_info: None};
|
||||
let mut best_fail_msg = ~"internal error: ran no matchers";
|
||||
|
||||
let s_d = cx.parse_sess().span_diagnostic;
|
||||
|
|
@ -75,7 +75,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
|||
match lhs {
|
||||
@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;
|
||||
let arg_rdr = new_tt_reader(s_d, itr, None, arg) as reader;
|
||||
match parse(cx.parse_sess(), cx.cfg(), arg_rdr, mtcs) {
|
||||
success(named_matches) => {
|
||||
let rhs = match rhses[i] {
|
||||
|
|
@ -84,7 +84,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
|||
_ => 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),
|
||||
let trncbr = new_tt_reader(s_d, itr, Some(named_matches),
|
||||
~[rhs]);
|
||||
let p = parser(cx.parse_sess(), cx.cfg(),
|
||||
trncbr as reader, SOURCE_FILE);
|
||||
|
|
@ -109,6 +109,6 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
|
|||
|
||||
return mr_def({
|
||||
name: *cx.parse_sess().interner.get(name),
|
||||
ext: expr_tt({expander: exp, span: some(sp)})
|
||||
ext: expr_tt({expander: exp, span: Some(sp)})
|
||||
});
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ import std::map::{hashmap, box_str_hash};
|
|||
export tt_reader, new_tt_reader, dup_tt_reader, tt_next_token;
|
||||
|
||||
enum tt_frame_up { /* to break a circularity */
|
||||
tt_frame_up(option<tt_frame>)
|
||||
tt_frame_up(Option<tt_frame>)
|
||||
}
|
||||
|
||||
/* FIXME #2811: figure out how to have a uniquely linked stack, and change to
|
||||
|
|
@ -19,7 +19,7 @@ type tt_frame = @{
|
|||
readme: ~[ast::token_tree],
|
||||
mut idx: uint,
|
||||
dotdotdoted: bool,
|
||||
sep: option<token>,
|
||||
sep: Option<token>,
|
||||
up: tt_frame_up,
|
||||
};
|
||||
|
||||
|
|
@ -40,15 +40,15 @@ type tt_reader = @{
|
|||
* `src` contains no `tt_seq`s and `tt_nonterminal`s, `interp` can (and
|
||||
* should) be none. */
|
||||
fn new_tt_reader(sp_diag: span_handler, itr: ident_interner,
|
||||
interp: option<std::map::hashmap<ident,@named_match>>,
|
||||
interp: Option<std::map::hashmap<ident,@named_match>>,
|
||||
src: ~[ast::token_tree])
|
||||
-> tt_reader {
|
||||
let r = @{sp_diag: sp_diag, interner: itr,
|
||||
mut cur: @{readme: src, mut idx: 0u, dotdotdoted: false,
|
||||
sep: none, up: tt_frame_up(option::none)},
|
||||
sep: None, up: tt_frame_up(option::None)},
|
||||
interpolations: match interp { /* just a convienience */
|
||||
none => std::map::uint_hash::<@named_match>(),
|
||||
some(x) => x
|
||||
None => std::map::uint_hash::<@named_match>(),
|
||||
Some(x) => x
|
||||
},
|
||||
mut repeat_idx: ~[mut], mut repeat_len: ~[],
|
||||
/* dummy values, never read: */
|
||||
|
|
@ -62,8 +62,8 @@ fn new_tt_reader(sp_diag: span_handler, itr: ident_interner,
|
|||
pure fn dup_tt_frame(&&f: tt_frame) -> tt_frame {
|
||||
@{readme: f.readme, mut idx: f.idx, dotdotdoted: f.dotdotdoted,
|
||||
sep: f.sep, up: match f.up {
|
||||
tt_frame_up(some(up_frame)) => {
|
||||
tt_frame_up(some(dup_tt_frame(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)
|
||||
}
|
||||
|
|
@ -141,11 +141,11 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
|
|||
|| r.repeat_idx.last() == r.repeat_len.last() - 1 {
|
||||
|
||||
match 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);
|
||||
}
|
||||
|
|
@ -159,11 +159,11 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
|
|||
r.cur.idx = 0u;
|
||||
r.repeat_idx[r.repeat_idx.len() - 1u] += 1u;
|
||||
match r.cur.sep {
|
||||
some(tk) => {
|
||||
Some(tk) => {
|
||||
r.cur_tok = tk; /* repeat same span, I guess */
|
||||
return ret_val;
|
||||
}
|
||||
none => ()
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -172,7 +172,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
|
|||
match r.cur.readme[r.cur.idx] {
|
||||
tt_delim(tts) => {
|
||||
r.cur = @{readme: tts, mut idx: 0u, dotdotdoted: false,
|
||||
sep: none, up: tt_frame_up(option::some(r.cur)) };
|
||||
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) => {
|
||||
|
|
@ -207,7 +207,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
|
|||
vec::push(r.repeat_len, len);
|
||||
vec::push(r.repeat_idx, 0u);
|
||||
r.cur = @{readme: tts, mut idx: 0u, dotdotdoted: true,
|
||||
sep: sep, up: tt_frame_up(option::some(r.cur))};
|
||||
sep: sep, up: tt_frame_up(option::Some(r.cur))};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ trait ast_fold {
|
|||
fn fold_crate_directive(&&@crate_directive) -> @crate_directive;
|
||||
fn fold_view_item(&&@view_item) -> @view_item;
|
||||
fn fold_foreign_item(&&@foreign_item) -> @foreign_item;
|
||||
fn fold_item(&&@item) -> option<@item>;
|
||||
fn fold_item(&&@item) -> Option<@item>;
|
||||
fn fold_struct_field(&&@struct_field) -> @struct_field;
|
||||
fn fold_item_underscore(item_) -> item_;
|
||||
fn fold_method(&&@method) -> @method;
|
||||
|
|
@ -54,7 +54,7 @@ type ast_fold_precursor = @{
|
|||
ast_fold) -> (crate_directive_, span),
|
||||
fold_view_item: fn@(view_item_, ast_fold) -> view_item_,
|
||||
fold_foreign_item: fn@(&&@foreign_item, ast_fold) -> @foreign_item,
|
||||
fold_item: fn@(&&@item, ast_fold) -> option<@item>,
|
||||
fold_item: fn@(&&@item, ast_fold) -> Option<@item>,
|
||||
fold_struct_field: fn@(&&@struct_field, ast_fold) -> @struct_field,
|
||||
fold_item_underscore: fn@(item_, ast_fold) -> item_,
|
||||
fold_method: fn@(&&@method, ast_fold) -> @method,
|
||||
|
|
@ -204,10 +204,10 @@ fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold)
|
|||
span: fld.new_span(ni.span)};
|
||||
}
|
||||
|
||||
fn noop_fold_item(&&i: @item, fld: ast_fold) -> option<@item> {
|
||||
fn noop_fold_item(&&i: @item, fld: ast_fold) -> Option<@item> {
|
||||
let fold_attribute = |x| fold_attribute_(x, fld);
|
||||
|
||||
return some(@{ident: fld.fold_ident(i.ident),
|
||||
return Some(@{ident: fld.fold_ident(i.ident),
|
||||
attrs: vec::map(i.attrs, fold_attribute),
|
||||
id: fld.new_id(i.id),
|
||||
node: fld.fold_item_underscore(i.node),
|
||||
|
|
@ -270,11 +270,11 @@ fn fold_struct_def(struct_def: @ast::struct_def, fld: ast_fold)
|
|||
-> @ast::struct_def {
|
||||
let resulting_optional_constructor;
|
||||
match struct_def.ctor {
|
||||
none => {
|
||||
resulting_optional_constructor = none;
|
||||
None => {
|
||||
resulting_optional_constructor = None;
|
||||
}
|
||||
some(constructor) => {
|
||||
resulting_optional_constructor = some({
|
||||
Some(constructor) => {
|
||||
resulting_optional_constructor = Some({
|
||||
node: {
|
||||
body: fld.fold_block(constructor.node.body),
|
||||
dec: fold_fn_decl(constructor.node.dec, fld),
|
||||
|
|
@ -394,8 +394,8 @@ fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ {
|
|||
match d {
|
||||
decl_local(ls) => decl_local(vec::map(ls, |x| fld.fold_local(x))),
|
||||
decl_item(it) => match fld.fold_item(it) {
|
||||
some(it_folded) => decl_item(it_folded),
|
||||
none => decl_local(~[])
|
||||
Some(it_folded) => decl_item(it_folded),
|
||||
None => decl_local(~[])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -581,7 +581,7 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
|
|||
fields: vec::map(struct_def.fields,
|
||||
|f| fld.fold_struct_field(f)),
|
||||
methods: vec::map(struct_def.methods, |m| fld.fold_method(m)),
|
||||
ctor: none,
|
||||
ctor: None,
|
||||
dtor: dtor
|
||||
})
|
||||
}
|
||||
|
|
@ -600,8 +600,8 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
|
|||
let attrs = vec::map(v.attrs, fold_attribute);
|
||||
|
||||
let de = match 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,
|
||||
|
|
@ -628,9 +628,9 @@ fn noop_fold_local(l: local_, fld: ast_fold) -> local_ {
|
|||
pat: fld.fold_pat(l.pat),
|
||||
init:
|
||||
match l.init {
|
||||
option::none::<initializer> => l.init,
|
||||
option::some::<initializer>(init) => {
|
||||
option::some::<initializer>({op: init.op,
|
||||
option::None::<initializer> => l.init,
|
||||
option::Some::<initializer>(init) => {
|
||||
option::Some::<initializer>({op: init.op,
|
||||
expr: fld.fold_expr(init.expr)})
|
||||
}
|
||||
},
|
||||
|
|
@ -698,7 +698,7 @@ impl ast_fold_precursor: ast_fold {
|
|||
-> @foreign_item {
|
||||
return self.fold_foreign_item(x, self as ast_fold);
|
||||
}
|
||||
fn fold_item(&&i: @item) -> option<@item> {
|
||||
fn fold_item(&&i: @item) -> Option<@item> {
|
||||
return self.fold_item(i, self as ast_fold);
|
||||
}
|
||||
fn fold_struct_field(&&sf: @struct_field) -> @struct_field {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ type parse_sess = @{
|
|||
mut byte_pos: uint
|
||||
};
|
||||
|
||||
fn new_parse_sess(demitter: option<emitter>) -> parse_sess {
|
||||
fn new_parse_sess(demitter: Option<emitter>) -> parse_sess {
|
||||
let cm = codemap::new_codemap();
|
||||
return @{cm: cm,
|
||||
mut next_id: 1,
|
||||
|
|
@ -51,9 +51,9 @@ fn new_parse_sess_special_handler(sh: span_handler, cm: codemap::codemap)
|
|||
|
||||
fn parse_crate_from_file(input: &Path, cfg: ast::crate_cfg,
|
||||
sess: parse_sess) -> @ast::crate {
|
||||
if input.filetype() == some(~"rc") {
|
||||
if input.filetype() == Some(~"rc") {
|
||||
parse_crate_from_crate_file(input, cfg, sess)
|
||||
} else if input.filetype() == some(~"rs") {
|
||||
} else if input.filetype() == Some(~"rs") {
|
||||
parse_crate_from_source_file(input, cfg, sess)
|
||||
} else {
|
||||
sess.span_diagnostic.handler().fatal(~"unknown input file type: " +
|
||||
|
|
@ -117,7 +117,7 @@ fn parse_expr_from_source_str(name: ~str, source: @~str, cfg: ast::crate_cfg,
|
|||
|
||||
fn parse_item_from_source_str(name: ~str, source: @~str, cfg: ast::crate_cfg,
|
||||
+attrs: ~[ast::attribute],
|
||||
sess: parse_sess) -> option<@ast::item> {
|
||||
sess: parse_sess) -> Option<@ast::item> {
|
||||
let (p, rdr) = new_parser_etc_from_source_str(sess, cfg, name,
|
||||
codemap::fss_none, source);
|
||||
let r = p.parse_item(attrs);
|
||||
|
|
@ -208,6 +208,6 @@ fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg, path: &Path,
|
|||
fn new_parser_from_tt(sess: parse_sess, cfg: ast::crate_cfg,
|
||||
tt: ~[ast::token_tree]) -> parser {
|
||||
let trdr = lexer::new_tt_reader(sess.span_diagnostic, sess.interner,
|
||||
none, tt);
|
||||
None, tt);
|
||||
return parser(sess, cfg, trdr as reader, parser::SOURCE_FILE)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ export parser_attr;
|
|||
|
||||
// A type to distingush between the parsing of item attributes or syntax
|
||||
// extensions, which both begin with token.POUND
|
||||
type attr_or_ext = option<Either<~[ast::attribute], @ast::expr>>;
|
||||
type attr_or_ext = Option<Either<~[ast::attribute], @ast::expr>>;
|
||||
|
||||
trait parser_attr {
|
||||
fn parse_outer_attrs_or_ext(first_item_attrs: ~[ast::attribute])
|
||||
|
|
@ -36,20 +36,20 @@ impl parser: parser_attr {
|
|||
self.bump();
|
||||
let first_attr =
|
||||
self.parse_attribute_naked(ast::attr_outer, lo);
|
||||
return some(Left(vec::append(~[first_attr],
|
||||
return Some(Left(vec::append(~[first_attr],
|
||||
self.parse_outer_attributes())));
|
||||
} else if !(self.look_ahead(1u) == token::LT
|
||||
|| self.look_ahead(1u) == token::LBRACKET
|
||||
|| self.look_ahead(1u) == token::POUND
|
||||
|| expect_item_next) {
|
||||
self.bump();
|
||||
return some(Right(self.parse_syntax_ext_naked(lo)));
|
||||
} else { return none; }
|
||||
return Some(Right(self.parse_syntax_ext_naked(lo)));
|
||||
} else { return None; }
|
||||
}
|
||||
token::DOC_COMMENT(_) => {
|
||||
return some(Left(self.parse_outer_attributes()));
|
||||
return Some(Left(self.parse_outer_attributes()));
|
||||
}
|
||||
_ => return none
|
||||
_ => return None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ fn ends_in_lit_int(ex: @ast::expr) -> bool {
|
|||
ends_in_lit_int(sub)
|
||||
}
|
||||
ast::expr_fail(osub) | ast::expr_ret(osub) => match osub {
|
||||
some(ex) => ends_in_lit_int(ex),
|
||||
Some(ex) => ends_in_lit_int(ex),
|
||||
_ => false
|
||||
},
|
||||
_ => false
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ fn strip_doc_comment_decoration(comment: ~str) -> ~str {
|
|||
}
|
||||
|
||||
// drop leftmost columns that contain only values in chars
|
||||
fn block_trim(lines: ~[~str], chars: ~str, max: option<uint>) -> ~[~str] {
|
||||
fn block_trim(lines: ~[~str], chars: ~str, max: Option<uint>) -> ~[~str] {
|
||||
|
||||
let mut i = max.get_default(uint::max_value);
|
||||
for lines.each |line| {
|
||||
|
|
@ -85,9 +85,9 @@ fn strip_doc_comment_decoration(comment: ~str) -> ~str {
|
|||
if comment.starts_with(~"/*") {
|
||||
let lines = str::lines_any(comment.slice(3u, comment.len() - 2u));
|
||||
let lines = vertical_trim(lines);
|
||||
let lines = block_trim(lines, ~"\t ", none);
|
||||
let lines = block_trim(lines, ~"*", some(1u));
|
||||
let lines = block_trim(lines, ~"\t ", none);
|
||||
let lines = block_trim(lines, ~"\t ", None);
|
||||
let lines = block_trim(lines, ~"*", Some(1u));
|
||||
let lines = block_trim(lines, ~"\t ", None);
|
||||
return str::connect(lines, ~"\n");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,18 +4,18 @@ import parser::parser;
|
|||
import lexer::reader;
|
||||
|
||||
type seq_sep = {
|
||||
sep: option<token::token>,
|
||||
sep: Option<token::token>,
|
||||
trailing_sep_allowed: bool
|
||||
};
|
||||
|
||||
fn seq_sep_trailing_disallowed(t: token::token) -> seq_sep {
|
||||
return {sep: option::some(t), trailing_sep_allowed: false};
|
||||
return {sep: option::Some(t), trailing_sep_allowed: false};
|
||||
}
|
||||
fn seq_sep_trailing_allowed(t: token::token) -> seq_sep {
|
||||
return {sep: option::some(t), trailing_sep_allowed: true};
|
||||
return {sep: option::Some(t), trailing_sep_allowed: true};
|
||||
}
|
||||
fn seq_sep_none() -> seq_sep {
|
||||
return {sep: option::none, trailing_sep_allowed: false};
|
||||
return {sep: option::None, trailing_sep_allowed: false};
|
||||
}
|
||||
|
||||
fn token_to_str(reader: reader, ++token: token::token) -> ~str {
|
||||
|
|
@ -41,11 +41,11 @@ trait parser_common {
|
|||
fn check_restricted_keywords();
|
||||
fn check_restricted_keywords_(w: ~str);
|
||||
fn expect_gt();
|
||||
fn parse_seq_to_before_gt<T: copy>(sep: option<token::token>,
|
||||
fn parse_seq_to_before_gt<T: copy>(sep: Option<token::token>,
|
||||
f: fn(parser) -> T) -> ~[T];
|
||||
fn parse_seq_to_gt<T: copy>(sep: option<token::token>,
|
||||
fn parse_seq_to_gt<T: copy>(sep: Option<token::token>,
|
||||
f: fn(parser) -> T) -> ~[T];
|
||||
fn parse_seq_lt_gt<T: copy>(sep: option<token::token>,
|
||||
fn parse_seq_lt_gt<T: copy>(sep: Option<token::token>,
|
||||
f: fn(parser) -> T) -> spanned<~[T]>;
|
||||
fn parse_seq_to_end<T: copy>(ket: token::token, sep: seq_sep,
|
||||
f: fn(parser) -> T) -> ~[T];
|
||||
|
|
@ -198,14 +198,14 @@ impl parser: parser_common {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_seq_to_before_gt<T: copy>(sep: option<token::token>,
|
||||
fn parse_seq_to_before_gt<T: copy>(sep: Option<token::token>,
|
||||
f: fn(parser) -> T) -> ~[T] {
|
||||
let mut first = true;
|
||||
let mut v = ~[];
|
||||
while self.token != token::GT
|
||||
&& self.token != token::BINOP(token::SHR) {
|
||||
match sep {
|
||||
some(t) => {
|
||||
Some(t) => {
|
||||
if first { first = false; }
|
||||
else { self.expect(t); }
|
||||
}
|
||||
|
|
@ -217,7 +217,7 @@ impl parser: parser_common {
|
|||
return v;
|
||||
}
|
||||
|
||||
fn parse_seq_to_gt<T: copy>(sep: option<token::token>,
|
||||
fn parse_seq_to_gt<T: copy>(sep: Option<token::token>,
|
||||
f: fn(parser) -> T) -> ~[T] {
|
||||
let v = self.parse_seq_to_before_gt(sep, f);
|
||||
self.expect_gt();
|
||||
|
|
@ -225,7 +225,7 @@ impl parser: parser_common {
|
|||
return v;
|
||||
}
|
||||
|
||||
fn parse_seq_lt_gt<T: copy>(sep: option<token::token>,
|
||||
fn parse_seq_lt_gt<T: copy>(sep: Option<token::token>,
|
||||
f: fn(parser) -> T) -> spanned<~[T]> {
|
||||
let lo = self.span.lo;
|
||||
self.expect(token::LT);
|
||||
|
|
@ -249,7 +249,7 @@ impl parser: parser_common {
|
|||
let mut v: ~[T] = ~[];
|
||||
while self.token != ket {
|
||||
match sep.sep {
|
||||
some(t) => {
|
||||
Some(t) => {
|
||||
if first { first = false; }
|
||||
else { self.expect(t); }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ fn eval_crate_directives(cx: ctx,
|
|||
}
|
||||
|
||||
fn eval_crate_directives_to_mod(cx: ctx, cdirs: ~[@ast::crate_directive],
|
||||
prefix: &Path, suffix: &option<Path>)
|
||||
prefix: &Path, suffix: &Option<Path>)
|
||||
-> (ast::_mod, ~[ast::attribute]) {
|
||||
let (cview_items, citems, cattrs)
|
||||
= parse_companion_mod(cx, prefix, suffix);
|
||||
|
|
@ -40,13 +40,13 @@ companion mod is a .rs file with the same name as the directory.
|
|||
We build the path to the companion mod by combining the prefix and the
|
||||
optional suffix then adding the .rs extension.
|
||||
*/
|
||||
fn parse_companion_mod(cx: ctx, prefix: &Path, suffix: &option<Path>)
|
||||
fn parse_companion_mod(cx: ctx, prefix: &Path, suffix: &Option<Path>)
|
||||
-> (~[@ast::view_item], ~[@ast::item], ~[ast::attribute]) {
|
||||
|
||||
fn companion_file(prefix: &Path, suffix: &option<Path>) -> Path {
|
||||
fn companion_file(prefix: &Path, suffix: &Option<Path>) -> Path {
|
||||
return match *suffix {
|
||||
option::some(s) => prefix.push_many(s.components),
|
||||
option::none => copy *prefix
|
||||
option::Some(s) => prefix.push_many(s.components),
|
||||
option::None => copy *prefix
|
||||
}.with_filetype("rs");
|
||||
}
|
||||
|
||||
|
|
@ -76,8 +76,8 @@ fn parse_companion_mod(cx: ctx, prefix: &Path, suffix: &option<Path>)
|
|||
|
||||
fn cdir_path_opt(default: ~str, attrs: ~[ast::attribute]) -> ~str {
|
||||
match ::attr::first_attr_value_str_by_name(attrs, ~"path") {
|
||||
some(d) => d,
|
||||
none => default
|
||||
Some(d) => d,
|
||||
None => default
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +117,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &Path,
|
|||
prefix.push_many(path.components)
|
||||
};
|
||||
let (m0, a0) = eval_crate_directives_to_mod(
|
||||
cx, cdirs, &full_path, &none);
|
||||
cx, cdirs, &full_path, &None);
|
||||
let i =
|
||||
@{ident: /* FIXME (#2543) */ copy id,
|
||||
attrs: vec::append(attrs, a0),
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue