Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
94d92e68
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,发现更多精彩内容 >>
提交
94d92e68
编写于
7月 19, 2014
作者:
M
Marvin Löbel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Moved `syntax::ext::base::SyntaxEnv` into `syntax::ext::base::ExtCtx`
上级
df68c6f3
变更
2
展开全部
隐藏空白更改
内联
并排
Showing
2 changed file
with
213 addition
and
201 deletion
+213
-201
src/libsyntax/ext/base.rs
src/libsyntax/ext/base.rs
+19
-17
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+194
-184
未找到文件。
src/libsyntax/ext/base.rs
浏览文件 @
94d92e68
...
...
@@ -23,6 +23,7 @@
use
std
::
collections
::
HashMap
;
use
std
::
gc
::{
Gc
,
GC
};
use
std
::
rc
::
Rc
;
// new-style macro! tt code:
//
...
...
@@ -104,9 +105,9 @@ fn expand(&self,
/// just into the compiler's internal macro table, for `make_def`).
pub
trait
MacResult
{
/// Define a new macro.
// this
particular flavor should go away; the idea that a macro might
// e
xpand into either a macro definition or an expression, depending
//
on what
the context wants, is kind of silly.
// this
should go away; the idea that a macro might expand into
// e
ither a macro definition or an expression, depending on what
// the context wants, is kind of silly.
fn
make_def
(
&
self
)
->
Option
<
MacroDef
>
{
None
}
...
...
@@ -314,7 +315,7 @@ pub fn new() -> BlockInfo {
/// The base map of methods for expanding syntax extension
/// AST nodes into full ASTs
pub
fn
syntax_expander_table
()
->
SyntaxEnv
{
fn
initial_
syntax_expander_table
()
->
SyntaxEnv
{
// utility function to simplify creating NormalTT syntax extensions
fn
builtin_normal_expander
(
f
:
MacroExpanderFn
)
->
SyntaxExtension
{
NormalTT
(
box
BasicMacroExpander
{
...
...
@@ -431,7 +432,9 @@ pub struct ExtCtxt<'a> {
pub
mod_path
:
Vec
<
ast
::
Ident
>
,
pub
trace_mac
:
bool
,
pub
exported_macros
:
Vec
<
Gc
<
ast
::
Item
>>
pub
exported_macros
:
Vec
<
Gc
<
ast
::
Item
>>
,
pub
syntax_env
:
SyntaxEnv
,
}
impl
<
'a
>
ExtCtxt
<
'a
>
{
...
...
@@ -445,6 +448,7 @@ pub fn new<'a>(parse_sess: &'a parse::ParseSess, cfg: ast::CrateConfig,
ecfg
:
ecfg
,
trace_mac
:
false
,
exported_macros
:
Vec
::
new
(),
syntax_env
:
initial_syntax_expander_table
(),
}
}
...
...
@@ -453,7 +457,6 @@ pub fn expand_expr(&mut self, mut e: Gc<ast::Expr>) -> Gc<ast::Expr> {
match
e
.node
{
ast
::
ExprMac
(
..
)
=>
{
let
mut
expander
=
expand
::
MacroExpander
{
extsbox
:
syntax_expander_table
(),
cx
:
self
,
};
e
=
expand
::
expand_expr
(
e
,
&
mut
expander
);
...
...
@@ -642,10 +645,13 @@ pub fn get_exprs_from_tts(cx: &mut ExtCtxt,
/// In order to have some notion of scoping for macros,
/// we want to implement the notion of a transformation
/// environment.
///
/// This environment maps Names to SyntaxExtensions.
pub
struct
SyntaxEnv
{
chain
:
Vec
<
MapChainFrame
>
,
}
//impl question: how to implement it? Initially, the
//
impl question: how to implement it? Initially, the
// env will contain only macros, so it might be painful
// to add an empty frame for every context. Let's just
// get it working, first....
...
...
@@ -657,15 +663,11 @@ pub fn get_exprs_from_tts(cx: &mut ExtCtxt,
struct
MapChainFrame
{
info
:
BlockInfo
,
map
:
HashMap
<
Name
,
SyntaxExtension
>
,
}
pub
struct
SyntaxEnv
{
chain
:
Vec
<
MapChainFrame
>
,
map
:
HashMap
<
Name
,
Rc
<
SyntaxExtension
>>
,
}
impl
SyntaxEnv
{
pub
fn
new
()
->
SyntaxEnv
{
fn
new
()
->
SyntaxEnv
{
let
mut
map
=
SyntaxEnv
{
chain
:
Vec
::
new
()
};
map
.push_frame
();
map
...
...
@@ -692,10 +694,10 @@ fn find_escape_frame<'a>(&'a mut self) -> &'a mut MapChainFrame {
unreachable!
()
}
pub
fn
find
<
'a
>
(
&
'a
self
,
k
:
&
Name
)
->
Option
<&
'a
SyntaxExtension
>
{
pub
fn
find
(
&
self
,
k
:
&
Name
)
->
Option
<
Rc
<
SyntaxExtension
>
>
{
for
frame
in
self
.chain
.iter
()
.rev
()
{
match
frame
.map
.find
(
k
)
{
Some
(
v
)
=>
return
Some
(
v
),
Some
(
v
)
=>
return
Some
(
v
.clone
()
),
None
=>
{}
}
}
...
...
@@ -703,7 +705,7 @@ pub fn find<'a>(&'a self, k: &Name) -> Option<&'a SyntaxExtension> {
}
pub
fn
insert
(
&
mut
self
,
k
:
Name
,
v
:
SyntaxExtension
)
{
self
.find_escape_frame
()
.map
.insert
(
k
,
v
);
self
.find_escape_frame
()
.map
.insert
(
k
,
Rc
::
new
(
v
)
);
}
pub
fn
info
<
'a
>
(
&
'a
mut
self
)
->
&
'a
mut
BlockInfo
{
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
94d92e68
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录