Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3192adbf
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,发现更多精彩内容 >>
提交
3192adbf
编写于
5月 21, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor out `mac_result` in `expand_mac_invoc`
上级
215c1460
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
53 addition
and
54 deletion
+53
-54
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+53
-54
未找到文件。
src/libsyntax/ext/expand.rs
浏览文件 @
3192adbf
...
...
@@ -201,47 +201,46 @@ fn expand_mac_invoc<T>(mac: ast::Mac, attrs: Vec<ast::Attribute>, span: Span,
fld
:
&
mut
MacroExpander
)
->
T
where
T
:
MacroGenerable
,
{
check_attributes
(
&
attrs
,
fld
);
// it would almost certainly be cleaner to pass the whole
// macro invocation in, rather than pulling it apart and
// marking the tts and the ctxt separately. This also goes
// for the other three macro invocation chunks of code
// in this file.
let
Mac_
{
path
:
pth
,
tts
,
..
}
=
mac
.node
;
if
pth
.segments
.len
()
>
1
{
fld
.cx
.span_err
(
pth
.span
,
"expected macro name without module
\
separators"
);
// let compilation continue
return
T
::
dummy
(
span
);
}
let
extname
=
pth
.segments
[
0
]
.identifier.name
;
match
fld
.cx.syntax_env
.find
(
extname
)
{
None
=>
{
let
mut
err
=
fld
.cx
.struct_span_err
(
pth
.span
,
&
format!
(
"macro undefined: '{}!'"
,
&
extname
));
let
Mac_
{
path
,
tts
,
..
}
=
mac
.node
;
let
mark
=
fresh_mark
();
fn
mac_result
<
'a
>
(
path
:
&
ast
::
Path
,
tts
:
Vec
<
TokenTree
>
,
mark
:
Mrk
,
attrs
:
Vec
<
ast
::
Attribute
>
,
call_site
:
Span
,
fld
:
&
'a
mut
MacroExpander
)
->
Option
<
Box
<
MacResult
+
'a
>>
{
check_attributes
(
&
attrs
,
fld
);
if
path
.segments
.len
()
>
1
{
fld
.cx
.span_err
(
path
.span
,
"expected macro name without module separators"
);
return
None
;
}
let
extname
=
path
.segments
[
0
]
.identifier.name
;
let
extension
=
if
let
Some
(
extension
)
=
fld
.cx.syntax_env
.find
(
extname
)
{
extension
}
else
{
let
mut
err
=
fld
.cx
.struct_span_err
(
path
.span
,
&
format!
(
"macro undefined: '{}!'"
,
&
extname
));
fld
.cx
.suggest_macro_name
(
&
extname
.as_str
(),
&
mut
err
);
err
.emit
();
return
None
;
};
// let compilation continue
T
::
dummy
(
span
)
}
Some
(
rc
)
=>
match
*
rc
{
match
*
extension
{
NormalTT
(
ref
expandfun
,
exp_span
,
allow_internal_unstable
)
=>
{
fld
.cx
.bt_push
(
ExpnInfo
{
call_site
:
span
,
callee
:
NameAndSpan
{
format
:
MacroBang
(
extname
),
span
:
exp_span
,
allow_internal_unstable
:
allow_internal_unstable
,
},
});
let
fm
=
fresh_mark
();
let
marked_before
=
mark_tts
(
&
tts
[
..
],
fm
);
call_site
:
call_site
,
callee
:
NameAndSpan
{
format
:
MacroBang
(
extname
),
span
:
exp_span
,
allow_internal_unstable
:
allow_internal_unstable
,
},
});
// The span that we pass to the expanders we want to
// be the root of the call stack. That's the most
...
...
@@ -249,35 +248,35 @@ fn expand_mac_invoc<T>(mac: ast::Mac, attrs: Vec<ast::Attribute>, span: Span,
// the macro.
let
mac_span
=
fld
.cx
.original_span
();
let
opt_parsed
=
{
let
expanded
=
expandfun
.expand
(
fld
.cx
,
mac_span
,
&
marked_before
[
..
]);
T
::
make_with
(
expanded
)
};
let
parsed
=
match
opt_parsed
{
Some
(
e
)
=>
e
,
None
=>
{
let
msg
=
format!
(
"non-{kind} macro in {kind} position: {name}"
,
name
=
extname
,
kind
=
T
::
kind_name
());
fld
.cx
.span_err
(
pth
.span
,
&
msg
);
return
T
::
dummy
(
span
);
}
};
let
marked
=
parsed
.fold_with
(
&
mut
Marker
{
mark
:
fm
});
let
fully_expanded
=
marked
.fold_with
(
fld
);
fld
.cx
.bt_pop
();
fully_expanded
let
marked_tts
=
mark_tts
(
&
tts
[
..
],
mark
);
Some
(
expandfun
.expand
(
fld
.cx
,
mac_span
,
&
marked_tts
))
}
_
=>
{
fld
.cx
.span_err
(
pth
.span
,
&
format!
(
"'{}' is not a tt-style macro"
,
extname
));
T
::
dummy
(
span
)
fld
.cx
.span_err
(
path
.span
,
&
format!
(
"'{}' is not a tt-style macro"
,
extname
));
None
}
}
}
let
opt_expanded
=
T
::
make_with
(
match
mac_result
(
&
path
,
tts
,
mark
,
attrs
,
span
,
fld
)
{
Some
(
result
)
=>
result
,
None
=>
return
T
::
dummy
(
span
),
});
let
expanded
=
if
let
Some
(
expanded
)
=
opt_expanded
{
expanded
}
else
{
let
msg
=
format!
(
"non-{kind} macro in {kind} position: {name}"
,
name
=
path
.segments
[
0
]
.identifier.name
,
kind
=
T
::
kind_name
());
fld
.cx
.span_err
(
path
.span
,
&
msg
);
return
T
::
dummy
(
span
);
};
let
marked
=
expanded
.fold_with
(
&
mut
Marker
{
mark
:
mark
});
let
fully_expanded
=
marked
.fold_with
(
fld
);
fld
.cx
.bt_pop
();
fully_expanded
}
/// Rename loop label and expand its loop body
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录