Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
aa91ef0c
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,发现更多精彩内容 >>
提交
aa91ef0c
编写于
7月 03, 2014
作者:
J
John Clements
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new_mark -> apply_mark, new_rename -> apply_rename
上级
b8cd7f7c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
29 deletion
+29
-29
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+4
-4
src/libsyntax/ext/mtwt.rs
src/libsyntax/ext/mtwt.rs
+24
-24
src/libsyntax/parse/token.rs
src/libsyntax/parse/token.rs
+1
-1
未找到文件。
src/libsyntax/ext/expand.rs
浏览文件 @
aa91ef0c
...
...
@@ -852,7 +852,7 @@ impl<'a> Folder for IdentRenamer<'a> {
fn
fold_ident
(
&
mut
self
,
id
:
Ident
)
->
Ident
{
Ident
{
name
:
id
.name
,
ctxt
:
mtwt
::
new
_renames
(
self
.renames
,
id
.ctxt
),
ctxt
:
mtwt
::
apply
_renames
(
self
.renames
,
id
.ctxt
),
}
}
}
...
...
@@ -870,7 +870,7 @@ fn fold_pat(&mut self, pat: Gc<ast::Pat>) -> Gc<ast::Pat> {
match
pat
.node
{
ast
::
PatIdent
(
binding_mode
,
Spanned
{
span
:
ref
sp
,
node
:
id
},
ref
sub
)
=>
{
let
new_ident
=
Ident
{
name
:
id
.name
,
ctxt
:
mtwt
::
new
_renames
(
self
.renames
,
id
.ctxt
)};
ctxt
:
mtwt
::
apply
_renames
(
self
.renames
,
id
.ctxt
)};
let
new_node
=
ast
::
PatIdent
(
binding_mode
,
Spanned
{
span
:
self
.new_span
(
*
sp
),
node
:
new_ident
},
...
...
@@ -990,7 +990,7 @@ impl Folder for Marker {
fn
fold_ident
(
&
mut
self
,
id
:
Ident
)
->
Ident
{
ast
::
Ident
{
name
:
id
.name
,
ctxt
:
mtwt
::
new
_mark
(
self
.mark
,
id
.ctxt
)
ctxt
:
mtwt
::
apply
_mark
(
self
.mark
,
id
.ctxt
)
}
}
fn
fold_mac
(
&
mut
self
,
m
:
&
ast
::
Mac
)
->
ast
::
Mac
{
...
...
@@ -998,7 +998,7 @@ fn fold_mac(&mut self, m: &ast::Mac) -> ast::Mac {
MacInvocTT
(
ref
path
,
ref
tts
,
ctxt
)
=>
{
MacInvocTT
(
self
.fold_path
(
path
),
fold_tts
(
tts
.as_slice
(),
self
),
mtwt
::
new
_mark
(
self
.mark
,
ctxt
))
mtwt
::
apply
_mark
(
self
.mark
,
ctxt
))
}
};
Spanned
{
...
...
src/libsyntax/ext/mtwt.rs
浏览文件 @
aa91ef0c
...
...
@@ -58,12 +58,12 @@ pub enum SyntaxContext_ {
pub
type
RenameList
=
Vec
<
(
Ident
,
Name
)
>
;
/// Extend a syntax context with a given mark
pub
fn
new
_mark
(
m
:
Mrk
,
ctxt
:
SyntaxContext
)
->
SyntaxContext
{
with_sctable
(|
table
|
new
_mark_internal
(
m
,
ctxt
,
table
))
pub
fn
apply
_mark
(
m
:
Mrk
,
ctxt
:
SyntaxContext
)
->
SyntaxContext
{
with_sctable
(|
table
|
apply
_mark_internal
(
m
,
ctxt
,
table
))
}
// Extend a syntax context with a given mark and sctable (explicit memoization)
fn
new
_mark_internal
(
m
:
Mrk
,
ctxt
:
SyntaxContext
,
table
:
&
SCTable
)
->
SyntaxContext
{
fn
apply
_mark_internal
(
m
:
Mrk
,
ctxt
:
SyntaxContext
,
table
:
&
SCTable
)
->
SyntaxContext
{
let
key
=
(
ctxt
,
m
);
let
new_ctxt
=
|
_
:
&
(
SyntaxContext
,
Mrk
)|
idx_push
(
&
mut
*
table
.table
.borrow_mut
(),
Mark
(
m
,
ctxt
));
...
...
@@ -72,13 +72,13 @@ fn new_mark_internal(m: Mrk, ctxt: SyntaxContext, table: &SCTable) -> SyntaxCont
}
/// Extend a syntax context with a given rename
pub
fn
new
_rename
(
id
:
Ident
,
to
:
Name
,
pub
fn
apply
_rename
(
id
:
Ident
,
to
:
Name
,
ctxt
:
SyntaxContext
)
->
SyntaxContext
{
with_sctable
(|
table
|
new
_rename_internal
(
id
,
to
,
ctxt
,
table
))
with_sctable
(|
table
|
apply
_rename_internal
(
id
,
to
,
ctxt
,
table
))
}
// Extend a syntax context with a given rename and sctable (explicit memoization)
fn
new
_rename_internal
(
id
:
Ident
,
fn
apply
_rename_internal
(
id
:
Ident
,
to
:
Name
,
ctxt
:
SyntaxContext
,
table
:
&
SCTable
)
->
SyntaxContext
{
...
...
@@ -93,10 +93,10 @@ fn new_rename_internal(id: Ident,
// if these rename lists get long, it would make sense
// to consider memoizing this fold. This may come up
// when we add hygiene to item names.
pub
fn
new
_renames
(
renames
:
&
RenameList
,
ctxt
:
SyntaxContext
)
->
SyntaxContext
{
pub
fn
apply
_renames
(
renames
:
&
RenameList
,
ctxt
:
SyntaxContext
)
->
SyntaxContext
{
renames
.iter
()
.fold
(
ctxt
,
|
ctxt
,
&
(
from
,
to
)|
{
new
_rename
(
from
,
to
,
ctxt
)
})
apply
_rename
(
from
,
to
,
ctxt
)
})
}
/// Fetch the SCTable from TLS, create one if it doesn't yet exist.
...
...
@@ -277,8 +277,8 @@ fn xor_push(marks: &mut Vec<Mrk>, mark: Mrk) {
#[cfg(test)]
mod
tests
{
use
ast
::{
EMPTY_CTXT
,
Ident
,
Mrk
,
Name
,
SyntaxContext
};
use
super
::{
resolve
,
xor_push
,
new
_mark_internal
,
new_sctable_internal
};
use
super
::{
new_rename_internal
,
new
_renames
,
marksof_internal
,
resolve_internal
};
use
super
::{
resolve
,
xor_push
,
apply
_mark_internal
,
new_sctable_internal
};
use
super
::{
apply_rename_internal
,
apply
_renames
,
marksof_internal
,
resolve_internal
};
use
super
::{
SCTable
,
EmptyCtxt
,
Mark
,
Rename
,
IllegalCtxt
};
use
std
::
collections
::
HashMap
;
...
...
@@ -319,8 +319,8 @@ fn unfold_test_sc(tscs : Vec<TestSC> , tail: SyntaxContext, table: &SCTable)
->
SyntaxContext
{
tscs
.iter
()
.rev
()
.fold
(
tail
,
|
tail
:
SyntaxContext
,
tsc
:
&
TestSC
|
{
match
*
tsc
{
M
(
mrk
)
=>
new
_mark_internal
(
mrk
,
tail
,
table
),
R
(
ident
,
name
)
=>
new
_rename_internal
(
ident
,
name
,
tail
,
table
)}})
M
(
mrk
)
=>
apply
_mark_internal
(
mrk
,
tail
,
table
),
R
(
ident
,
name
)
=>
apply
_rename_internal
(
ident
,
name
,
tail
,
table
)}})
}
// gather a SyntaxContext back into a vector of TestSCs
...
...
@@ -365,7 +365,7 @@ fn test_unfold_refold(){
fn
unfold_marks
(
mrks
:
Vec
<
Mrk
>
,
tail
:
SyntaxContext
,
table
:
&
SCTable
)
->
SyntaxContext
{
mrks
.iter
()
.rev
()
.fold
(
tail
,
|
tail
:
SyntaxContext
,
mrk
:
&
Mrk
|
{
new
_mark_internal
(
*
mrk
,
tail
,
table
)})
{
apply
_mark_internal
(
*
mrk
,
tail
,
table
)})
}
#[test]
fn
unfold_marks_test
()
{
...
...
@@ -397,13 +397,13 @@ fn test_marksof () {
// rename where stop doesn't match:
{
let
chain
=
vec!
(
M
(
9
),
R
(
id
(
name1
,
new
_mark_internal
(
4
,
EMPTY_CTXT
,
&
mut
t
)),
apply
_mark_internal
(
4
,
EMPTY_CTXT
,
&
mut
t
)),
100101102
),
M
(
14
));
let
ans
=
unfold_test_sc
(
chain
,
EMPTY_CTXT
,
&
mut
t
);
assert_eq!
(
marksof_internal
(
ans
,
stopname
,
&
t
),
vec!
(
9
,
14
));}
// rename where stop does match
{
let
name1sc
=
new
_mark_internal
(
4
,
EMPTY_CTXT
,
&
mut
t
);
{
let
name1sc
=
apply
_mark_internal
(
4
,
EMPTY_CTXT
,
&
mut
t
);
let
chain
=
vec!
(
M
(
9
),
R
(
id
(
name1
,
name1sc
),
stopname
),
...
...
@@ -427,7 +427,7 @@ fn resolve_tests () {
{
let
sc
=
unfold_test_sc
(
vec!
(
R
(
id
(
50
,
EMPTY_CTXT
),
51
),
M
(
12
)),
EMPTY_CTXT
,
&
mut
t
);
assert_eq!
(
resolve_internal
(
id
(
a
,
sc
),
&
mut
t
,
&
mut
rt
),
a
);}
// - rename where names do match, but marks don't
{
let
sc1
=
new
_mark_internal
(
1
,
EMPTY_CTXT
,
&
mut
t
);
{
let
sc1
=
apply
_mark_internal
(
1
,
EMPTY_CTXT
,
&
mut
t
);
let
sc
=
unfold_test_sc
(
vec!
(
R
(
id
(
a
,
sc1
),
50
),
M
(
1
),
M
(
2
)),
...
...
@@ -450,11 +450,11 @@ fn resolve_tests () {
EMPTY_CTXT
,
&
mut
t
);
assert_eq!
(
resolve_internal
(
id
(
a
,
sc
),
&
mut
t
,
&
mut
rt
),
51
);
}
// the simplest double-rename:
{
let
a_to_a50
=
new
_rename_internal
(
id
(
a
,
EMPTY_CTXT
),
50
,
EMPTY_CTXT
,
&
mut
t
);
let
a50_to_a51
=
new
_rename_internal
(
id
(
a
,
a_to_a50
),
51
,
a_to_a50
,
&
mut
t
);
{
let
a_to_a50
=
apply
_rename_internal
(
id
(
a
,
EMPTY_CTXT
),
50
,
EMPTY_CTXT
,
&
mut
t
);
let
a50_to_a51
=
apply
_rename_internal
(
id
(
a
,
a_to_a50
),
51
,
a_to_a50
,
&
mut
t
);
assert_eq!
(
resolve_internal
(
id
(
a
,
a50_to_a51
),
&
mut
t
,
&
mut
rt
),
51
);
// mark on the outside doesn't stop rename:
let
sc
=
new
_mark_internal
(
9
,
a50_to_a51
,
&
mut
t
);
let
sc
=
apply
_mark_internal
(
9
,
a50_to_a51
,
&
mut
t
);
assert_eq!
(
resolve_internal
(
id
(
a
,
sc
),
&
mut
t
,
&
mut
rt
),
51
);
// but mark on the inside does:
let
a50_to_a51_b
=
unfold_test_sc
(
vec!
(
R
(
id
(
a
,
a_to_a50
),
51
),
...
...
@@ -474,10 +474,10 @@ fn mtwt_resolve_test(){
#[test]
fn
hashing_tests
()
{
let
mut
t
=
new_sctable_internal
();
assert_eq!
(
new
_mark_internal
(
12
,
EMPTY_CTXT
,
&
mut
t
),
2
);
assert_eq!
(
new
_mark_internal
(
13
,
EMPTY_CTXT
,
&
mut
t
),
3
);
assert_eq!
(
apply
_mark_internal
(
12
,
EMPTY_CTXT
,
&
mut
t
),
2
);
assert_eq!
(
apply
_mark_internal
(
13
,
EMPTY_CTXT
,
&
mut
t
),
3
);
// using the same one again should result in the same index:
assert_eq!
(
new
_mark_internal
(
12
,
EMPTY_CTXT
,
&
mut
t
),
2
);
assert_eq!
(
apply
_mark_internal
(
12
,
EMPTY_CTXT
,
&
mut
t
),
2
);
// I'm assuming that the rename table will behave the same....
}
...
...
@@ -498,7 +498,7 @@ fn resolve_table_hashing_tests() {
fn
new_resolves_test
()
{
let
renames
=
vec!
((
Ident
{
name
:
23
,
ctxt
:
EMPTY_CTXT
},
24
),
(
Ident
{
name
:
29
,
ctxt
:
EMPTY_CTXT
},
29
));
let
new_ctxt1
=
new
_renames
(
&
renames
,
EMPTY_CTXT
);
let
new_ctxt1
=
apply
_renames
(
&
renames
,
EMPTY_CTXT
);
assert_eq!
(
resolve
(
Ident
{
name
:
23
,
ctxt
:
new_ctxt1
}),
24
);
assert_eq!
(
resolve
(
Ident
{
name
:
29
,
ctxt
:
new_ctxt1
}),
29
);
}
...
...
src/libsyntax/parse/token.rs
浏览文件 @
aa91ef0c
...
...
@@ -765,7 +765,7 @@ mod test {
use
ext
::
mtwt
;
fn
mark_ident
(
id
:
ast
::
Ident
,
m
:
ast
::
Mrk
)
->
ast
::
Ident
{
ast
::
Ident
{
name
:
id
.name
,
ctxt
:
mtwt
::
new
_mark
(
m
,
id
.ctxt
)}
ast
::
Ident
{
name
:
id
.name
,
ctxt
:
mtwt
::
apply
_mark
(
m
,
id
.ctxt
)}
}
#[test]
fn
mtwt_token_eq_test
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录