]> git.lizzy.rs Git - rust.git/commitdiff
Review changes
authorNick Cameron <ncameron@mozilla.com>
Tue, 3 Feb 2015 00:40:52 +0000 (13:40 +1300)
committerNick Cameron <ncameron@mozilla.com>
Mon, 9 Feb 2015 06:58:49 +0000 (19:58 +1300)
src/librustc/session/config.rs
src/librustc_driver/driver.rs
src/librustc_driver/lib.rs
src/librustdoc/test.rs
src/test/run-pass-fulldeps/compiler-calls.rs

index cc68b44ac12698c3f97e3b30951820b0d3e16077..cd664b7388cd877c9bdb7e0e500ccef519963c8d 100644 (file)
@@ -36,8 +36,8 @@
 use getopts;
 use std::collections::HashMap;
 use std::collections::hash_map::Entry::{Occupied, Vacant};
+use std::env;
 use std::fmt;
-use std::os;
 
 use llvm;
 
index 042718b4412e53b95c40b81aa051636ef1433490..d82c160fdee9b543fc65d58fa75960c7631daf86 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -27,6 +27,7 @@
 use rustc_trans::trans;
 use rustc_typeck as typeck;
 use rustc_privacy;
+use super::Compilation;
 
 use serialize::json;
 
@@ -55,7 +56,7 @@ macro_rules! controller_entry_point{($point: ident, $make_state: expr) => ({
             let state = $make_state;
             (control.$point.callback)(state);
         }
-        if control.$point.stop {
+        if control.$point.stop == Compilation::Stop {
             return;
         }
     })}
@@ -206,14 +207,14 @@ pub fn basic() -> CompileController<'a> {
 }
 
 pub struct PhaseController<'a> {
-    pub stop: bool,
+    pub stop: Compilation,
     pub callback: Box<Fn(CompileState) -> () + 'a>,
 }
 
 impl<'a> PhaseController<'a> {
     pub fn basic() -> PhaseController<'a> {
         PhaseController {
-            stop: false,
+            stop: Compilation::Continue,
             callback: box |_| {},
         }
     }
