Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
4f45b061
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4f45b061
编写于
5月 17, 2018
作者:
B
bjorn3
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add AdHocCalls and pass self to build_controller as Box<Self>
上级
90f34b5f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
65 addition
and
34 deletion
+65
-34
src/librustc_driver/lib.rs
src/librustc_driver/lib.rs
+50
-22
src/test/run-pass-fulldeps/compiler-calls.rs
src/test/run-pass-fulldeps/compiler-calls.rs
+15
-12
未找到文件。
src/librustc_driver/lib.rs
浏览文件 @
4f45b061
...
...
@@ -454,7 +454,7 @@ fn GetModuleFileNameW(hModule: usize,
// See comments on CompilerCalls below for details about the callbacks argument.
// The FileLoader provides a way to load files from sources other than the file system.
pub
fn
run_compiler
<
'a
>
(
args
:
&
[
String
],
callbacks
:
&
mut
(
CompilerCalls
<
'a
>
+
sync
::
Send
)
,
callbacks
:
Box
<
CompilerCalls
<
'a
>
+
sync
::
Send
+
'a
>
,
file_loader
:
Option
<
Box
<
FileLoader
+
Send
+
Sync
+
'static
>>
,
emitter_dest
:
Option
<
Box
<
Write
+
Send
>>
)
->
(
CompileResult
,
Option
<
Session
>
)
...
...
@@ -478,7 +478,7 @@ fn run_compiler_with_pool<'a>(
matches
:
getopts
::
Matches
,
sopts
:
config
::
Options
,
cfg
:
ast
::
CrateConfig
,
callbacks
:
&
mut
(
CompilerCalls
<
'a
>
+
sync
::
Send
)
,
mut
callbacks
:
Box
<
CompilerCalls
<
'a
>
+
sync
::
Send
+
'a
>
,
file_loader
:
Option
<
Box
<
FileLoader
+
Send
+
Sync
+
'static
>>
,
emitter_dest
:
Option
<
Box
<
Write
+
Send
>>
)
->
(
CompileResult
,
Option
<
Session
>
)
{
...
...
@@ -642,12 +642,12 @@ pub fn and_then<F: FnOnce() -> Compilation>(self, next: F) -> Compilation {
}
}
// A trait for customising the compilation process. Offers a number of hooks for
// executing custom code or customising input.
//
/
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).
//
/
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).
fn
early_callback
(
&
mut
self
,
_
:
&
getopts
::
Matches
,
_
:
&
config
::
Options
,
...
...
@@ -658,9 +658,9 @@ fn early_callback(&mut self,
Compilation
::
Continue
}
// 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.
//
/
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.
fn
late_callback
(
&
mut
self
,
_
:
&
CodegenBackend
,
_
:
&
getopts
::
Matches
,
...
...
@@ -673,9 +673,9 @@ fn late_callback(&mut self,
Compilation
::
Continue
}
// 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.
// The default behaviour is to simply pass through the inputs.
//
/
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.
//
/
The default behaviour is to simply pass through the inputs.
fn
some_input
(
&
mut
self
,
input
:
Input
,
input_path
:
Option
<
PathBuf
>
)
...
...
@@ -683,11 +683,11 @@ fn some_input(&mut self,
(
input
,
input_path
)
}
// Called after we extract the input from the arguments if there is no valid
// input. Gives the implementer an opportunity to supply alternate input (by
// returning a Some value) or to add custom behaviour for this error such as
// emitting error messages. Returning None will cause compilation to stop
// at this point.
//
/
Called after we extract the input from the arguments if there is no valid
//
/
input. Gives the implementer an opportunity to supply alternate input (by
//
/
returning a Some value) or to add custom behaviour for this error such as
//
/
emitting error messages. Returning None will cause compilation to stop
//
/
at this point.
fn
no_input
(
&
mut
self
,
_
:
&
getopts
::
Matches
,
_
:
&
config
::
Options
,
...
...
@@ -701,13 +701,41 @@ fn no_input(&mut self,
// Create a CompilController struct for controlling the behaviour of
// compilation.
fn
build_controller
(
&
mut
self
,
_
:
&
Session
,
_
:
&
getopts
::
Matches
)
->
CompileController
<
'a
>
;
fn
build_controller
(
self
:
Box
<
Self
>
,
_
:
&
Session
,
_
:
&
getopts
::
Matches
)
->
CompileController
<
'a
>
;
}
// CompilerCalls instance for a regular rustc build.
//
/
CompilerCalls instance for a regular rustc build.
#[derive(Copy,
Clone)]
pub
struct
RustcDefaultCalls
;
/// CompilerCalls instance for quick access to the result of one compile phase.
pub
enum
AdHocCalls
<
'a
>
{
AfterAnalysis
(
Compilation
,
Box
<
Fn
(
&
mut
::
driver
::
CompileState
)
+
'a
>
)
}
impl
<
'a
>
CompilerCalls
<
'a
>
for
AdHocCalls
<
'a
>
{
fn
build_controller
(
self
:
Box
<
Self
>
,
_
:
&
Session
,
_
:
&
getopts
::
Matches
)
->
CompileController
<
'a
>
{
let
mut
control
=
CompileController
::
basic
();
match
*
self
{
AdHocCalls
::
AfterAnalysis
(
c
,
f
)
=>
{
control
.after_analysis.stop
=
c
;
control
.after_analysis.callback
=
f
;
}
}
control
}
}
// FIXME remove these and use winapi 0.3 instead
// Duplicates: bootstrap/compile.rs, librustc_errors/emitter.rs
#[cfg(unix)]
...
...
@@ -878,7 +906,7 @@ fn late_callback(&mut self,
.and_then
(||
RustcDefaultCalls
::
list_metadata
(
sess
,
cstore
,
matches
,
input
))
}
fn
build_controller
(
&
mut
self
,
fn
build_controller
(
self
:
Box
<
Self
>
,
sess
:
&
Session
,
matches
:
&
getopts
::
Matches
)
->
CompileController
<
'a
>
{
...
...
@@ -1693,7 +1721,7 @@ pub fn main() {
}))
.collect
::
<
Vec
<
_
>>
();
run_compiler
(
&
args
,
&
mut
RustcDefaultCalls
,
Box
::
new
(
RustcDefaultCalls
)
,
None
,
None
)
});
...
...
src/test/run-pass-fulldeps/compiler-calls.rs
浏览文件 @
4f45b061
...
...
@@ -31,11 +31,11 @@
use
std
::
path
::
PathBuf
;
struct
TestCalls
{
count
:
u32
struct
TestCalls
<
'a
>
{
count
:
&
'a
mut
u32
}
impl
<
'a
>
CompilerCalls
<
'a
>
for
TestCalls
{
impl
<
'a
>
CompilerCalls
<
'a
>
for
TestCalls
<
'a
>
{
fn
early_callback
(
&
mut
self
,
_
:
&
getopts
::
Matches
,
_
:
&
config
::
Options
,
...
...
@@ -43,7 +43,7 @@ fn early_callback(&mut self,
_
:
&
errors
::
registry
::
Registry
,
_
:
config
::
ErrorOutputType
)
->
Compilation
{
self
.count
*=
2
;
*
self
.count
*=
2
;
Compilation
::
Continue
}
...
...
@@ -56,13 +56,13 @@ fn late_callback(&mut self,
_
:
&
Option
<
PathBuf
>
,
_
:
&
Option
<
PathBuf
>
)
->
Compilation
{
self
.count
*=
3
;
*
self
.count
*=
3
;
Compilation
::
Stop
}
fn
some_input
(
&
mut
self
,
input
:
Input
,
input_path
:
Option
<
PathBuf
>
)
->
(
Input
,
Option
<
PathBuf
>
)
{
self
.count
*=
5
;
*
self
.count
*=
5
;
(
input
,
input_path
)
}
...
...
@@ -77,7 +77,7 @@ fn no_input(&mut self,
panic!
(
"This shouldn't happen"
);
}
fn
build_controller
(
&
mut
self
,
fn
build_controller
(
self
:
Box
<
Self
>
,
_
:
&
Session
,
_
:
&
getopts
::
Matches
)
->
driver
::
CompileController
<
'a
>
{
...
...
@@ -87,9 +87,12 @@ fn build_controller(&mut self,
fn
main
()
{
let
mut
tc
=
TestCalls
{
count
:
1
};
// we should never get use this filename, but lets make sure they are valid args.
let
args
=
vec!
[
"compiler-calls"
.to_string
(),
"foo.rs"
.to_string
()];
rustc_driver
::
run_compiler
(
&
args
,
&
mut
tc
,
None
,
None
);
assert_eq!
(
tc
.count
,
30
);
let
mut
count
=
1
;
{
let
tc
=
TestCalls
{
count
:
&
mut
count
};
// we should never get use this filename, but lets make sure they are valid args.
let
args
=
vec!
[
"compiler-calls"
.to_string
(),
"foo.rs"
.to_string
()];
rustc_driver
::
run_compiler
(
&
args
,
Box
::
new
(
tc
),
None
,
None
);
}
assert_eq!
(
count
,
30
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录