Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d26ae205
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,发现更多精彩内容 >>
提交
d26ae205
编写于
8月 29, 2018
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve: Rename some fields related to legacy macro scopes
上级
c057d579
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
60 addition
and
51 deletion
+60
-51
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+13
-11
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+47
-40
未找到文件。
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
d26ae205
...
...
@@ -950,7 +950,7 @@ fn legacy_macro_imports(&mut self, attrs: &[ast::Attribute]) -> LegacyMacroImpor
pub
struct
BuildReducedGraphVisitor
<
'a
,
'b
:
'a
,
'c
:
'b
>
{
pub
resolver
:
&
'a
mut
Resolver
<
'b
,
'c
>
,
pub
legacy_scope
:
LegacyScope
<
'b
>
,
pub
current_
legacy_scope
:
LegacyScope
<
'b
>
,
pub
expansion
:
Mark
,
}
...
...
@@ -960,7 +960,7 @@ fn visit_invoc(&mut self, id: ast::NodeId) -> &'b InvocationData<'b> {
self
.resolver.current_module.unresolved_invocations
.borrow_mut
()
.insert
(
mark
);
let
invocation
=
self
.resolver.invocations
[
&
mark
];
invocation
.module
.set
(
self
.resolver.current_module
);
invocation
.
legacy_scope
.set
(
self
.
legacy_scope
);
invocation
.
parent_legacy_scope
.set
(
self
.current_
legacy_scope
);
invocation
}
}
...
...
@@ -986,29 +986,30 @@ impl<'a, 'b, 'cl> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b, 'cl> {
fn
visit_item
(
&
mut
self
,
item
:
&
'a
Item
)
{
let
macro_use
=
match
item
.node
{
ItemKind
::
MacroDef
(
..
)
=>
{
self
.resolver
.define_macro
(
item
,
self
.expansion
,
&
mut
self
.legacy_scope
);
self
.resolver
.define_macro
(
item
,
self
.expansion
,
&
mut
self
.
current_
legacy_scope
);
return
}
ItemKind
::
Mac
(
..
)
=>
{
self
.legacy_scope
=
LegacyScope
::
Expansion
(
self
.visit_invoc
(
item
.id
));
self
.
current_
legacy_scope
=
LegacyScope
::
Expansion
(
self
.visit_invoc
(
item
.id
));
return
}
ItemKind
::
Mod
(
..
)
=>
self
.resolver
.contains_macro_use
(
&
item
.attrs
),
_
=>
false
,
};
let
(
parent
,
legacy_scope
)
=
(
self
.resolver.current_module
,
self
.legacy_scope
);
let
orig_current_module
=
self
.resolver.current_module
;
let
orig_current_legacy_scope
=
self
.current_legacy_scope
;
self
.resolver
.build_reduced_graph_for_item
(
item
,
self
.expansion
);
visit
::
walk_item
(
self
,
item
);
self
.resolver.current_module
=
parent
;
self
.resolver.current_module
=
orig_current_module
;
if
!
macro_use
{
self
.
legacy_scope
=
legacy_scope
;
self
.
current_legacy_scope
=
orig_current_
legacy_scope
;
}
}
fn
visit_stmt
(
&
mut
self
,
stmt
:
&
'a
ast
::
Stmt
)
{
if
let
ast
::
StmtKind
::
Mac
(
..
)
=
stmt
.node
{
self
.legacy_scope
=
LegacyScope
::
Expansion
(
self
.visit_invoc
(
stmt
.id
));
self
.
current_
legacy_scope
=
LegacyScope
::
Expansion
(
self
.visit_invoc
(
stmt
.id
));
}
else
{
visit
::
walk_stmt
(
self
,
stmt
);
}
...
...
@@ -1025,11 +1026,12 @@ fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) {
}
fn
visit_block
(
&
mut
self
,
block
:
&
'a
Block
)
{
let
(
parent
,
legacy_scope
)
=
(
self
.resolver.current_module
,
self
.legacy_scope
);
let
orig_current_module
=
self
.resolver.current_module
;
let
orig_current_legacy_scope
=
self
.current_legacy_scope
;
self
.resolver
.build_reduced_graph_for_block
(
block
,
self
.expansion
);
visit
::
walk_block
(
self
,
block
);
self
.resolver.current_module
=
parent
;
self
.
legacy_scope
=
legacy_scope
;
self
.resolver.current_module
=
orig_current_module
;
self
.
current_legacy_scope
=
orig_current_
legacy_scope
;
}
fn
visit_trait_item
(
&
mut
self
,
item
:
&
'a
TraitItem
)
{
...
...
src/librustc_resolve/macros.rs
浏览文件 @
d26ae205
...
...
@@ -50,13 +50,15 @@
#[derive(Clone)]
pub
struct
InvocationData
<
'a
>
{
pub
module
:
Cell
<
Module
<
'a
>>
,
pub
def_index
:
DefIndex
,
// The scope in which the invocation path is resolved.
pub
legacy_scope
:
Cell
<
LegacyScope
<
'a
>>
,
// The smallest scope that includes this invocation's expansion,
// or `Empty` if this invocation has not been expanded yet.
pub
expansion
:
Cell
<
LegacyScope
<
'a
>>
,
crate
module
:
Cell
<
Module
<
'a
>>
,
def_index
:
DefIndex
,
// Legacy scope in which the macro was invoked.
// The invocation path is resolved in this scope.
crate
parent_legacy_scope
:
Cell
<
LegacyScope
<
'a
>>
,
// Legacy scope *produced* by expanding this macro invocation,
// includes all the macro_rules items, other invocations, etc generated by it.
// `Empty` is used if for invocations that has not been expanded yet.
output_legacy_scope
:
Cell
<
LegacyScope
<
'a
>>
,
}
impl
<
'a
>
InvocationData
<
'a
>
{
...
...
@@ -64,12 +66,21 @@ pub fn root(graph_root: Module<'a>) -> Self {
InvocationData
{
module
:
Cell
::
new
(
graph_root
),
def_index
:
CRATE_DEF_INDEX
,
legacy_scope
:
Cell
::
new
(
LegacyScope
::
Empty
),
expansion
:
Cell
::
new
(
LegacyScope
::
Empty
),
parent_
legacy_scope
:
Cell
::
new
(
LegacyScope
::
Empty
),
output_legacy_scope
:
Cell
::
new
(
LegacyScope
::
Empty
),
}
}
}
// Binding produced by a `macro_rules` item.
// Not modularized, can shadow previous legacy bindings, etc.
pub
struct
LegacyBinding
<
'a
>
{
binding
:
&
'a
NameBinding
<
'a
>
,
// Legacy scope into which the `macro_rules` item was planted.
parent_legacy_scope
:
Cell
<
LegacyScope
<
'a
>>
,
ident
:
Ident
,
}
#[derive(Copy,
Clone)]
pub
enum
LegacyScope
<
'a
>
{
Empty
,
...
...
@@ -78,14 +89,6 @@ pub enum LegacyScope<'a> {
Binding
(
&
'a
LegacyBinding
<
'a
>
),
}
// Binding produced by a `macro_rules` item.
// Not modularized, can shadow previous legacy bindings, etc.
pub
struct
LegacyBinding
<
'a
>
{
binding
:
&
'a
NameBinding
<
'a
>
,
parent
:
Cell
<
LegacyScope
<
'a
>>
,
ident
:
Ident
,
}
pub
struct
ProcMacError
{
crate_name
:
Symbol
,
name
:
Symbol
,
...
...
@@ -105,8 +108,8 @@ fn get_module_scope(&mut self, id: ast::NodeId) -> Mark {
self
.invocations
.insert
(
mark
,
self
.arenas
.alloc_invocation_data
(
InvocationData
{
module
:
Cell
::
new
(
module
),
def_index
:
module
.def_id
()
.unwrap
()
.index
,
legacy_scope
:
Cell
::
new
(
LegacyScope
::
Empty
),
expansion
:
Cell
::
new
(
LegacyScope
::
Empty
),
parent_
legacy_scope
:
Cell
::
new
(
LegacyScope
::
Empty
),
output_legacy_scope
:
Cell
::
new
(
LegacyScope
::
Empty
),
}));
mark
}
...
...
@@ -178,11 +181,11 @@ fn visit_ast_fragment_with_placeholders(&mut self, mark: Mark, fragment: &AstFra
}
let
mut
visitor
=
BuildReducedGraphVisitor
{
resolver
:
self
,
legacy_scope
:
LegacyScope
::
Invocation
(
invocation
),
current_
legacy_scope
:
LegacyScope
::
Invocation
(
invocation
),
expansion
:
mark
,
};
fragment
.visit_with
(
&
mut
visitor
);
invocation
.
expansion
.set
(
visitor
.
legacy_scope
);
invocation
.
output_legacy_scope
.set
(
visitor
.current_
legacy_scope
);
}
fn
add_builtin
(
&
mut
self
,
ident
:
ast
::
Ident
,
ext
:
Lrc
<
SyntaxExtension
>
)
{
...
...
@@ -481,7 +484,7 @@ pub fn resolve_macro_to_def_inner(&mut self, path: &ast::Path, kind: MacroKind,
}
let
legacy_resolution
=
self
.resolve_legacy_scope
(
path
[
0
],
invoc_id
,
&
invocation
.legacy_scope
,
false
);
self
.resolve_legacy_scope
(
path
[
0
],
invoc_id
,
&
invocation
.
parent_
legacy_scope
,
false
);
let
result
=
if
let
Some
(
legacy_binding
)
=
legacy_resolution
{
Ok
(
legacy_binding
.def
())
}
else
{
...
...
@@ -814,18 +817,20 @@ fn resolve_legacy_scope(&mut self,
macro_rules!
continue_search
{
()
=>
{
where_to_resolve
=
match
where_to_resolve
.get
()
{
LegacyScope
::
Binding
(
binding
)
=>
&
binding
.parent
,
LegacyScope
::
Invocation
(
invocation
)
=>
&
invocation
.legacy_scope
,
LegacyScope
::
Expansion
(
invocation
)
=>
match
invocation
.expansion
.get
()
{
LegacyScope
::
Empty
=>
&
invocation
.legacy_scope
,
LegacyScope
::
Binding
(
..
)
|
LegacyScope
::
Expansion
(
..
)
=>
&
invocation
.expansion
,
LegacyScope
::
Invocation
(
..
)
=>
{
where_to_resolve
.set
(
invocation
.legacy_scope
.get
());
where_to_resolve
LegacyScope
::
Empty
=>
break
,
// nowhere else to search
LegacyScope
::
Binding
(
binding
)
=>
&
binding
.parent_legacy_scope
,
LegacyScope
::
Invocation
(
invocation
)
=>
&
invocation
.parent_legacy_scope
,
LegacyScope
::
Expansion
(
invocation
)
=>
{
match
invocation
.output_legacy_scope
.get
()
{
LegacyScope
::
Empty
=>
&
invocation
.parent_legacy_scope
,
LegacyScope
::
Binding
(
..
)
|
LegacyScope
::
Expansion
(
..
)
=>
&
invocation
.output_legacy_scope
,
LegacyScope
::
Invocation
(
..
)
=>
{
where_to_resolve
.set
(
invocation
.parent_legacy_scope
.get
());
where_to_resolve
}
}
}
LegacyScope
::
Empty
=>
break
,
// nowhere else to search
};
continue
;
...
...
@@ -880,8 +885,9 @@ pub fn finalize_current_module_macro_resolutions(&mut self) {
for
&
(
invoc_id
,
ident
,
kind
,
def
)
in
module
.legacy_macro_resolutions
.borrow
()
.iter
()
{
let
span
=
ident
.span
;
let
legacy_scope
=
&
self
.invocations
[
&
invoc_id
]
.legacy_scope
;
let
legacy_resolution
=
self
.resolve_legacy_scope
(
ident
,
invoc_id
,
legacy_scope
,
true
);
let
invoc_parent_legacy_scope
=
&
self
.invocations
[
&
invoc_id
]
.parent_legacy_scope
;
let
legacy_resolution
=
self
.resolve_legacy_scope
(
ident
,
invoc_id
,
invoc_parent_legacy_scope
,
true
);
let
resolution
=
self
.resolve_lexical_macro_path_segment
(
ident
,
MacroNS
,
invoc_id
,
true
,
true
,
kind
==
MacroKind
::
Attr
,
span
);
...
...
@@ -1007,8 +1013,8 @@ fn collect_def_ids(&mut self,
arenas
.alloc_invocation_data
(
InvocationData
{
def_index
:
invoc
.def_index
,
module
:
Cell
::
new
(
graph_root
),
expansion
:
Cell
::
new
(
LegacyScope
::
Empty
),
legacy_scope
:
Cell
::
new
(
LegacyScope
::
Empty
),
parent_legacy_scope
:
Cell
::
new
(
LegacyScope
::
Empty
),
output_
legacy_scope
:
Cell
::
new
(
LegacyScope
::
Empty
),
})
});
};
...
...
@@ -1023,7 +1029,7 @@ fn collect_def_ids(&mut self,
pub
fn
define_macro
(
&
mut
self
,
item
:
&
ast
::
Item
,
expansion
:
Mark
,
legacy_scope
:
&
mut
LegacyScope
<
'a
>
)
{
current_
legacy_scope
:
&
mut
LegacyScope
<
'a
>
)
{
self
.local_macro_def_scopes
.insert
(
item
.id
,
self
.current_module
);
let
ident
=
item
.ident
;
if
ident
.name
==
"macro_rules"
{
...
...
@@ -1043,9 +1049,10 @@ pub fn define_macro(&mut self,
let
def
=
Def
::
Macro
(
def_id
,
MacroKind
::
Bang
);
let
vis
=
ty
::
Visibility
::
Invisible
;
// Doesn't matter for legacy bindings
let
binding
=
(
def
,
vis
,
item
.span
,
expansion
)
.to_name_binding
(
self
.arenas
);
*
legacy_scope
=
LegacyScope
::
Binding
(
self
.arenas
.alloc_legacy_binding
(
LegacyBinding
{
parent
:
Cell
::
new
(
*
legacy_scope
),
binding
,
ident
}
));
let
legacy_binding
=
self
.arenas
.alloc_legacy_binding
(
LegacyBinding
{
parent_legacy_scope
:
Cell
::
new
(
*
current_legacy_scope
),
binding
,
ident
});
*
current_legacy_scope
=
LegacyScope
::
Binding
(
legacy_binding
);
self
.all_macros
.insert
(
ident
.name
,
def
);
if
attr
::
contains_name
(
&
item
.attrs
,
"macro_export"
)
{
let
module
=
self
.graph_root
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录