]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass-fulldeps/compiler-calls.rs
New upstream version 1.22.1+dfsg1
[rustc.git] / src / test / run-pass-fulldeps / compiler-calls.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Test that the CompilerCalls interface to the compiler works.
12
13 // ignore-cross-compile
14
15 #![feature(rustc_private, path)]
16 #![feature(core)]
17
18 extern crate getopts;
19 extern crate rustc;
20 extern crate rustc_driver;
21 extern crate syntax;
22 extern crate rustc_errors as errors;
23
24 use rustc::middle::cstore::CrateStore;
25 use rustc::session::Session;
26 use rustc::session::config::{self, Input};
27 use rustc_driver::{driver, CompilerCalls, Compilation};
28 use syntax::ast;
29
30 use std::path::PathBuf;
31
32 struct TestCalls {
33 count: u32
34 }
35
36 impl<'a> CompilerCalls<'a> for TestCalls {
37 fn early_callback(&mut self,
38 _: &getopts::Matches,
39 _: &config::Options,
40 _: &ast::CrateConfig,
41 _: &errors::registry::Registry,
42 _: config::ErrorOutputType)
43 -> Compilation {
44 self.count *= 2;
45 Compilation::Continue
46 }
47
48 fn late_callback(&mut self,
49 _: &getopts::Matches,
50 _: &Session,
51 _: &CrateStore,
52 _: &Input,
53 _: &Option<PathBuf>,
54 _: &Option<PathBuf>)
55 -> Compilation {
56 self.count *= 3;
57 Compilation::Stop
58 }
59
60 fn some_input(&mut self, input: Input, input_path: Option<PathBuf>)
61 -> (Input, Option<PathBuf>) {
62 self.count *= 5;
63 (input, input_path)
64 }
65
66 fn no_input(&mut self,
67 _: &getopts::Matches,
68 _: &config::Options,
69 _: &ast::CrateConfig,
70 _: &Option<PathBuf>,
71 _: &Option<PathBuf>,
72 _: &errors::registry::Registry)
73 -> Option<(Input, Option<PathBuf>)> {
74 panic!("This shouldn't happen");
75 }
76
77 fn build_controller(&mut self,
78 _: &Session,
79 _: &getopts::Matches)
80 -> driver::CompileController<'a> {
81 panic!("This shouldn't be called");
82 }
83 }
84
85
86 fn main() {
87 let mut tc = TestCalls { count: 1 };
88 // we should never get use this filename, but lets make sure they are valid args.
89 let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()];
90 rustc_driver::run_compiler(&args, &mut tc, None, None);
91 assert_eq!(tc.count, 30);
92 }