about summary refs log tree commit diff
path: root/src/comp/driver
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-08-19 15:16:48 -0700
committerBrian Anderson <banderson@mozilla.com>2011-08-20 11:04:00 -0700
commit518dc52f85c2efb67aaa1208c02e9a7e0bdaca49 (patch)
tree9af4f631455ff5ba42b233819fe4bb9f3b9ac194 /src/comp/driver
parent4aa165553bfb2a74e2e54f08fd9507e23bc24708 (diff)
downloadrust-518dc52f85c2efb67aaa1208c02e9a7e0bdaca49.tar.gz
rust-518dc52f85c2efb67aaa1208c02e9a7e0bdaca49.zip
Reformat
This changes the indexing syntax from .() to [], the vector syntax from ~[] to
[] and the extension syntax from #fmt() to #fmt[]
Diffstat (limited to 'src/comp/driver')
-rw-r--r--src/comp/driver/rustc.rs192
-rw-r--r--src/comp/driver/session.rs7
2 files changed, 97 insertions, 102 deletions
diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs
index 6c125f0e176..a75a46e64c7 100644
--- a/src/comp/driver/rustc.rs
+++ b/src/comp/driver/rustc.rs
@@ -53,11 +53,11 @@ fn default_configuration(sess: session::session, argv0: str, input: str) ->
 
     let mk = attr::mk_name_value_item_str;
 
-    ret ~[ // Target bindings.
-          mk("target_os", std::os::target_os()), mk("target_arch", "x86"),
-          mk("target_libc", libc),
-          // Build bindings.
-          mk("build_compiler", argv0), mk("build_input", input)];
+    ret [ // Target bindings.
+         mk("target_os", std::os::target_os()), mk("target_arch", "x86"),
+         mk("target_libc", libc),
+         // Build bindings.
+         mk("build_compiler", argv0), mk("build_input", input)];
 }
 
 fn build_configuration(sess: session::session, argv0: str, input: str) ->
@@ -71,8 +71,8 @@ fn build_configuration(sess: session::session, argv0: str, input: str) ->
         {
             if sess.get_opts().test && !attr::contains_name(user_cfg, "test")
                {
-                ~[attr::mk_word_item("test")]
-            } else { ~[] }
+                [attr::mk_word_item("test")]
+            } else { [] }
         };
     ret user_cfg + gen_cfg + default_cfg;
 }
@@ -81,8 +81,8 @@ fn build_configuration(sess: session::session, argv0: str, input: str) ->
 fn parse_cfgspecs(cfgspecs: &[str]) -> ast::crate_cfg {
     // FIXME: It would be nice to use the parser to parse all varieties of
     // meta_item here. At the moment we just support the meta_word variant.
-    let words = ~[];
-    for s: str in cfgspecs { words += ~[attr::mk_word_item(s)]; }
+    let words = [];
+    for s: str in cfgspecs { words += [attr::mk_word_item(s)]; }
     ret words;
 }
 
@@ -92,31 +92,29 @@ fn parse_input(sess: session::session, cfg: &ast::crate_cfg, input: str) ->
    @ast::crate {
     if !input_is_stdin(input) {
         parser::parse_crate_from_file(input, cfg, sess.get_parse_sess())
-    } else {
-        parse_input_src(sess, cfg, input).crate
-    }
+    } else { parse_input_src(sess, cfg, input).crate }
 }
 
-fn parse_input_src(sess: session::session, cfg: &ast::crate_cfg,
-                   infile: str) -> {crate: @ast::crate, src: str} {
-    let srcbytes = if infile != "-" {
-        io::file_reader(infile)
-    } else {
-        io::stdin()
-    }.read_whole_stream();
+fn parse_input_src(sess: session::session, cfg: &ast::crate_cfg, infile: str)
+   -> {crate: @ast::crate, src: str} {
+    let srcbytes =
+        if infile != "-" {
+            io::file_reader(infile)
+        } else { io::stdin() }.read_whole_stream();
     let src = str::unsafe_from_bytes(srcbytes);
-    let crate = parser::parse_crate_from_source_str(infile, src, cfg,
-                                                    sess.get_parse_sess());
+    let crate =
+        parser::parse_crate_from_source_str(infile, src, cfg,
+                                            sess.get_parse_sess());
     ret {crate: crate, src: src};
 }
 
-fn time<T>(do_it: bool, what: str, thunk: fn() -> T ) -> T {
+fn time<T>(do_it: bool, what: str, thunk: fn() -> T) -> T {
     if !do_it { ret thunk(); }
     let start = std::time::precise_time_s();
     let rv = thunk();
     let end = std::time::precise_time_s();
-    log_err #fmt("time: %s took %s s", what,
-                 common::float_to_str(end - start, 3u));
+    log_err #fmt["time: %s took %s s", what,
+                 common::float_to_str(end - start, 3u)];
     ret rv;
 }
 
