1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use syntax::ast::Crate;
use crate::command::{Command, CommandState, RefactorState, Registry};
use crate::driver::Phase;
use crate::RefactorCtxt;
pub trait Transform {
fn transform(&self, krate: &mut Crate, st: &CommandState, cx: &RefactorCtxt);
fn min_phase(&self) -> Phase {
Phase::Phase2
}
}
pub struct TransformCommand<T: Transform>(pub T);
impl<T: Transform> Command for TransformCommand<T> {
fn run(&mut self, state: &mut RefactorState) {
state
.transform_crate(self.0.min_phase(), |st, cx| {
self.0.transform(&mut *st.krate_mut(), st, cx)
})
.expect("Failed to run compiler");
}
}
fn mk<T: Transform + 'static>(t: T) -> Box<Command> {
Box::new(TransformCommand(t))
}
macro_rules! transform_modules {
($($name:ident,)*) => {
$( pub mod $name; )*
pub fn register_commands(reg: &mut Registry) {
$( $name::register_commands(reg); )*
}
};
}
transform_modules! {
canonicalize_refs,
char_literals,
control_flow,
externs,
format,
funcs,
generics,
ionize,
items,
linkage,
literals,
reorganize_definitions,
ownership,
retype,
rewrite,
statics,
structs,
test,
vars,
wrapping_arith,
}