Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
399da7bc
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,发现更多精彩内容 >>
提交
399da7bc
编写于
6月 23, 2018
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
expansion: Improve searchability for `AstFragments` methods
上级
a1272646
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
65 addition
and
48 deletion
+65
-48
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+60
-44
src/libsyntax/lib.rs
src/libsyntax/lib.rs
+5
-4
未找到文件。
src/libsyntax/ext/expand.rs
浏览文件 @
399da7bc
...
@@ -41,22 +41,33 @@
...
@@ -41,22 +41,33 @@
use
std
::
path
::
PathBuf
;
use
std
::
path
::
PathBuf
;
macro_rules!
ast_fragments
{
macro_rules!
ast_fragments
{
(
$
(
$kind:ident
:
$ty:ty
[
$
(
$vec:ident
,
$ty_elt:ty
)
*
],
$kind_name:expr
,
.
$make:ident
,
(
$
(
.
$fold:ident
)
*
$
(
lift
.
$fold_elt:ident
)
*
,
$
(
$Kind:ident
(
$AstTy:ty
)
{
$
(
.
$visit:ident
)
*
$
(
lift
.
$visit_elt:ident
)
*
;)
*
)
=>
{
$kind_name:expr
;
$
(
one
fn
$fold_ast:ident
;
fn
$visit_ast:ident
;)
?
$
(
many
fn
$fold_ast_elt:ident
;
fn
$visit_ast_elt:ident
;)
?
fn
$make_ast:ident
;
})
*
)
=>
{
/// A fragment of AST that can be produced by a single macro expansion.
/// A fragment of AST that can be produced by a single macro expansion.
/// Can also serve as an input and intermediate result for macro expansion operations.
/// Can also serve as an input and intermediate result for macro expansion operations.
pub
enum
AstFragment
{
OptExpr
(
Option
<
P
<
ast
::
Expr
>>
),
$
(
$kind
(
$ty
),
)
*
}
pub
enum
AstFragment
{
OptExpr
(
Option
<
P
<
ast
::
Expr
>>
),
$
(
$Kind
(
$AstTy
),)
*
}
/// "Discriminant" of an AST fragment.
/// "Discriminant" of an AST fragment.
#[derive(Copy,
Clone,
PartialEq,
Eq)]
#[derive(Copy,
Clone,
PartialEq,
Eq)]
pub
enum
AstFragmentKind
{
OptExpr
,
$
(
$kind
,
)
*
}
pub
enum
AstFragmentKind
{
OptExpr
,
$
(
$Kind
,)
*
}
impl
AstFragmentKind
{
impl
AstFragmentKind
{
pub
fn
name
(
self
)
->
&
'static
str
{
pub
fn
name
(
self
)
->
&
'static
str
{
match
self
{
match
self
{
AstFragmentKind
::
OptExpr
=>
"expression"
,
AstFragmentKind
::
OptExpr
=>
"expression"
,
$
(
AstFragmentKind
::
$kind
=>
$kind_name
,
)
*
$
(
AstFragmentKind
::
$Kind
=>
$kind_name
,
)
*
}
}
}
}
...
@@ -64,7 +75,7 @@ fn make_from<'a>(self, result: Box<MacResult + 'a>) -> Option<AstFragment> {
...
@@ -64,7 +75,7 @@ fn make_from<'a>(self, result: Box<MacResult + 'a>) -> Option<AstFragment> {
match
self
{
match
self
{
AstFragmentKind
::
OptExpr
=>
AstFragmentKind
::
OptExpr
=>
result
.make_expr
()
.map
(
Some
)
.map
(
AstFragment
::
OptExpr
),
result
.make_expr
()
.map
(
Some
)
.map
(
AstFragment
::
OptExpr
),
$
(
AstFragmentKind
::
$kind
=>
result
.
$make
()
.map
(
AstFragment
::
$kind
),
)
*
$
(
AstFragmentKind
::
$Kind
=>
result
.
$make_ast
()
.map
(
AstFragment
::
$Kind
),
)
*
}
}
}
}
}
}
...
@@ -76,21 +87,24 @@ pub fn make_opt_expr(self) -> Option<P<ast::Expr>> {
...
@@ -76,21 +87,24 @@ pub fn make_opt_expr(self) -> Option<P<ast::Expr>> {
_
=>
panic!
(
"AstFragment::make_* called on the wrong kind of fragment"
),
_
=>
panic!
(
"AstFragment::make_* called on the wrong kind of fragment"
),
}
}
}
}
$
(
pub
fn
$make
(
self
)
->
$ty
{
$
(
pub
fn
$make_ast
(
self
)
->
$AstTy
{
match
self
{
match
self
{
AstFragment
::
$
k
ind
(
ast
)
=>
ast
,
AstFragment
::
$
K
ind
(
ast
)
=>
ast
,
_
=>
panic!
(
"AstFragment::make_* called on the wrong kind of fragment"
),
_
=>
panic!
(
"AstFragment::make_* called on the wrong kind of fragment"
),
}
}
}
)
*
})
*
pub
fn
fold_with
<
F
:
Folder
>
(
self
,
folder
:
&
mut
F
)
->
Self
{
pub
fn
fold_with
<
F
:
Folder
>
(
self
,
folder
:
&
mut
F
)
->
Self
{
use
self
::
AstFragment
::
*
;
match
self
{
match
self
{
OptExpr
(
expr
)
=>
OptExpr
(
expr
.and_then
(|
expr
|
folder
.fold_opt_expr
(
expr
))),
AstFragment
::
OptExpr
(
expr
)
=>
$
(
$
(
$kind
(
ast
)
=>
$kind
(
folder
.
$fold
(
ast
)),
)
*
)
*
AstFragment
::
OptExpr
(
expr
.and_then
(|
expr
|
folder
.fold_opt_expr
(
expr
))),
$
(
$
(
$kind
(
ast
)
=>
{
$
(
$
(
AstFragment
::
$Kind
(
ast
)
=>
$kind
(
ast
.into_iter
()
.flat_map
(|
ast
|
folder
.
$fold_elt
(
ast
))
.collect
())
AstFragment
::
$Kind
(
folder
.
$fold_ast
(
ast
)),)
?
)
*
},
)
*
)
*
$
(
$
(
AstFragment
::
$Kind
(
ast
)
=>
AstFragment
::
$Kind
(
ast
.into_iter
()
.flat_map
(|
ast
|
folder
.
$fold_ast_elt
(
ast
))
.collect
()),)
?
)
*
}
}
}
}
...
@@ -98,48 +112,50 @@ pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) {
...
@@ -98,48 +112,50 @@ pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) {
match
*
self
{
match
*
self
{
AstFragment
::
OptExpr
(
Some
(
ref
expr
))
=>
visitor
.visit_expr
(
expr
),
AstFragment
::
OptExpr
(
Some
(
ref
expr
))
=>
visitor
.visit_expr
(
expr
),
AstFragment
::
OptExpr
(
None
)
=>
{}
AstFragment
::
OptExpr
(
None
)
=>
{}
$
(
$
(
AstFragment
::
$kind
(
ref
ast
)
=>
visitor
.
$visit
(
ast
),
)
*
)
*
$
(
$
(
AstFragment
::
$Kind
(
ref
ast
)
=>
visitor
.
$visit_ast
(
ast
),)
?
)
*
$
(
$
(
AstFragment
::
$kind
(
ref
ast
)
=>
for
as
t
in
&
ast
[
..
]
{
$
(
$
(
AstFragment
::
$Kind
(
ref
ast
)
=>
for
ast_el
t
in
&
ast
[
..
]
{
visitor
.
$visit_
elt
(
as
t
);
visitor
.
$visit_
ast_elt
(
ast_el
t
);
}
,
)
*
)
*
}
)
?
)
*
}
}
}
}
}
}
impl
<
'a
,
'b
>
Folder
for
MacroExpander
<
'a
,
'b
>
{
impl
<
'a
,
'b
>
Folder
for
MacroExpander
<
'a
,
'b
>
{
fn
fold_opt_expr
(
&
mut
self
,
expr
:
P
<
ast
::
Expr
>
)
->
Option
<
P
<
ast
::
Expr
>>
{
fn
fold_opt_expr
(
&
mut
self
,
expr
:
P
<
ast
::
Expr
>
)
->
Option
<
P
<
ast
::
Expr
>>
{
self
.expand
(
AstFragment
::
OptExpr
(
Some
(
expr
)))
.make_opt_expr
()
self
.expand
_fragment
(
AstFragment
::
OptExpr
(
Some
(
expr
)))
.make_opt_expr
()
}
}
$
(
$
(
fn
$fold
(
&
mut
self
,
node
:
$ty
)
->
$t
y
{
$
(
$
(
fn
$fold
_ast
(
&
mut
self
,
ast
:
$AstTy
)
->
$AstT
y
{
self
.expand
(
AstFragment
::
$kind
(
node
))
.
$make
()
self
.expand
_fragment
(
AstFragment
::
$Kind
(
ast
))
.
$make_ast
()
})
*
)
*
})
?
)
*
$
(
$
(
fn
$fold_
elt
(
&
mut
self
,
node
:
$ty_elt
)
->
$t
y
{
$
(
$
(
fn
$fold_
ast_elt
(
&
mut
self
,
ast_elt
:
<
$AstTy
as
IntoIterator
>
::
Item
)
->
$AstT
y
{
self
.expand
(
AstFragment
::
$kind
(
SmallVector
::
one
(
node
)))
.
$make
()
self
.expand
_fragment
(
AstFragment
::
$Kind
(
SmallVector
::
one
(
ast_elt
)))
.
$make_ast
()
})
*
)
*
})
?
)
*
}
}
impl
<
'a
>
MacResult
for
::
ext
::
tt
::
macro_rules
::
ParserAnyMacro
<
'a
>
{
impl
<
'a
>
MacResult
for
::
ext
::
tt
::
macro_rules
::
ParserAnyMacro
<
'a
>
{
$
(
fn
$make
(
self
:
Box
<
::
ext
::
tt
::
macro_rules
::
ParserAnyMacro
<
'a
>>
)
->
Option
<
$ty
>
{
$
(
fn
$make_ast
(
self
:
Box
<
::
ext
::
tt
::
macro_rules
::
ParserAnyMacro
<
'a
>>
)
Some
(
self
.make
(
AstFragmentKind
::
$kind
)
.
$make
())
->
Option
<
$AstTy
>
{
Some
(
self
.make
(
AstFragmentKind
::
$Kind
)
.
$make_ast
())
})
*
})
*
}
}
}
}
}
}
ast_fragments!
{
ast_fragments!
{
Expr
:
P
<
ast
::
Expr
>
[],
"expression"
,
.make_expr
,
.fold_expr
,
.visit_expr
;
Expr
(
P
<
ast
::
Expr
>
)
{
"expression"
;
one
fn
fold_expr
;
fn
visit_expr
;
fn
make_expr
;
}
Pat
:
P
<
ast
::
Pat
>
[],
"pattern"
,
.make_pat
,
.fold_pat
,
.visit_pat
;
Pat
(
P
<
ast
::
Pat
>
)
{
"pattern"
;
one
fn
fold_pat
;
fn
visit_pat
;
fn
make_pat
;
}
Ty
:
P
<
ast
::
Ty
>
[],
"type"
,
.make_ty
,
.fold_ty
,
.visit_ty
;
Ty
(
P
<
ast
::
Ty
>
)
{
"type"
;
one
fn
fold_ty
;
fn
visit_ty
;
fn
make_ty
;
}
Stmts
:
SmallVector
<
ast
::
Stmt
>
[
SmallVector
,
ast
::
Stmt
],
Stmts
(
SmallVector
<
ast
::
Stmt
>
)
{
"statement"
;
many
fn
fold_stmt
;
fn
visit_stmt
;
fn
make_stmts
;
}
"statement"
,
.make_stmts
,
lift
.fold_stmt
,
lift
.visit_stmt
;
Items
(
SmallVector
<
P
<
ast
::
Item
>>
)
{
"item"
;
many
fn
fold_item
;
fn
visit_item
;
fn
make_items
;
}
Items
:
SmallVector
<
P
<
ast
::
Item
>>
[
SmallVector
,
P
<
ast
::
Item
>
],
TraitItems
(
SmallVector
<
ast
::
TraitItem
>
)
{
"item"
,
.make_items
,
lift
.fold_item
,
lift
.visit_item
;
"trait item"
;
many
fn
fold_trait_item
;
fn
visit_trait_item
;
fn
make_trait_items
;
TraitItems
:
SmallVector
<
ast
::
TraitItem
>
[
SmallVector
,
ast
::
TraitItem
],
}
"trait item"
,
.make_trait_items
,
lift
.fold_trait_item
,
lift
.visit_trait_item
;
ImplItems
(
SmallVector
<
ast
::
ImplItem
>
)
{
ImplItems
:
SmallVector
<
ast
::
ImplItem
>
[
SmallVector
,
ast
::
ImplItem
],
"impl item"
;
many
fn
fold_impl_item
;
fn
visit_impl_item
;
fn
make_impl_items
;
"impl item"
,
.make_impl_items
,
lift
.fold_impl_item
,
lift
.visit_impl_item
;
}
ForeignItems
:
SmallVector
<
ast
::
ForeignItem
>
[
SmallVector
,
ast
::
ForeignItem
],
ForeignItems
(
SmallVector
<
ast
::
ForeignItem
>
)
{
"foreign item"
,
.make_foreign_items
,
lift
.fold_foreign_item
,
lift
.visit_foreign_item
;
"foreign item"
;
many
fn
fold_foreign_item
;
fn
visit_foreign_item
;
fn
make_foreign_items
;
}
}
}
impl
AstFragmentKind
{
impl
AstFragmentKind
{
...
@@ -261,7 +277,7 @@ pub fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
...
@@ -261,7 +277,7 @@ pub fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
tokens
:
None
,
tokens
:
None
,
})));
})));
match
self
.expand
(
krate_item
)
.make_items
()
.pop
()
.map
(
P
::
into_inner
)
{
match
self
.expand
_fragment
(
krate_item
)
.make_items
()
.pop
()
.map
(
P
::
into_inner
)
{
Some
(
ast
::
Item
{
attrs
,
node
:
ast
::
ItemKind
::
Mod
(
module
),
..
})
=>
{
Some
(
ast
::
Item
{
attrs
,
node
:
ast
::
ItemKind
::
Mod
(
module
),
..
})
=>
{
krate
.attrs
=
attrs
;
krate
.attrs
=
attrs
;
krate
.module
=
module
;
krate
.module
=
module
;
...
@@ -281,7 +297,7 @@ pub fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
...
@@ -281,7 +297,7 @@ pub fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
}
}
// Fully expand all macro invocations in this AST fragment.
// Fully expand all macro invocations in this AST fragment.
fn
expand
(
&
mut
self
,
input_fragment
:
AstFragment
)
->
AstFragment
{
fn
expand
_fragment
(
&
mut
self
,
input_fragment
:
AstFragment
)
->
AstFragment
{
let
orig_expansion_data
=
self
.cx.current_expansion
.clone
();
let
orig_expansion_data
=
self
.cx.current_expansion
.clone
();
self
.cx.current_expansion.depth
=
0
;
self
.cx.current_expansion.depth
=
0
;
...
...
src/libsyntax/lib.rs
浏览文件 @
399da7bc
...
@@ -19,13 +19,14 @@
...
@@ -19,13 +19,14 @@
html_root_url
=
"https://doc.rust-lang.org/nightly/"
,
html_root_url
=
"https://doc.rust-lang.org/nightly/"
,
test(attr(deny(warnings))))]
test(attr(deny(warnings))))]
#![feature(unicode_internals)]
#![feature(rustc_diagnostic_macros)]
#![feature(slice_sort_by_cached_key)]
#![feature(const_atomic_usize_new)]
#![feature(const_atomic_usize_new)]
#![feature(crate_visibility_modifier)]
#![feature(macro_at_most_once_rep)]
#![feature(rustc_attrs)]
#![feature(rustc_attrs)]
#![feature(rustc_diagnostic_macros)]
#![feature(slice_sort_by_cached_key)]
#![feature(str_escape)]
#![feature(str_escape)]
#![feature(
crate_visibility_modifier
)]
#![feature(
unicode_internals
)]
#![recursion_limit=
"256"
]
#![recursion_limit=
"256"
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录