Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f126eacd
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,发现更多精彩内容 >>
提交
f126eacd
编写于
7月 04, 2014
作者:
J
John Clements
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
comments, whitespace, rename NameFinderContext to PatIdentFinder
上级
4358bf8b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
25 deletion
+27
-25
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+12
-6
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+15
-19
未找到文件。
src/libsyntax/ast.rs
浏览文件 @
f126eacd
...
@@ -453,10 +453,10 @@ pub enum Expr_ {
...
@@ -453,10 +453,10 @@ pub enum Expr_ {
ExprCast
(
Gc
<
Expr
>
,
P
<
Ty
>
),
ExprCast
(
Gc
<
Expr
>
,
P
<
Ty
>
),
ExprIf
(
Gc
<
Expr
>
,
P
<
Block
>
,
Option
<
Gc
<
Expr
>>
),
ExprIf
(
Gc
<
Expr
>
,
P
<
Block
>
,
Option
<
Gc
<
Expr
>>
),
ExprWhile
(
Gc
<
Expr
>
,
P
<
Block
>
),
ExprWhile
(
Gc
<
Expr
>
,
P
<
Block
>
),
// FIXME #6993: change to Option<Name>
// FIXME #6993: change to Option<Name>
... or not, if these are hygienic.
ExprForLoop
(
Gc
<
Pat
>
,
Gc
<
Expr
>
,
P
<
Block
>
,
Option
<
Ident
>
),
ExprForLoop
(
Gc
<
Pat
>
,
Gc
<
Expr
>
,
P
<
Block
>
,
Option
<
Ident
>
),
// Conditionless loop (can be exited with break, cont, or ret)
// Conditionless loop (can be exited with break, cont, or ret)
// FIXME #6993: change to Option<Name>
// FIXME #6993: change to Option<Name>
... or not, if these are hygienic.
ExprLoop
(
P
<
Block
>
,
Option
<
Ident
>
),
ExprLoop
(
P
<
Block
>
,
Option
<
Ident
>
),
ExprMatch
(
Gc
<
Expr
>
,
Vec
<
Arm
>
),
ExprMatch
(
Gc
<
Expr
>
,
Vec
<
Arm
>
),
ExprFnBlock
(
P
<
FnDecl
>
,
P
<
Block
>
),
ExprFnBlock
(
P
<
FnDecl
>
,
P
<
Block
>
),
...
@@ -468,9 +468,8 @@ pub enum Expr_ {
...
@@ -468,9 +468,8 @@ pub enum Expr_ {
ExprField
(
Gc
<
Expr
>
,
SpannedIdent
,
Vec
<
P
<
Ty
>>
),
ExprField
(
Gc
<
Expr
>
,
SpannedIdent
,
Vec
<
P
<
Ty
>>
),
ExprIndex
(
Gc
<
Expr
>
,
Gc
<
Expr
>
),
ExprIndex
(
Gc
<
Expr
>
,
Gc
<
Expr
>
),
/// Expression that looks like a "name". For example,
/// Variable reference, possibly containing `::` and/or
/// `std::slice::from_elem::<uint>` is an ExprPath that's the "name" part
/// type parameters, e.g. foo::bar::<baz>
/// of a function call.
ExprPath
(
Path
),
ExprPath
(
Path
),
ExprAddrOf
(
Mutability
,
Gc
<
Expr
>
),
ExprAddrOf
(
Mutability
,
Gc
<
Expr
>
),
...
@@ -643,6 +642,8 @@ pub struct TypeField {
...
@@ -643,6 +642,8 @@ pub struct TypeField {
pub
span
:
Span
,
pub
span
:
Span
,
}
}
/// Represents a required method in a trait declaration,
/// one without a default implementation
#[deriving(Clone,
PartialEq,
Eq,
Encodable,
Decodable,
Hash)]
#[deriving(Clone,
PartialEq,
Eq,
Encodable,
Decodable,
Hash)]
pub
struct
TypeMethod
{
pub
struct
TypeMethod
{
pub
ident
:
Ident
,
pub
ident
:
Ident
,
...
@@ -656,6 +657,8 @@ pub struct TypeMethod {
...
@@ -656,6 +657,8 @@ pub struct TypeMethod {
pub
vis
:
Visibility
,
pub
vis
:
Visibility
,
}
}
/// Represents a method declaration in a trait declaration, possibly
/// including a default implementation
// A trait method is either required (meaning it doesn't have an
// A trait method is either required (meaning it doesn't have an
// implementation, just a signature) or provided (meaning it has a default
// implementation, just a signature) or provided (meaning it has a default
// implementation).
// implementation).
...
@@ -741,6 +744,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
...
@@ -741,6 +744,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
}
}
}
}
/// Represents the type of a closure
#[deriving(PartialEq,
Eq,
Encodable,
Decodable,
Hash)]
#[deriving(PartialEq,
Eq,
Encodable,
Decodable,
Hash)]
pub
struct
ClosureTy
{
pub
struct
ClosureTy
{
pub
lifetimes
:
Vec
<
Lifetime
>
,
pub
lifetimes
:
Vec
<
Lifetime
>
,
...
@@ -809,6 +813,7 @@ pub struct InlineAsm {
...
@@ -809,6 +813,7 @@ pub struct InlineAsm {
pub
dialect
:
AsmDialect
pub
dialect
:
AsmDialect
}
}
/// represents an argument in a function header
#[deriving(Clone,
PartialEq,
Eq,
Encodable,
Decodable,
Hash)]
#[deriving(Clone,
PartialEq,
Eq,
Encodable,
Decodable,
Hash)]
pub
struct
Arg
{
pub
struct
Arg
{
pub
ty
:
P
<
Ty
>
,
pub
ty
:
P
<
Ty
>
,
...
@@ -836,7 +841,7 @@ pub fn new_self(span: Span, mutability: Mutability) -> Arg {
...
@@ -836,7 +841,7 @@ pub fn new_self(span: Span, mutability: Mutability) -> Arg {
}
}
}
}
// represents the header (not the body) of a function declaration
//
/
represents the header (not the body) of a function declaration
#[deriving(Clone,
PartialEq,
Eq,
Encodable,
Decodable,
Hash)]
#[deriving(Clone,
PartialEq,
Eq,
Encodable,
Decodable,
Hash)]
pub
struct
FnDecl
{
pub
struct
FnDecl
{
pub
inputs
:
Vec
<
Arg
>
,
pub
inputs
:
Vec
<
Arg
>
,
...
@@ -1107,6 +1112,7 @@ pub enum Item_ {
...
@@ -1107,6 +1112,7 @@ pub enum Item_ {
ItemTy
(
P
<
Ty
>
,
Generics
),
ItemTy
(
P
<
Ty
>
,
Generics
),
ItemEnum
(
EnumDef
,
Generics
),
ItemEnum
(
EnumDef
,
Generics
),
ItemStruct
(
Gc
<
StructDef
>
,
Generics
),
ItemStruct
(
Gc
<
StructDef
>
,
Generics
),
/// Represents a Trait Declaration
ItemTrait
(
Generics
,
Sized
,
Vec
<
TraitRef
>
,
Vec
<
TraitMethod
>
),
ItemTrait
(
Generics
,
Sized
,
Vec
<
TraitRef
>
,
Vec
<
TraitMethod
>
),
ItemImpl
(
Generics
,
ItemImpl
(
Generics
,
Option
<
TraitRef
>
,
// (optional) trait this impl implements
Option
<
TraitRef
>
,
// (optional) trait this impl implements
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
f126eacd
...
@@ -267,7 +267,8 @@ fn expand_loop_block(loop_block: P<Block>,
...
@@ -267,7 +267,8 @@ fn expand_loop_block(loop_block: P<Block>,
}
}
}
}
// eval $e with a new exts frame:
// eval $e with a new exts frame.
// must be a macro so that $e isn't evaluated too early.
macro_rules!
with_exts_frame
(
macro_rules!
with_exts_frame
(
(
$extsboxexpr:expr
,
$macros_escape:expr
,
$e:expr
)
=>
(
$extsboxexpr:expr
,
$macros_escape:expr
,
$e:expr
)
=>
({
$extsboxexpr
.push_frame
();
({
$extsboxexpr
.push_frame
();
...
@@ -609,7 +610,7 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander)
...
@@ -609,7 +610,7 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander)
}
=
**
local
;
}
=
**
local
;
// expand the pat (it might contain macro uses):
// expand the pat (it might contain macro uses):
let
expanded_pat
=
fld
.fold_pat
(
pat
);
let
expanded_pat
=
fld
.fold_pat
(
pat
);
// find the
pat_i
dents in the pattern:
// find the
PatI
dents in the pattern:
// oh dear heaven... this is going to include the enum
// oh dear heaven... this is going to include the enum
// names, as well... but that should be okay, as long as
// names, as well... but that should be okay, as long as
// the new names are gensyms for the old ones.
// the new names are gensyms for the old ones.
...
@@ -691,39 +692,34 @@ fn expand_arm(arm: &ast::Arm, fld: &mut MacroExpander) -> ast::Arm {
...
@@ -691,39 +692,34 @@ fn expand_arm(arm: &ast::Arm, fld: &mut MacroExpander) -> ast::Arm {
//
a visitor that extracts the pat_i
dent (binding) paths
//
/ A visitor that extracts the PatI
dent (binding) paths
// from a given thingy and puts them in a mutable
//
/
from a given thingy and puts them in a mutable
// array
//
/
array
#[deriving(Clone)]
#[deriving(Clone)]
struct
NameFinderContext
{
struct
PatIdentFinder
{
ident_accumulator
:
Vec
<
ast
::
Ident
>
,
ident_accumulator
:
Vec
<
ast
::
Ident
>
,
}
}
impl
Visitor
<
()
>
for
NameFinderContext
{
impl
Visitor
<
()
>
for
PatIdentFinder
{
fn
visit_pat
(
&
mut
self
,
pattern
:
&
ast
::
Pat
,
_
:
())
{
fn
visit_pat
(
&
mut
self
,
pattern
:
&
ast
::
Pat
,
_
:
())
{
match
*
pattern
{
match
*
pattern
{
// we found a pat_ident!
ast
::
Pat
{
id
:
_
,
node
:
ast
::
PatIdent
(
_
,
ref
path1
,
ref
inner
),
span
:
_
}
=>
{
ast
::
Pat
{
id
:
_
,
node
:
ast
::
PatIdent
(
_
,
ref
path1
,
ref
inner
),
span
:
_
}
=>
{
self
.ident_accumulator
.push
(
path1
.node
);
self
.ident_accumulator
.push
(
path1
.node
);
// visit optional subpattern of
pat_i
dent:
// visit optional subpattern of
PatI
dent:
for
subpat
in
inner
.iter
()
{
for
subpat
in
inner
.iter
()
{
self
.visit_pat
(
&**
subpat
,
())
self
.visit_pat
(
&**
subpat
,
())
}
}
}
}
// use the default traversal for non-
pat_i
dents
// use the default traversal for non-
PatI
dents
_
=>
visit
::
walk_pat
(
self
,
pattern
,
())
_
=>
visit
::
walk_pat
(
self
,
pattern
,
())
}
}
}
}
}
}
//
find the pat_i
dent paths in a pattern
//
/ find the PatI
dent paths in a pattern
fn
pattern_bindings
(
pat
:
&
ast
::
Pat
)
->
Vec
<
ast
::
Ident
>
{
fn
pattern_bindings
(
pat
:
&
ast
::
Pat
)
->
Vec
<
ast
::
Ident
>
{
let
mut
name_finder
=
NameFinderContext
{
ident_accumulator
:
Vec
::
new
()};
let
mut
name_finder
=
PatIdentFinder
{
ident_accumulator
:
Vec
::
new
()};
name_finder
.visit_pat
(
pat
,());
name_finder
.visit_pat
(
pat
,());
name_finder
.ident_accumulator
name_finder
.ident_accumulator
}
}
...
@@ -1028,7 +1024,7 @@ fn original_span(cx: &ExtCtxt) -> Gc<codemap::ExpnInfo> {
...
@@ -1028,7 +1024,7 @@ fn original_span(cx: &ExtCtxt) -> Gc<codemap::ExpnInfo> {
#[cfg(test)]
#[cfg(test)]
mod
test
{
mod
test
{
use
super
::{
pattern_bindings
,
expand_crate
,
contains_macro_escape
};
use
super
::{
pattern_bindings
,
expand_crate
,
contains_macro_escape
};
use
super
::{
NameFinderContext
};
use
super
::{
PatIdentFinder
};
use
ast
;
use
ast
;
use
ast
::{
Attribute_
,
AttrOuter
,
MetaWord
};
use
ast
::{
Attribute_
,
AttrOuter
,
MetaWord
};
use
attr
;
use
attr
;
...
@@ -1167,7 +1163,7 @@ fn expand_crate_str(crate_str: String) -> ast::Crate {
...
@@ -1167,7 +1163,7 @@ fn expand_crate_str(crate_str: String) -> ast::Crate {
// find the pat_ident paths in a crate
// find the pat_ident paths in a crate
fn
crate_bindings
(
the_crate
:
&
ast
::
Crate
)
->
Vec
<
ast
::
Ident
>
{
fn
crate_bindings
(
the_crate
:
&
ast
::
Crate
)
->
Vec
<
ast
::
Ident
>
{
let
mut
name_finder
=
NameFinderContext
{
ident_accumulator
:
Vec
::
new
()};
let
mut
name_finder
=
PatIdentFinder
{
ident_accumulator
:
Vec
::
new
()};
visit
::
walk_crate
(
&
mut
name_finder
,
the_crate
,
());
visit
::
walk_crate
(
&
mut
name_finder
,
the_crate
,
());
name_finder
.ident_accumulator
name_finder
.ident_accumulator
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录