index 0337f9f8591bfb51818d965e23aef81b9a955f09..0c936698e6d9aaaf71501d7948706b172f7e9394 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -108,8 +108,9 @@ pub fn run(args: Vec<String>) -> int {
 pub fn run_compiler<'a>(args: &[String],
                         callbacks: &mut CompilerCalls<'a>) {
     macro_rules! do_or_return {($expr: expr) => {
-        if $expr {
-            return;
+        match $expr {
+            Compilation::Stop => return,
+            Compilation::Continue => {}
         }
     }}
 
@@ -144,7 +145,7 @@ macro_rules! do_or_return {($expr: expr) => {
     // It is somewhat unfortunate that this is hardwired in - this is forced by
     // the fact that pretty_print_input requires the session by value.
     let pretty = callbacks.parse_pretty(&sess, &matches);
-        match pretty.into_iter().next() {
+    match pretty {
         Some((ppm, opt_uii)) => {
             pretty::pretty_print_input(sess, cfg, &input, ppm, opt_uii, ofile);
             return;
@@ -180,26 +181,43 @@ fn make_input(free_matches: &[String]) -> Option<(Input, Option<Path>)> {
     }
 }
 
+// Whether to stop or continue compilation.
+#[derive(Copy, Debug, Eq, PartialEq)]
+pub enum Compilation {
+    Stop,
+    Continue,
+}
+
+impl Compilation {
+    pub fn and_then<F: FnOnce() -> Compilation>(self, next: F) -> Compilation {
+        match self {
+            Compilation::Stop => Compilation::Stop,
+            Compilation::Continue => next()
+        }
+    }
+}
+
 // A trait for customising the compilation process. Offers a number of hooks for
 // executing custom code or customising input.
 pub trait CompilerCalls<'a> {
     // Hook for a callback early in the process of handling arguments. This will
     // be called straight after options have been parsed but before anything
-    // else (e.g., selecting input and output). Return true to terminate compilation,
-    // false to continue.
-    fn early_callback(&mut self, &getopts::Matches, &diagnostics::registry::Registry) -> bool;
+    // else (e.g., selecting input and output).
+    fn early_callback(&mut self,
+                      &getopts::Matches,
+                      &diagnostics::registry::Registry)
+                      -> Compilation;
 
     // Hook for a callback late in the process of handling arguments. This will
     // be called just before actual compilation starts (and before build_controller
-    // is called), after all arguments etc. have been completely handled. Return
-    // true to terminate compilation, false to continue.
+    // is called), after all arguments etc. have been completely handled.
     fn late_callback(&mut self,
                      &getopts::Matches,
                      &Session,
                      &Input,
                      &Option<Path>,
                      &Option<Path>)
-                     -> bool;
+                     -> Compilation;
 
     // Called after we extract the input from the arguments. Gives the implementer
     // an opportunity to change the inputs or to add some custom input handling.
@@ -253,7 +271,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
     fn early_callback(&mut self,
                       matches: &getopts::Matches,
                       descriptions: &diagnostics::registry::Registry)
-                      -> bool {
+                      -> Compilation {
         match matches.opt_str("explain") {
             Some(ref code) => {
                 match descriptions.find_description(&code[]) {
@@ -264,12 +282,12 @@ fn early_callback(&mut self,
                         early_error(&format!("no extended information for {}", code)[]);
                     }
                 }
-                return true;
+                return Compilation::Stop;
             },
             None => ()
         }
 
-        return false;
+        return Compilation::Continue;
     }
 
     fn no_input(&mut self,
@@ -288,7 +306,8 @@ fn no_input(&mut self,
                     return None;
                 }
                 let sess = build_session(sopts.clone(), None, descriptions.clone());
-                if RustcDefaultCalls::print_crate_info(&sess, None, odir, ofile) {
+                let should_stop = RustcDefaultCalls::print_crate_info(&sess, None, odir, ofile);
+                if should_stop == Compilation::Stop {
                     return None;
                 }
                 early_error("no input filename given");
@@ -328,9 +347,9 @@ fn late_callback(&mut self,
                      input: &Input,
                      odir: &Option<Path>,
                      ofile: &Option<Path>)
-                     -> bool {
-        RustcDefaultCalls::print_crate_info(sess, Some(input), odir, ofile) ||
-            RustcDefaultCalls::list_metadata(sess, matches, input)
+                     -> Compilation {
+        RustcDefaultCalls::print_crate_info(sess, Some(input), odir, ofile).and_then(
+            || RustcDefaultCalls::list_metadata(sess, matches, input))
     }
 
     fn build_controller(&mut self, sess: &Session) -> CompileController<'a> {
@@ -339,19 +358,19 @@ fn build_controller(&mut self, sess: &Session) -> CompileController<'a> {
         if sess.opts.parse_only ||
            sess.opts.show_span.is_some() ||
            sess.opts.debugging_opts.ast_json_noexpand {
-            control.after_parse.stop = true;
+            control.after_parse.stop = Compilation::Stop;
         }
 
         if sess.opts.no_analysis || sess.opts.debugging_opts.ast_json {
-            control.after_write_deps.stop = true;
+            control.after_write_deps.stop = Compilation::Stop;
         }
 
         if sess.opts.no_trans {
-            control.after_analysis.stop = true;
+            control.after_analysis.stop = Compilation::Stop;
         }
 
         if !sess.opts.output_types.iter().any(|&i| i == config::OutputTypeExe) {
-            control.after_llvm.stop = true;
+            control.after_llvm.stop = Compilation::Stop;
         }
 
         if sess.opts.debugging_opts.save_analysis {
@@ -373,7 +392,7 @@ impl RustcDefaultCalls {
     pub fn list_metadata(sess: &Session,
                          matches: &getopts::Matches,
                          input: &Input)
-                         -> bool {
+                         -> Compilation {
         let r = matches.opt_strs("Z");
         if r.contains(&("ls".to_string())) {
             match input {
@@ -388,10 +407,10 @@ pub fn list_metadata(sess: &Session,
                     early_error("cannot list metadata for stdin");
                 }
             }
-            return true;
+            return Compilation::Stop;
         }
 
-        return false;
+        return Compilation::Continue;
     }
 
 
@@ -399,9 +418,9 @@ fn print_crate_info(sess: &Session,
                         input: Option<&Input>,
                         odir: &Option<Path>,
                         ofile: &Option<Path>)
-                        -> bool {
+                        -> Compilation {
         if sess.opts.prints.len() == 0 {
-            return false
+            return Compilation::Continue;
         }
 
         let attrs = input.map(|input| parse_crate_attrs(sess, input));
@@ -440,7 +459,7 @@ fn print_crate_info(sess: &Session,
                 }
             }
         }
-        return true;
+        return Compilation::Stop;
     }
 }
 
index 51beb7fc7165b3ed8acdfc93de2fea4fbf1cdd3b..e43c3a6da3ac70893479bb7bbcb86698eae4b32e 100644 (file)
@@ -23,7 +23,7 @@
 use rustc::session::{self, config};
 use rustc::session::config::get_unstable_features_setting;
 use rustc::session::search_paths::{SearchPaths, PathKind};
-use rustc_driver::driver;
+use rustc_driver::{driver, Compilation};
 use syntax::ast;
 use syntax::codemap::{CodeMap, dummy_spanned};
 use syntax::diagnostic;
@@ -178,7 +178,7 @@ fn runtest(test: &str, cratename: &str, libs: SearchPaths,
     let libdir = sess.target_filesearch(PathKind::All).get_lib_path();
     let mut control = driver::CompileController::basic();
     if no_run {
-        control.after_analysis.stop = true;
+        control.after_analysis.stop = Compilation::Stop;
     }
     driver::compile_input(sess, cfg, &input, &out, &None, None, control);
 
index 6021c9bccea0ae8609c27a24da473ef3097dd273..9e164522d77a60db51fd8c6e693eecb7587b36a2 100644 (file)
@@ -10,6 +10,8 @@
 
 // Test that the CompilerCalls interface to the compiler works.
 
+// ignore-android
+
 #![feature(rustc_private)]
 #![feature(core)]
 
@@ -20,7 +22,7 @@
 
 use rustc::session::Session;
 use rustc::session::config::{self, Input};
-use rustc_driver::{driver, CompilerCalls};
+use rustc_driver::{driver, CompilerCalls, Compilation};
 use syntax::diagnostics;
 
 
@@ -32,9 +34,9 @@ impl<'a> CompilerCalls<'a> for TestCalls {
     fn early_callback(&mut self,
                       _: &getopts::Matches,
                       _: &diagnostics::registry::Registry)
-                      -> bool {
+                      -> Compilation {
         self.count *= 2;
-        false
+        Compilation::Continue
     }
 
     fn late_callback(&mut self,
@@ -43,9 +45,9 @@ fn late_callback(&mut self,
                      _: &Input,
                      _: &Option<Path>,
                      _: &Option<Path>)
-                     -> bool {
+                     -> Compilation {
         self.count *= 3;
-        true
+        Compilation::Stop
     }
 
     fn some_input(&mut self, input: Input, input_path: Option<Path>) -> (Input, Option<Path>) {