Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
20d8222e
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,发现更多精彩内容 >>
提交
20d8222e
编写于
2月 15, 2015
作者:
F
Felix S. Klock II
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
libsyntax: Pass feature set in ExpansionConfig, not just enable_quotes.
上级
cf636c23
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
17 deletion
+27
-17
src/librustc_driver/driver.rs
src/librustc_driver/driver.rs
+2
-1
src/libsyntax/ext/base.rs
src/libsyntax/ext/base.rs
+5
-4
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+20
-12
未找到文件。
src/librustc_driver/driver.rs
浏览文件 @
20d8222e
...
...
@@ -469,9 +469,10 @@ pub fn phase_2_configure_and_expand(sess: &Session,
new_path
.extend
(
env
::
split_paths
(
&
_
old_path
));
env
::
set_var
(
"PATH"
,
&
env
::
join_paths
(
new_path
.iter
())
.unwrap
());
}
let
features
=
sess
.features
.borrow
();
let
cfg
=
syntax
::
ext
::
expand
::
ExpansionConfig
{
crate_name
:
crate_name
.to_string
(),
enable_quotes
:
sess
.features
.borrow
()
.quote
,
features
:
Some
(
&
features
)
,
recursion_limit
:
sess
.recursion_limit
.get
(),
};
let
ret
=
syntax
::
ext
::
expand
::
expand_crate
(
&
sess
.parse_sess
,
...
...
src/libsyntax/ext/base.rs
浏览文件 @
20d8222e
...
...
@@ -439,7 +439,8 @@ pub fn new() -> BlockInfo {
/// The base map of methods for expanding syntax extension
/// AST nodes into full ASTs
fn
initial_syntax_expander_table
(
ecfg
:
&
expand
::
ExpansionConfig
)
->
SyntaxEnv
{
fn
initial_syntax_expander_table
<
'feat
>
(
ecfg
:
&
expand
::
ExpansionConfig
<
'feat
>
)
->
SyntaxEnv
{
// utility function to simplify creating NormalTT syntax extensions
fn
builtin_normal_expander
(
f
:
MacroExpanderFn
)
->
SyntaxExtension
{
NormalTT
(
box
f
,
None
)
...
...
@@ -470,7 +471,7 @@ fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
syntax_expanders
.insert
(
intern
(
"deriving"
),
Decorator
(
box
ext
::
deriving
::
expand_deprecated_deriving
));
if
ecfg
.enable_quotes
{
if
ecfg
.enable_quotes
()
{
// Quasi-quoting expanders
syntax_expanders
.insert
(
intern
(
"quote_tokens"
),
builtin_normal_expander
(
...
...
@@ -541,7 +542,7 @@ pub struct ExtCtxt<'a> {
pub
parse_sess
:
&
'a
parse
::
ParseSess
,
pub
cfg
:
ast
::
CrateConfig
,
pub
backtrace
:
ExpnId
,
pub
ecfg
:
expand
::
ExpansionConfig
,
pub
ecfg
:
expand
::
ExpansionConfig
<
'a
>
,
pub
use_std
:
bool
,
pub
mod_path
:
Vec
<
ast
::
Ident
>
,
...
...
@@ -554,7 +555,7 @@ pub struct ExtCtxt<'a> {
impl
<
'a
>
ExtCtxt
<
'a
>
{
pub
fn
new
(
parse_sess
:
&
'a
parse
::
ParseSess
,
cfg
:
ast
::
CrateConfig
,
ecfg
:
expand
::
ExpansionConfig
)
->
ExtCtxt
<
'a
>
{
ecfg
:
expand
::
ExpansionConfig
<
'a
>
)
->
ExtCtxt
<
'a
>
{
let
env
=
initial_syntax_expander_table
(
&
ecfg
);
ExtCtxt
{
parse_sess
:
parse_sess
,
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
20d8222e
...
...
@@ -22,6 +22,7 @@
use
codemap
;
use
codemap
::{
Span
,
Spanned
,
ExpnInfo
,
NameAndSpan
,
MacroBang
,
MacroAttribute
};
use
ext
::
base
::
*
;
use
feature_gate
::{
Features
};
use
fold
;
use
fold
::
*
;
use
parse
;
...
...
@@ -1407,28 +1408,35 @@ fn new_span(cx: &ExtCtxt, sp: Span) -> Span {
}
}
pub
struct
ExpansionConfig
{
pub
struct
ExpansionConfig
<
'feat
>
{
pub
crate_name
:
String
,
pub
enable_quotes
:
bool
,
pub
features
:
Option
<&
'feat
Features
>
,
pub
recursion_limit
:
usize
,
}
impl
ExpansionConfig
{
pub
fn
default
(
crate_name
:
String
)
->
ExpansionConfig
{
impl
<
'feat
>
ExpansionConfig
<
'feat
>
{
pub
fn
default
(
crate_name
:
String
)
->
ExpansionConfig
<
'static
>
{
ExpansionConfig
{
crate_name
:
crate_name
,
enable_quotes
:
fals
e
,
features
:
Non
e
,
recursion_limit
:
64
,
}
}
pub
fn
enable_quotes
(
&
self
)
->
bool
{
match
self
.features
{
Some
(
&
Features
{
quote
:
true
,
..
})
=>
true
,
_
=>
false
,
}
}
}
pub
fn
expand_crate
(
parse_sess
:
&
parse
::
ParseSess
,
cfg
:
ExpansionConfig
,
// these are the macros being imported to this crate:
imported_macros
:
Vec
<
ast
::
MacroDef
>
,
user_exts
:
Vec
<
NamedSyntaxExtension
>
,
c
:
Crate
)
->
Crate
{
pub
fn
expand_crate
<
'feat
>
(
parse_sess
:
&
parse
::
ParseSess
,
cfg
:
ExpansionConfig
<
'feat
>
,
// these are the macros being imported to this crate:
imported_macros
:
Vec
<
ast
::
MacroDef
>
,
user_exts
:
Vec
<
NamedSyntaxExtension
>
,
c
:
Crate
)
->
Crate
{
let
mut
cx
=
ExtCtxt
::
new
(
parse_sess
,
c
.config
.clone
(),
cfg
);
cx
.use_std
=
std_inject
::
use_std
(
&
c
);
...
...
@@ -1597,7 +1605,7 @@ fn crate_idents(the_crate: &ast::Crate) -> Vec<ast::Ident> {
// these following tests are quite fragile, in that they don't test what
// *kind* of failure occurs.
fn
test_ecfg
()
->
ExpansionConfig
{
fn
test_ecfg
()
->
ExpansionConfig
<
'static
>
{
ExpansionConfig
::
default
(
"test"
.to_string
())
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录