@@ -143,7 +141,7 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
              bind middle::ast_map::map_crate(*crate));
     time(time_passes, "external crate/lib resolution",
          bind creader::read_crates(sess, *crate));
-    let {def_map, ext_map} =
+    let {def_map: def_map, ext_map: ext_map} =
         time(time_passes, "resolution",
              bind resolve::resolve_crate(sess, ast_map, crate));
     let freevars =
@@ -151,9 +149,9 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
              bind freevars::annotate_freevars(sess, def_map, crate));
     let ty_cx = ty::mk_ctxt(sess, def_map, ext_map, ast_map, freevars);
     time::<()>(time_passes, "typechecking",
-             bind typeck::check_crate(ty_cx, crate));
+               bind typeck::check_crate(ty_cx, crate));
     time::<()>(time_passes, "alt checking",
-             bind middle::check_alt::check_crate(ty_cx, crate));
+               bind middle::check_alt::check_crate(ty_cx, crate));
     if sess.get_opts().run_typestate {
         time(time_passes, "typestate checking",
              bind middle::tstate::ck::check_crate(ty_cx, crate));
@@ -161,15 +159,15 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
     time(time_passes, "alias checking",
          bind middle::alias::check_crate(ty_cx, crate));
     time::<()>(time_passes, "kind checking",
-             bind kind::check_crate(ty_cx, crate));
+               bind kind::check_crate(ty_cx, crate));
     if sess.get_opts().no_trans { ret; }
     let llmod =
         time::<llvm::llvm::ModuleRef>(time_passes, "translation",
-                                    bind trans::trans_crate(sess, crate,
-                                                            ty_cx, output,
-                                                            ast_map));
+                                      bind trans::trans_crate(sess, crate,
+                                                              ty_cx, output,
+                                                              ast_map));
     time::<()>(time_passes, "LLVM passes",
-             bind link::write::run_passes(sess, llmod, output));
+               bind link::write::run_passes(sess, llmod, output));
 }
 
 fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
