Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d76bf3ed
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,发现更多精彩内容 >>
提交
d76bf3ed
编写于
9月 07, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Strip unconfigured nodes in the `InvocationCollector` fold.
上级
3af0c657
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
67 addition
and
19 deletion
+67
-19
src/libsyntax/config.rs
src/libsyntax/config.rs
+6
-6
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+60
-13
src/libsyntax/lib.rs
src/libsyntax/lib.rs
+1
-0
未找到文件。
src/libsyntax/config.rs
浏览文件 @
d76bf3ed
...
...
@@ -70,7 +70,7 @@ pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool)
}
impl
<
'a
>
StripUnconfigured
<
'a
>
{
fn
configure
<
T
:
HasAttrs
>
(
&
mut
self
,
node
:
T
)
->
Option
<
T
>
{
pub
fn
configure
<
T
:
HasAttrs
>
(
&
mut
self
,
node
:
T
)
->
Option
<
T
>
{
let
node
=
self
.process_cfg_attrs
(
node
);
if
self
.in_cfg
(
node
.attrs
())
{
Some
(
node
)
}
else
{
None
}
}
...
...
@@ -166,7 +166,7 @@ fn visit_stmt_or_expr_attrs(&mut self, attrs: &[ast::Attribute]) {
}
}
fn
configure_foreign_mod
(
&
mut
self
,
foreign_mod
:
ast
::
ForeignMod
)
->
ast
::
ForeignMod
{
pub
fn
configure_foreign_mod
(
&
mut
self
,
foreign_mod
:
ast
::
ForeignMod
)
->
ast
::
ForeignMod
{
ast
::
ForeignMod
{
abi
:
foreign_mod
.abi
,
items
:
foreign_mod
.items
.into_iter
()
.filter_map
(|
item
|
self
.configure
(
item
))
.collect
(),
...
...
@@ -187,7 +187,7 @@ fn configure_variant_data(&mut self, vdata: ast::VariantData) -> ast::VariantDat
}
}
fn
configure_item_kind
(
&
mut
self
,
item
:
ast
::
ItemKind
)
->
ast
::
ItemKind
{
pub
fn
configure_item_kind
(
&
mut
self
,
item
:
ast
::
ItemKind
)
->
ast
::
ItemKind
{
match
item
{
ast
::
ItemKind
::
Struct
(
def
,
generics
)
=>
{
ast
::
ItemKind
::
Struct
(
self
.configure_variant_data
(
def
),
generics
)
...
...
@@ -217,7 +217,7 @@ fn configure_item_kind(&mut self, item: ast::ItemKind) -> ast::ItemKind {
}
}
fn
configure_expr_kind
(
&
mut
self
,
expr_kind
:
ast
::
ExprKind
)
->
ast
::
ExprKind
{
pub
fn
configure_expr_kind
(
&
mut
self
,
expr_kind
:
ast
::
ExprKind
)
->
ast
::
ExprKind
{
if
let
ast
::
ExprKind
::
Match
(
m
,
arms
)
=
expr_kind
{
let
arms
=
arms
.into_iter
()
.filter_map
(|
a
|
self
.configure
(
a
))
.collect
();
ast
::
ExprKind
::
Match
(
m
,
arms
)
...
...
@@ -226,7 +226,7 @@ fn configure_expr_kind(&mut self, expr_kind: ast::ExprKind) -> ast::ExprKind {
}
}
fn
configure_expr
(
&
mut
self
,
expr
:
P
<
ast
::
Expr
>
)
->
P
<
ast
::
Expr
>
{
pub
fn
configure_expr
(
&
mut
self
,
expr
:
P
<
ast
::
Expr
>
)
->
P
<
ast
::
Expr
>
{
self
.visit_stmt_or_expr_attrs
(
expr
.attrs
());
// If an expr is valid to cfg away it will have been removed by the
...
...
@@ -244,7 +244,7 @@ fn configure_expr(&mut self, expr: P<ast::Expr>) -> P<ast::Expr> {
self
.process_cfg_attrs
(
expr
)
}
fn
configure_stmt
(
&
mut
self
,
stmt
:
ast
::
Stmt
)
->
Option
<
ast
::
Stmt
>
{
pub
fn
configure_stmt
(
&
mut
self
,
stmt
:
ast
::
Stmt
)
->
Option
<
ast
::
Stmt
>
{
self
.visit_stmt_or_expr_attrs
(
stmt
.attrs
());
self
.configure
(
stmt
)
}
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
d76bf3ed
...
...
@@ -208,14 +208,23 @@ fn expand(&mut self, expansion: Expansion) -> Expansion {
}
fn
collect_invocations
(
&
mut
self
,
expansion
:
Expansion
)
->
(
Expansion
,
Vec
<
Invocation
>
)
{
let
expansion
=
expansion
.fold_with
(
&
mut
StripUnconfigured
{
config
:
&
self
.cx.cfg
,
should_test
:
self
.cx.ecfg.should_test
,
sess
:
self
.cx.parse_sess
,
features
:
self
.cx.ecfg.features
,
});
let
mut
collector
=
InvocationCollector
{
cx
:
self
.cx
,
invocations
:
Vec
::
new
()
};
(
expansion
.fold_with
(
&
mut
collector
),
collector
.invocations
)
let
crate_config
=
mem
::
replace
(
&
mut
self
.cx.cfg
,
Vec
::
new
());
let
result
=
{
let
mut
collector
=
InvocationCollector
{
cfg
:
StripUnconfigured
{
config
:
&
crate_config
,
should_test
:
self
.cx.ecfg.should_test
,
sess
:
self
.cx.parse_sess
,
features
:
self
.cx.ecfg.features
,
},
cx
:
self
.cx
,
invocations
:
Vec
::
new
(),
};
(
expansion
.fold_with
(
&
mut
collector
),
collector
.invocations
)
};
self
.cx.cfg
=
crate_config
;
result
}
fn
expand_invoc
(
&
mut
self
,
invoc
:
Invocation
)
->
Expansion
{
...
...
@@ -403,9 +412,19 @@ fn expand_bang_invoc(&mut self, invoc: Invocation) -> Expansion {
struct
InvocationCollector
<
'a
,
'b
:
'a
>
{
cx
:
&
'a
mut
ExtCtxt
<
'b
>
,
cfg
:
StripUnconfigured
<
'a
>
,
invocations
:
Vec
<
Invocation
>
,
}
macro_rules!
fully_configure
{
(
$this:ident
,
$node:ident
,
$noop_fold:ident
)
=>
{
match
$noop_fold
(
$node
,
&
mut
$this
.cfg
)
.pop
()
{
Some
(
node
)
=>
node
,
None
=>
return
SmallVector
::
zero
(),
}
}
}
impl
<
'a
,
'b
>
InvocationCollector
<
'a
,
'b
>
{
fn
collect
(
&
mut
self
,
expansion_kind
:
ExpansionKind
,
kind
:
InvocationKind
)
->
Expansion
{
let
mark
=
Mark
::
fresh
();
...
...
@@ -475,11 +494,17 @@ fn contains_macro_use(&mut self, attrs: &[ast::Attribute]) -> bool {
}
false
}
fn
configure
<
T
:
HasAttrs
>
(
&
mut
self
,
node
:
T
)
->
Option
<
T
>
{
self
.cfg
.configure
(
node
)
}
}
impl
<
'a
,
'b
>
Folder
for
InvocationCollector
<
'a
,
'b
>
{
fn
fold_expr
(
&
mut
self
,
expr
:
P
<
ast
::
Expr
>
)
->
P
<
ast
::
Expr
>
{
let
expr
=
expr
.unwrap
();
let
mut
expr
=
self
.cfg
.configure_expr
(
expr
)
.unwrap
();
expr
.node
=
self
.cfg
.configure_expr_kind
(
expr
.node
);
if
let
ast
::
ExprKind
::
Mac
(
mac
)
=
expr
.node
{
self
.collect_bang
(
mac
,
expr
.attrs
.into
(),
expr
.span
,
ExpansionKind
::
Expr
)
.make_expr
()
}
else
{
...
...
@@ -488,7 +513,9 @@ fn fold_expr(&mut self, expr: P<ast::Expr>) -> P<ast::Expr> {
}
fn
fold_opt_expr
(
&
mut
self
,
expr
:
P
<
ast
::
Expr
>
)
->
Option
<
P
<
ast
::
Expr
>>
{
let
expr
=
expr
.unwrap
();
let
mut
expr
=
configure!
(
self
,
expr
)
.unwrap
();
expr
.node
=
self
.cfg
.configure_expr_kind
(
expr
.node
);
if
let
ast
::
ExprKind
::
Mac
(
mac
)
=
expr
.node
{
self
.collect_bang
(
mac
,
expr
.attrs
.into
(),
expr
.span
,
ExpansionKind
::
OptExpr
)
.make_opt_expr
()
...
...
@@ -511,6 +538,11 @@ fn fold_pat(&mut self, pat: P<ast::Pat>) -> P<ast::Pat> {
}
fn
fold_stmt
(
&
mut
self
,
stmt
:
ast
::
Stmt
)
->
SmallVector
<
ast
::
Stmt
>
{
let
stmt
=
match
self
.cfg
.configure_stmt
(
stmt
)
{
Some
(
stmt
)
=>
stmt
,
None
=>
return
SmallVector
::
zero
(),
};
let
(
mac
,
style
,
attrs
)
=
match
stmt
.node
{
StmtKind
::
Mac
(
mac
)
=>
mac
.unwrap
(),
_
=>
return
noop_fold_stmt
(
stmt
,
self
),
...
...
@@ -540,9 +572,11 @@ fn fold_block(&mut self, block: P<Block>) -> P<Block> {
}
fn
fold_item
(
&
mut
self
,
item
:
P
<
ast
::
Item
>
)
->
SmallVector
<
P
<
ast
::
Item
>>
{
let
item
=
configure!
(
self
,
item
);
let
(
item
,
attr
)
=
self
.classify_item
(
item
);
if
let
Some
(
attr
)
=
attr
{
let
item
=
Annotatable
::
Item
(
item
);
let
item
=
Annotatable
::
Item
(
fully_configure!
(
self
,
item
,
noop_fold_item
)
);
return
self
.collect_attr
(
attr
,
item
,
ExpansionKind
::
Items
)
.make_items
();
}
...
...
@@ -610,9 +644,12 @@ fn fold_item(&mut self, item: P<ast::Item>) -> SmallVector<P<ast::Item>> {
}
fn
fold_trait_item
(
&
mut
self
,
item
:
ast
::
TraitItem
)
->
SmallVector
<
ast
::
TraitItem
>
{
let
item
=
configure!
(
self
,
item
);
let
(
item
,
attr
)
=
self
.classify_item
(
item
);
if
let
Some
(
attr
)
=
attr
{
let
item
=
Annotatable
::
TraitItem
(
P
(
item
));
let
item
=
Annotatable
::
TraitItem
(
P
(
fully_configure!
(
self
,
item
,
noop_fold_trait_item
)));
return
self
.collect_attr
(
attr
,
item
,
ExpansionKind
::
TraitItems
)
.make_trait_items
()
}
...
...
@@ -626,9 +663,11 @@ fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVector<ast::TraitIte
}
fn
fold_impl_item
(
&
mut
self
,
item
:
ast
::
ImplItem
)
->
SmallVector
<
ast
::
ImplItem
>
{
let
item
=
configure!
(
self
,
item
);
let
(
item
,
attr
)
=
self
.classify_item
(
item
);
if
let
Some
(
attr
)
=
attr
{
let
item
=
Annotatable
::
ImplItem
(
P
(
item
));
let
item
=
Annotatable
::
ImplItem
(
P
(
fully_configure!
(
self
,
item
,
noop_fold_impl_item
)
));
return
self
.collect_attr
(
attr
,
item
,
ExpansionKind
::
ImplItems
)
.make_impl_items
();
}
...
...
@@ -653,6 +692,14 @@ fn fold_ty(&mut self, ty: P<ast::Ty>) -> P<ast::Ty> {
_
=>
unreachable!
(),
}
}
fn
fold_foreign_mod
(
&
mut
self
,
foreign_mod
:
ast
::
ForeignMod
)
->
ast
::
ForeignMod
{
noop_fold_foreign_mod
(
self
.cfg
.configure_foreign_mod
(
foreign_mod
),
self
)
}
fn
fold_item_kind
(
&
mut
self
,
item
:
ast
::
ItemKind
)
->
ast
::
ItemKind
{
noop_fold_item_kind
(
self
.cfg
.configure_item_kind
(
item
),
self
)
}
}
pub
struct
ExpansionConfig
<
'feat
>
{
...
...
src/libsyntax/lib.rs
浏览文件 @
d76bf3ed
...
...
@@ -104,6 +104,7 @@ pub mod syntax {
pub
mod
ast
;
pub
mod
attr
;
pub
mod
codemap
;
#[macro_use]
pub
mod
config
;
pub
mod
entry
;
pub
mod
feature_gate
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录