Skip to content

Commit 4cf2e51

Browse files
committed
Convert std::getopts to istrs. Issue #855
1 parent 3a5f4e7 commit 4cf2e51

File tree

7 files changed

+287
-259
lines changed

7 files changed

+287
-259
lines changed

src/comp/driver/rustc.rs

Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -330,45 +330,47 @@ fn build_target_config() -> @session::config {
330330
ret target_cfg;
331331
}
332332

333-
fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
333+
fn build_session_options(binary: str, match: &getopts::match, binary_dir: str)
334334
-> @session::options {
335-
let library = opt_present(match, "lib");
336-
let static = opt_present(match, "static");
335+
let library = opt_present(match, ~"lib");
336+
let static = opt_present(match, ~"static");
337337

338338
let library_search_paths = [binary_dir + "/lib"];
339-
let lsp_vec = getopts::opt_strs(match, "L");
340-
for lsp: str in lsp_vec { library_search_paths += [lsp]; }
339+
let lsp_vec = getopts::opt_strs(match, ~"L");
340+
for lsp: istr in lsp_vec {
341+
library_search_paths += [istr::to_estr(lsp)];
342+
}
341343

342-
let parse_only = opt_present(match, "parse-only");
343-
let no_trans = opt_present(match, "no-trans");
344+
let parse_only = opt_present(match, ~"parse-only");
345+
let no_trans = opt_present(match, ~"no-trans");
344346

345347
let output_type =
346348
if parse_only || no_trans {
347349
link::output_type_none
348-
} else if opt_present(match, "S") {
350+
} else if opt_present(match, ~"S") {
349351
link::output_type_assembly
350-
} else if opt_present(match, "c") {
352+
} else if opt_present(match, ~"c") {
351353
link::output_type_object
352-
} else if opt_present(match, "emit-llvm") {
354+
} else if opt_present(match, ~"emit-llvm") {
353355
link::output_type_bitcode
354356
} else { link::output_type_exe };
355-
let verify = !opt_present(match, "noverify");
356-
let save_temps = opt_present(match, "save-temps");
357-
let debuginfo = opt_present(match, "g");
358-
let stats = opt_present(match, "stats");
359-
let time_passes = opt_present(match, "time-passes");
360-
let time_llvm_passes = opt_present(match, "time-llvm-passes");
361-
let run_typestate = !opt_present(match, "no-typestate");
362-
let sysroot_opt = getopts::opt_maybe_str(match, "sysroot");
357+
let verify = !opt_present(match, ~"noverify");
358+
let save_temps = opt_present(match, ~"save-temps");
359+
let debuginfo = opt_present(match, ~"g");
360+
let stats = opt_present(match, ~"stats");
361+
let time_passes = opt_present(match, ~"time-passes");
362+
let time_llvm_passes = opt_present(match, ~"time-llvm-passes");
363+
let run_typestate = !opt_present(match, ~"no-typestate");
364+
let sysroot_opt = getopts::opt_maybe_str(match, ~"sysroot");
363365
let opt_level: uint =
364-
if opt_present(match, "O") {
365-
if opt_present(match, "OptLevel") {
366+
if opt_present(match, ~"O") {
367+
if opt_present(match, ~"OptLevel") {
366368
log_err "error: -O and --OptLevel both provided";
367369
fail;
368370
}
369371
2u
370-
} else if opt_present(match, "OptLevel") {
371-
alt getopts::opt_str(match, "OptLevel") {
372+
} else if opt_present(match, ~"OptLevel") {
373+
alt istr::to_estr(getopts::opt_str(match, ~"OptLevel")) {
372374
"0" { 0u }
373375
"1" { 1u }
374376
"2" { 2u }
@@ -383,11 +385,12 @@ fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
383385
let sysroot =
384386
alt sysroot_opt {
385387
none. { get_default_sysroot(binary) }
386-
some(s) { s }
388+
some(s) { istr::to_estr(s) }
387389
};
388-
let cfg = parse_cfgspecs(getopts::opt_strs(match, "cfg"));
389-
let test = opt_present(match, "test");
390-
let do_gc = opt_present(match, "gc");
390+
let cfg = parse_cfgspecs(
391+
istr::to_estrs(getopts::opt_strs(match, ~"cfg")));
392+
let test = opt_present(match, ~"test");
393+
let do_gc = opt_present(match, ~"gc");
391394
let sopts: @session::options =
392395
@{library: library,
393396
static: static,
@@ -418,60 +421,62 @@ fn build_session(sopts: @session::options) -> session::session {
418421
none, 0u);
419422
}
420423

421-
fn parse_pretty(sess: session::session, name: &str) -> pp_mode {
422-
if str::eq(name, "normal") {
424+
fn parse_pretty(sess: session::session, name: &istr) -> pp_mode {
425+
if istr::eq(name, ~"normal") {
423426
ret ppm_normal;
424-
} else if str::eq(name, "expanded") {
427+
} else if istr::eq(name, ~"expanded") {
425428
ret ppm_expanded;
426-
} else if str::eq(name, "typed") {
429+
} else if istr::eq(name, ~"typed") {
427430
ret ppm_typed;
428-
} else if str::eq(name, "identified") { ret ppm_identified; }
431+
} else if istr::eq(name, ~"identified") { ret ppm_identified; }
429432
sess.fatal("argument to `pretty` must be one of `normal`, `typed`, or "
430433
+ "`identified`");
431434
}
432435

433436
fn opts() -> [getopts::opt] {
434-
ret [optflag("h"), optflag("help"), optflag("v"), optflag("version"),
435-
optflag("glue"), optflag("emit-llvm"), optflagopt("pretty"),
436-
optflag("ls"), optflag("parse-only"), optflag("no-trans"),
437-
optflag("O"), optopt("OptLevel"), optmulti("L"),
438-
optflag("S"), optflag("c"), optopt("o"), optflag("g"),
439-
optflag("save-temps"), optopt("sysroot"), optflag("stats"),
440-
optflag("time-passes"), optflag("time-llvm-passes"),
441-
optflag("no-typestate"), optflag("noverify"), optmulti("cfg"),
442-
optflag("test"), optflag("lib"), optflag("static"), optflag("gc")];
437+
ret [optflag(~"h"), optflag(~"help"), optflag(~"v"), optflag(~"version"),
438+
optflag(~"glue"), optflag(~"emit-llvm"), optflagopt(~"pretty"),
439+
optflag(~"ls"), optflag(~"parse-only"), optflag(~"no-trans"),
440+
optflag(~"O"), optopt(~"OptLevel"), optmulti(~"L"),
441+
optflag(~"S"), optflag(~"c"), optopt(~"o"), optflag(~"g"),
442+
optflag(~"save-temps"), optopt(~"sysroot"), optflag(~"stats"),
443+
optflag(~"time-passes"), optflag(~"time-llvm-passes"),
444+
optflag(~"no-typestate"), optflag(~"noverify"), optmulti(~"cfg"),
445+
optflag(~"test"), optflag(~"lib"), optflag(~"static"),
446+
optflag(~"gc")];
443447
}
444448

445449
fn main(args: [str]) {
446450
let binary = vec::shift(args);
447451
let binary_dir = istr::to_estr(
448452
fs::dirname(istr::from_estr(binary)));
449453
let match =
450-
alt getopts::getopts(args, opts()) {
454+
alt getopts::getopts(istr::from_estrs(args), opts()) {
451455
getopts::success(m) { m }
452456
getopts::failure(f) {
453-
log_err #fmt["error: %s", getopts::fail_str(f)];
457+
log_err #fmt["error: %s", istr::to_estr(getopts::fail_str(f))];
454458
fail
455459
}
456460
};
457-
if opt_present(match, "h") || opt_present(match, "help") {
461+
if opt_present(match, ~"h") || opt_present(match, ~"help") {
458462
usage(binary);
459463
ret;
460464
}
461-
if opt_present(match, "v") || opt_present(match, "version") {
465+
if opt_present(match, ~"v") || opt_present(match, ~"version") {
462466
version(binary);
463467
ret;
464468
}
465469
let sopts = build_session_options(binary, match, binary_dir);
466470
let sess = build_session(sopts);
467-
let n_inputs = vec::len::<str>(match.free);
468-
let output_file = getopts::opt_maybe_str(match, "o");
469-
let glue = opt_present(match, "glue");
471+
let n_inputs = vec::len::<istr>(match.free);
472+
let output_file = getopts::opt_maybe_str(match, ~"o");
473+
let glue = opt_present(match, ~"glue");
470474
if glue {
471475
if n_inputs > 0u {
472476
sess.fatal("No input files allowed with --glue.");
473477
}
474-
let out = option::from_maybe::<str>("glue.bc", output_file);
478+
let out = option::from_maybe::<istr>(~"glue.bc", output_file);
479+
let out = istr::to_estr(out);
475480
middle::trans::make_common_glue(sess, out);
476481
ret;
477482
}
@@ -480,22 +485,22 @@ fn main(args: [str]) {
480485
} else if n_inputs > 1u {
481486
sess.fatal("Multiple input filenames provided.");
482487
}
483-
let ifile = match.free[0];
488+
let ifile = istr::to_estr(match.free[0]);
484489
let saved_out_filename: str = "";
485490
let cfg = build_configuration(sess, binary, ifile);
486491
let pretty =
487-
option::map::<str,
492+
option::map::<istr,
488493
pp_mode>(bind parse_pretty(sess, _),
489-
getopts::opt_default(match, "pretty",
490-
"normal"));
494+
getopts::opt_default(match, ~"pretty",
495+
~"normal"));
491496
alt pretty {
492497
some::<pp_mode>(ppm) {
493498
pretty_print_input(sess, cfg, ifile, ppm);
494499
ret;
495500
}
496501
none::<pp_mode>. {/* continue */ }
497502
}
498-
let ls = opt_present(match, "ls");
503+
let ls = opt_present(match, ~"ls");
499504
if ls { metadata::creader::list_file_metadata(ifile, io::stdout()); ret; }
500505

501506
let stop_after_codegen =
@@ -528,6 +533,7 @@ fn main(args: [str]) {
528533
compile_input(sess, cfg, ifile, ofile);
529534
}
530535
some(ofile) {
536+
let ofile = istr::to_estr(ofile);
531537
// FIXME: what about windows? This will create a foo.exe.o.
532538
saved_out_filename = ofile;
533539
let temp_filename =
@@ -634,7 +640,7 @@ mod test {
634640
#[test]
635641
fn test_switch_implies_cfg_test() {
636642
let match =
637-
alt getopts::getopts(["--test"], opts()) {
643+
alt getopts::getopts([~"--test"], opts()) {
638644
getopts::success(m) { m }
639645
};
640646
let sessopts = build_session_options("whatever", match, "whatever");
@@ -648,7 +654,7 @@ mod test {
648654
#[test]
649655
fn test_switch_implies_cfg_test_unless_cfg_test() {
650656
let match =
651-
alt getopts::getopts(["--test", "--cfg=test"], opts()) {
657+
alt getopts::getopts([~"--test", ~"--cfg=test"], opts()) {
652658
getopts::success(m) { m }
653659
};
654660
let sessopts = build_session_options("whatever", match, "whatever");

0 commit comments

Comments
 (0)