@@ -222,7 +220,8 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
     alt ppm {
       ppm_typed. {
         let amap = middle::ast_map::map_crate(*crate);
-        let {def_map, ext_map} = resolve::resolve_crate(sess, amap, crate);
+        let {def_map: def_map, ext_map: ext_map} =
+            resolve::resolve_crate(sess, amap, crate);
         let freevars = freevars::annotate_freevars(sess, def_map, crate);
         let ty_cx = ty::mk_ctxt(sess, def_map, ext_map, amap, freevars);
         typeck::check_crate(ty_cx, crate);
@@ -239,14 +238,14 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
 
 fn version(argv0: str) {
     let vers = "unknown version";
-    let env_vers = #env("CFG_VERSION");
+    let env_vers = #env["CFG_VERSION"];
     if str::byte_len(env_vers) != 0u { vers = env_vers; }
-    io::stdout().write_str(#fmt("%s %s\n", argv0, vers));
+    io::stdout().write_str(#fmt["%s %s\n", argv0, vers]);
 }
 
 fn usage(argv0: str) {
-    io::stdout().write_str(#fmt("usage: %s [options] <input>\n", argv0) +
-                                   "
+    io::stdout().write_str(#fmt["usage: %s [options] <input>\n", argv0] +
+                               "
 options:
 
     -h --help          display this message
@@ -287,9 +286,9 @@ fn get_os(triple: str) -> session::os {
     ret if str::find(triple, "win32") >= 0 ||
                str::find(triple, "mingw32") >= 0 {
             session::os_win32
-        } else if (str::find(triple, "darwin") >= 0) {
+        } else if str::find(triple, "darwin") >= 0 {
             session::os_macos
-        } else if (str::find(triple, "linux") >= 0) {
+        } else if str::find(triple, "linux") >= 0 {
             session::os_linux
         } else { log_err "Unknown operating system!"; fail };
 }
@@ -300,10 +299,10 @@ fn get_arch(triple: str) -> session::arch {
                str::find(triple, "i686") >= 0 ||
                str::find(triple, "i786") >= 0 {
             session::arch_x86
-        } else if (str::find(triple, "x86_64") >= 0) {
+        } else if str::find(triple, "x86_64") >= 0 {
             session::arch_x64
-        } else if (str::find(triple, "arm") >= 0 ||
-                       str::find(triple, "xscale") >= 0) {
+        } else if str::find(triple, "arm") >= 0 ||
+                      str::find(triple, "xscale") >= 0 {
             session::arch_arm
         } else { log_err "Unknown architecture! " + triple; fail };
 }
@@ -331,9 +330,9 @@ fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
     let library = opt_present(match, "lib");
     let static = opt_present(match, "static");
 
-    let library_search_paths = ~[binary_dir + "/lib"];
+    let library_search_paths = [binary_dir + "/lib"];
     let lsp_vec = getopts::opt_strs(match, "L");
-    for lsp: str in lsp_vec { library_search_paths += ~[lsp]; }
+    for lsp: str in lsp_vec { library_search_paths += [lsp]; }
 
     let parse_only = opt_present(match, "parse-only");
     let no_trans = opt_present(match, "no-trans");
@@ -341,11 +340,11 @@ fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
     let output_type =
         if parse_only || no_trans {
             link::output_type_none
-        } else if (opt_present(match, "S")) {
+        } else if opt_present(match, "S") {
             link::output_type_assembly
-        } else if (opt_present(match, "c")) {
+        } else if opt_present(match, "c") {
             link::output_type_object
-        } else if (opt_present(match, "emit-llvm")) {
+        } else if opt_present(match, "emit-llvm") {
             link::output_type_bitcode
         } else { link::output_type_exe };
     let verify = !opt_present(match, "noverify");
@@ -363,7 +362,7 @@ fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
                 fail;
             }
             2u
-        } else if (opt_present(match, "OptLevel")) {
+        } else if opt_present(match, "OptLevel") {
             alt getopts::opt_str(match, "OptLevel") {
               "0" { 0u }
               "1" { 1u }
@@ -417,24 +416,23 @@ fn build_session(sopts: @session::options) -> session::session {
 fn parse_pretty(sess: session::session, name: &str) -> pp_mode {
     if str::eq(name, "normal") {
         ret ppm_normal;
-    } else if (str::eq(name, "typed")) {
+    } else if str::eq(name, "typed") {
         ret ppm_typed;
-    } else if (str::eq(name, "identified")) { ret ppm_identified; }
+    } else if str::eq(name, "identified") { ret ppm_identified; }
     sess.fatal("argument to `pretty` or `expand` must be one of `normal`, " +
                    "`typed`, or `identified`");
 }
 
 fn opts() -> [getopts::opt] {
-    ret ~[optflag("h"), optflag("help"), optflag("v"), optflag("version"),
-          optflag("glue"), optflag("emit-llvm"), optflagopt("pretty"),
-          optflagopt("expand"), optflag("ls"), optflag("parse-only"),
-          optflag("no-trans"),
-          optflag("O"), optopt("OptLevel"), optmulti("L"), optflag("S"),
-          optflag("c"), optopt("o"), optflag("g"), optflag("save-temps"),
-          optopt("sysroot"), optflag("stats"), optflag("time-passes"),
-          optflag("time-llvm-passes"), optflag("no-typestate"),
-          optflag("noverify"), optmulti("cfg"), optflag("test"),
-          optflag("lib"), optflag("static"), optflag("gc")];
+    ret [optflag("h"), optflag("help"), optflag("v"), optflag("version"),
+         optflag("glue"), optflag("emit-llvm"), optflagopt("pretty"),
+         optflagopt("expand"), optflag("ls"), optflag("parse-only"),
+         optflag("no-trans"), optflag("O"), optopt("OptLevel"), optmulti("L"),
+         optflag("S"), optflag("c"), optopt("o"), optflag("g"),
+         optflag("save-temps"), optopt("sysroot"), optflag("stats"),
+         optflag("time-passes"), optflag("time-llvm-passes"),
+         optflag("no-typestate"), optflag("noverify"), optmulti("cfg"),
+         optflag("test"), optflag("lib"), optflag("static"), optflag("gc")];
 }
 
 fn main(args: [str]) {
@@ -444,7 +442,7 @@ fn main(args: [str]) {
         alt getopts::getopts(args, opts()) {
           getopts::success(m) { m }
           getopts::failure(f) {
-            log_err #fmt("error: %s", getopts::fail_str(f));
+            log_err #fmt["error: %s", getopts::fail_str(f)];
             fail
           }
         };
@@ -471,10 +469,10 @@ fn main(args: [str]) {
     }
     if n_inputs == 0u {
         sess.fatal("No input filename given.");
-    } else if (n_inputs > 1u) {
+    } else if n_inputs > 1u {
         sess.fatal("Multiple input filenames provided.");
     }
-    let ifile = match.free.(0);
+    let ifile = match.free[0];
     let saved_out_filename: str = "";
     let cfg = build_configuration(sess, binary, ifile);
     let expand =
@@ -502,10 +500,7 @@ fn main(args: [str]) {
       none::<pp_mode>. {/* continue */ }
     }
     let ls = opt_present(match, "ls");
-    if ls {
-        metadata::creader::list_file_metadata(ifile, io::stdout());
-        ret;
-    }
+    if ls { metadata::creader::list_file_metadata(ifile, io::stdout()); ret; }
 
     let stop_after_codegen =
         sopts.output_type != link::output_type_exe ||
@@ -516,29 +511,31 @@ fn main(args: [str]) {
         // "-" as input file will cause the parser to read from stdin so we
         // have to make up a name
         // We want to toss everything after the final '.'
-        let parts = if !input_is_stdin(ifile) {
-            str::split(ifile, '.' as u8)
-        } else {
-            ~["default", "rs"]
-        };
+        let parts =
+            if !input_is_stdin(ifile) {
+                str::split(ifile, '.' as u8)
+            } else { ["default", "rs"] };
         vec::pop(parts);
         saved_out_filename = str::connect(parts, ".");
-        let suffix = alt sopts.output_type {
-          link::output_type_none. { "none" }
-          link::output_type_bitcode. { "bc" }
-          link::output_type_assembly. { "s" }
-          // Object and exe output both use the '.o' extension here
-          link::output_type_object. | link::output_type_exe. { "o" }
-        };
+        let suffix =
+            alt sopts.output_type {
+              link::output_type_none. { "none" }
+              link::output_type_bitcode. { "bc" }
+              link::output_type_assembly. { "s" }
+
+              // Object and exe output both use the '.o' extension here
+              link::output_type_object. | link::output_type_exe. {
+                "o"
+              }
+            };
         let ofile = saved_out_filename + "." + suffix;
         compile_input(sess, cfg, ifile, ofile);
       }
       some(ofile) {
         // FIXME: what about windows? This will create a foo.exe.o.
         saved_out_filename = ofile;
-        let temp_filename = if !stop_after_codegen {
-            ofile + ".o"
-        } else { ofile };
+        let temp_filename =
+            if !stop_after_codegen { ofile + ".o" } else { ofile };
         compile_input(sess, cfg, ifile, temp_filename);
       }
     }
@@ -556,8 +553,8 @@ fn main(args: [str]) {
     // The invocations of gcc share some flags across platforms
 
     let gcc_args =
-        ~[stage, "-Lrt", "-lrustrt", glu, "-m32", "-o", saved_out_filename,
-          saved_out_filename + ".o"];
+        [stage, "-Lrt", "-lrustrt", glu, "-m32", "-o", saved_out_filename,
+         saved_out_filename + ".o"];
     let lib_cmd;
 
     let os = sess.get_targ_cfg().os;
@@ -591,46 +588,45 @@ fn main(args: [str]) {
     let cstore = sess.get_cstore();
     for cratepath: str in cstore::get_used_crate_files(cstore) {
         if str::ends_with(cratepath, ".rlib") {
-            gcc_args += ~[cratepath];
+            gcc_args += [cratepath];
             cont;
         }
         let dir = fs::dirname(cratepath);
-        if dir != "" { gcc_args += ~["-L" + dir]; }
+        if dir != "" { gcc_args += ["-L" + dir]; }
         let libarg = unlib(sess.get_targ_cfg(), fs::basename(cratepath));
-        gcc_args += ~["-l" + libarg];
+        gcc_args += ["-l" + libarg];
     }
 
     let ula = cstore::get_used_link_args(cstore);
-    for arg: str in ula { gcc_args += ~[arg]; }
+    for arg: str in ula { gcc_args += [arg]; }
 
     let used_libs = cstore::get_used_libraries(cstore);
-    for l: str in used_libs { gcc_args += ~["-l" + l]; }
+    for l: str in used_libs { gcc_args += ["-l" + l]; }
 
     if sopts.library {
-        gcc_args += ~[lib_cmd];
+        gcc_args += [lib_cmd];
     } else {
         // FIXME: why do we hardcode -lm?
-        gcc_args += ~["-lm", main];
+        gcc_args += ["-lm", main];
     }
     // We run 'gcc' here
 
     let err_code = run::run_program(prog, gcc_args);
     if 0 != err_code {
-        sess.err(#fmt("linking with gcc failed with code %d", err_code));
-        sess.note(#fmt("gcc arguments: %s",
-                       str::connect(gcc_args, " ")));
+        sess.err(#fmt["linking with gcc failed with code %d", err_code]);
+        sess.note(#fmt["gcc arguments: %s", str::connect(gcc_args, " ")]);
         sess.abort_if_errors();
     }
     // Clean up on Darwin
 
     if sess.get_targ_cfg().os == session::os_macos {
-        run::run_program("dsymutil", ~[saved_out_filename]);
+        run::run_program("dsymutil", [saved_out_filename]);
     }
 
 
     // Remove the temporary object file if we aren't saving temps
     if !sopts.save_temps {
-        run::run_program("rm", ~[saved_out_filename + ".o"]);
+        run::run_program("rm", [saved_out_filename + ".o"]);
     }
 }
 
@@ -641,7 +637,7 @@ mod test {
     #[test]
     fn test_switch_implies_cfg_test() {
         let match =
-            alt getopts::getopts(~["--test"], opts()) {
+            alt getopts::getopts(["--test"], opts()) {
               getopts::success(m) { m }
             };
         let sessopts = build_session_options("whatever", match, "whatever");
@@ -655,7 +651,7 @@ mod test {
     #[test]
     fn test_switch_implies_cfg_test_unless_cfg_test() {
         let match =
-            alt getopts::getopts(~["--test", "--cfg=test"], opts()) {
+            alt getopts::getopts(["--test", "--cfg=test"], opts()) {
               getopts::success(m) { m }
             };
         let sessopts = build_session_options("whatever", match, "whatever");
diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs
index ea3eae60767..5a2b26739aa 100644
--- a/src/comp/driver/session.rs
+++ b/src/comp/driver/session.rs
@@ -43,8 +43,7 @@ type options =
      test: bool,
      parse_only: bool,
      no_trans: bool,
-     do_gc: bool
-     };
+     do_gc: bool};
 
 type crate_metadata = {name: str, data: [u8]};
 
@@ -90,10 +89,10 @@ obj session(targ_cfg: @config,
     }
     fn note(msg: str) { codemap::emit_note(none, msg, parse_sess.cm); }
     fn span_bug(sp: span, msg: str) -> ! {
-        self.span_fatal(sp, #fmt("internal compiler error %s", msg));
+        self.span_fatal(sp, #fmt["internal compiler error %s", msg]);
     }
     fn bug(msg: str) -> ! {
-        self.fatal(#fmt("internal compiler error %s", msg));
+        self.fatal(#fmt["internal compiler error %s", msg]);
     }
     fn span_unimpl(sp: span, msg: str) -> ! {
         self.span_bug(sp, "unimplemented " + msg);