Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
31e0e12e
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,发现更多精彩内容 >>
提交
31e0e12e
编写于
10月 11, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for undetermined macro invocations.
上级
d5281ef6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
44 addition
and
18 deletion
+44
-18
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+6
-5
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+1
-7
src/libsyntax/ext/base.rs
src/libsyntax/ext/base.rs
+11
-3
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+26
-3
未找到文件。
src/librustc_resolve/macros.rs
浏览文件 @
31e0e12e
...
...
@@ -17,7 +17,7 @@
use
std
::
rc
::
Rc
;
use
syntax
::
ast
;
use
syntax
::
errors
::
DiagnosticBuilder
;
use
syntax
::
ext
::
base
::{
self
,
MultiModifier
,
MultiDecorator
,
MultiItemModifier
};
use
syntax
::
ext
::
base
::{
self
,
Determinacy
,
MultiModifier
,
MultiDecorator
,
MultiItemModifier
};
use
syntax
::
ext
::
base
::{
NormalTT
,
SyntaxExtension
};
use
syntax
::
ext
::
expand
::{
Expansion
,
Invocation
,
InvocationKind
};
use
syntax
::
ext
::
hygiene
::
Mark
;
...
...
@@ -173,7 +173,8 @@ fn find_attr_invoc(&mut self, attrs: &mut Vec<ast::Attribute>) -> Option<ast::At
None
}
fn
resolve_invoc
(
&
mut
self
,
scope
:
Mark
,
invoc
:
&
Invocation
)
->
Option
<
Rc
<
SyntaxExtension
>>
{
fn
resolve_invoc
(
&
mut
self
,
scope
:
Mark
,
invoc
:
&
Invocation
,
_
force
:
bool
)
->
Result
<
Rc
<
SyntaxExtension
>
,
Determinacy
>
{
let
(
name
,
span
)
=
match
invoc
.kind
{
InvocationKind
::
Bang
{
ref
mac
,
..
}
=>
{
let
path
=
&
mac
.node.path
;
...
...
@@ -181,7 +182,7 @@ fn resolve_invoc(&mut self, scope: Mark, invoc: &Invocation) -> Option<Rc<Syntax
!
path
.segments
[
0
]
.parameters
.is_empty
()
{
self
.session
.span_err
(
path
.span
,
"expected macro name without module separators"
);
return
None
;
return
Err
(
Determinacy
::
Determined
)
;
}
(
path
.segments
[
0
]
.identifier.name
,
path
.span
)
}
...
...
@@ -192,12 +193,12 @@ fn resolve_invoc(&mut self, scope: Mark, invoc: &Invocation) -> Option<Rc<Syntax
if
let
LegacyScope
::
Expansion
(
parent
)
=
invocation
.legacy_scope
.get
()
{
invocation
.legacy_scope
.set
(
LegacyScope
::
simplify_expansion
(
parent
));
}
self
.resolve_macro_name
(
invocation
.legacy_scope
.get
(),
name
,
true
)
.or_else
(||
{
self
.resolve_macro_name
(
invocation
.legacy_scope
.get
(),
name
,
true
)
.o
k_o
r_else
(||
{
let
mut
err
=
self
.session
.struct_span_err
(
span
,
&
format!
(
"macro undefined: '{}!'"
,
name
));
self
.suggest_macro_name
(
&
name
.as_str
(),
&
mut
err
);
err
.emit
();
None
Determinacy
::
Determined
})
}
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
31e0e12e
...
...
@@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
self
::
Determinacy
::
*
;
use
self
::
ImportDirectiveSubclass
::
*
;
use
Module
;
...
...
@@ -26,6 +25,7 @@
use
rustc
::
hir
::
def
::
*
;
use
syntax
::
ast
::{
NodeId
,
Name
};
use
syntax
::
ext
::
base
::
Determinacy
::{
self
,
Determined
,
Undetermined
};
use
syntax
::
util
::
lev_distance
::
find_best_match_for_name
;
use
syntax_pos
::
Span
;
...
...
@@ -37,12 +37,6 @@ pub fn resolve_imports(&mut self) {
}
}
#[derive(Copy,
Clone,
Debug)]
pub
enum
Determinacy
{
Determined
,
Undetermined
,
}
/// Contains data for specific types of import directives.
#[derive(Clone,
Debug)]
pub
enum
ImportDirectiveSubclass
<
'a
>
{
...
...
src/libsyntax/ext/base.rs
浏览文件 @
31e0e12e
...
...
@@ -522,10 +522,17 @@ pub trait Resolver {
fn
add_expansions_at_stmt
(
&
mut
self
,
id
:
ast
::
NodeId
,
macros
:
Vec
<
Mark
>
);
fn
find_attr_invoc
(
&
mut
self
,
attrs
:
&
mut
Vec
<
Attribute
>
)
->
Option
<
Attribute
>
;
fn
resolve_invoc
(
&
mut
self
,
scope
:
Mark
,
invoc
:
&
Invocation
)
->
Option
<
Rc
<
SyntaxExtension
>>
;
fn
resolve_invoc
(
&
mut
self
,
scope
:
Mark
,
invoc
:
&
Invocation
,
force
:
bool
)
->
Result
<
Rc
<
SyntaxExtension
>
,
Determinacy
>
;
fn
resolve_derive_mode
(
&
mut
self
,
ident
:
ast
::
Ident
)
->
Option
<
Rc
<
MultiItemModifier
>>
;
}
#[derive(Copy,
Clone,
Debug)]
pub
enum
Determinacy
{
Determined
,
Undetermined
,
}
pub
struct
DummyResolver
;
impl
Resolver
for
DummyResolver
{
...
...
@@ -539,8 +546,9 @@ fn add_expansions_at_stmt(&mut self, _id: ast::NodeId, _macros: Vec<Mark>) {}
fn
find_attr_invoc
(
&
mut
self
,
_
attrs
:
&
mut
Vec
<
Attribute
>
)
->
Option
<
Attribute
>
{
None
}
fn
resolve_derive_mode
(
&
mut
self
,
_
ident
:
ast
::
Ident
)
->
Option
<
Rc
<
MultiItemModifier
>>
{
None
}
fn
resolve_invoc
(
&
mut
self
,
_
scope
:
Mark
,
_
invoc
:
&
Invocation
)
->
Option
<
Rc
<
SyntaxExtension
>>
{
None
fn
resolve_invoc
(
&
mut
self
,
_
scope
:
Mark
,
_
invoc
:
&
Invocation
,
_
force
:
bool
)
->
Result
<
Rc
<
SyntaxExtension
>
,
Determinacy
>
{
Err
(
Determinacy
::
Determined
)
}
}
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
31e0e12e
...
...
@@ -225,13 +225,36 @@ fn expand(&mut self, expansion: Expansion) -> Expansion {
invocations
.reverse
();
let
mut
expansions
=
Vec
::
new
();
while
let
Some
(
invoc
)
=
invocations
.pop
()
{
let
mut
undetermined_invocations
=
Vec
::
new
();
let
(
mut
progress
,
mut
force
)
=
(
false
,
!
self
.monotonic
);
loop
{
let
invoc
=
if
let
Some
(
invoc
)
=
invocations
.pop
()
{
invoc
}
else
if
undetermined_invocations
.is_empty
()
{
break
}
else
{
invocations
=
mem
::
replace
(
&
mut
undetermined_invocations
,
Vec
::
new
());
force
=
!
mem
::
replace
(
&
mut
progress
,
false
);
continue
};
let
scope
=
if
self
.monotonic
{
invoc
.expansion_data.mark
}
else
{
orig_expansion_data
.mark
};
let
ext
=
match
self
.cx.resolver
.resolve_invoc
(
scope
,
&
invoc
,
force
)
{
Ok
(
ext
)
=>
Some
(
ext
),
Err
(
Determinacy
::
Determined
)
=>
None
,
Err
(
Determinacy
::
Undetermined
)
=>
{
undetermined_invocations
.push
(
invoc
);
continue
}
};
progress
=
true
;
let
ExpansionData
{
depth
,
mark
,
..
}
=
invoc
.expansion_data
;
self
.cx.current_expansion
=
invoc
.expansion_data
.clone
();
let
scope
=
if
self
.monotonic
{
mark
}
else
{
orig_expansion_data
.mark
};
self
.cx.current_expansion.mark
=
scope
;
let
expansion
=
match
self
.cx.resolver
.resolve_invoc
(
scope
,
&
invoc
)
{
let
expansion
=
match
ext
{
Some
(
ext
)
=>
self
.expand_invoc
(
invoc
,
ext
),
None
=>
invoc
.expansion_kind
.dummy
(
invoc
.span
()),
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录