Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a1a338fa
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
a1a338fa
编写于
8月 22, 2018
作者:
V
varkor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename MapEntry to EntryKind
上级
70a21e89
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
159 addition
and
161 deletion
+159
-161
src/librustc/hir/map/collector.rs
src/librustc/hir/map/collector.rs
+25
-25
src/librustc/hir/map/mod.rs
src/librustc/hir/map/mod.rs
+134
-136
未找到文件。
src/librustc/hir/map/collector.rs
浏览文件 @
a1a338fa
...
...
@@ -29,7 +29,7 @@ pub(super) struct NodeCollector<'a, 'hir> {
/// The crate
krate
:
&
'hir
Crate
,
/// The node map
map
:
Vec
<
MapEntry
<
'hir
>>
,
map
:
Vec
<
EntryKind
<
'hir
>>
,
/// The parent of this node
parent_node
:
NodeId
,
...
...
@@ -114,7 +114,7 @@ pub(super) fn root(krate: &'hir Crate,
hcx
,
hir_body_nodes
,
};
collector
.insert_entry
(
CRATE_NODE_ID
,
RootCrate
(
root_mod_sig_dep_index
));
collector
.insert_entry
(
CRATE_NODE_ID
,
EntryKind
::
RootCrate
(
root_mod_sig_dep_index
));
collector
}
...
...
@@ -124,7 +124,7 @@ pub(super) fn finalize_and_compute_crate_hash(mut self,
cstore
:
&
dyn
CrateStore
,
source_map
:
&
SourceMap
,
commandline_args_hash
:
u64
)
->
(
Vec
<
MapEntry
<
'hir
>>
,
Svh
)
{
->
(
Vec
<
EntryKind
<
'hir
>>
,
Svh
)
{
self
.hir_body_nodes
.sort_unstable_by
(|
&
(
ref
d1
,
_
),
&
(
ref
d2
,
_
)|
d1
.cmp
(
d2
));
...
...
@@ -178,11 +178,11 @@ pub(super) fn finalize_and_compute_crate_hash(mut self,
(
self
.map
,
svh
)
}
fn
insert_entry
(
&
mut
self
,
id
:
NodeId
,
entry
:
MapEntry
<
'hir
>
)
{
fn
insert_entry
(
&
mut
self
,
id
:
NodeId
,
entry
:
EntryKind
<
'hir
>
)
{
debug!
(
"hir_map: {:?} => {:?}"
,
id
,
entry
);
let
len
=
self
.map
.len
();
if
id
.as_usize
()
>=
len
{
self
.map
.extend
(
repeat
(
NotPresent
)
.take
(
id
.as_usize
()
-
len
+
1
));
self
.map
.extend
(
repeat
(
EntryKind
::
NotPresent
)
.take
(
id
.as_usize
()
-
len
+
1
));
}
self
.map
[
id
.as_usize
()]
=
entry
;
}
...
...
@@ -196,26 +196,26 @@ fn insert(&mut self, id: NodeId, node: Node<'hir>) {
};
let
entry
=
match
node
{
NodeItem
(
n
)
=>
EntryItem
(
parent
,
dep_node_index
,
n
),
NodeForeignItem
(
n
)
=>
EntryForeignItem
(
parent
,
dep_node_index
,
n
),
NodeTraitItem
(
n
)
=>
EntryTraitItem
(
parent
,
dep_node_index
,
n
),
NodeImplItem
(
n
)
=>
EntryImplItem
(
parent
,
dep_node_index
,
n
),
NodeVariant
(
n
)
=>
EntryVariant
(
parent
,
dep_node_index
,
n
),
NodeField
(
n
)
=>
EntryField
(
parent
,
dep_node_index
,
n
),
NodeAnonConst
(
n
)
=>
EntryAnonConst
(
parent
,
dep_node_index
,
n
),
NodeExpr
(
n
)
=>
EntryExpr
(
parent
,
dep_node_index
,
n
),
NodeStmt
(
n
)
=>
EntryStmt
(
parent
,
dep_node_index
,
n
),
NodeTy
(
n
)
=>
EntryTy
(
parent
,
dep_node_index
,
n
),
NodeTraitRef
(
n
)
=>
EntryTraitRef
(
parent
,
dep_node_index
,
n
),
NodeBinding
(
n
)
=>
EntryBinding
(
parent
,
dep_node_index
,
n
),
NodePat
(
n
)
=>
EntryPat
(
parent
,
dep_node_index
,
n
),
NodeBlock
(
n
)
=>
EntryBlock
(
parent
,
dep_node_index
,
n
),
NodeStructCtor
(
n
)
=>
EntryStructCtor
(
parent
,
dep_node_index
,
n
),
NodeLifetime
(
n
)
=>
EntryLifetime
(
parent
,
dep_node_index
,
n
),
NodeGenericParam
(
n
)
=>
EntryGenericParam
(
parent
,
dep_node_index
,
n
),
NodeVisibility
(
n
)
=>
EntryVisibility
(
parent
,
dep_node_index
,
n
),
NodeLocal
(
n
)
=>
EntryLocal
(
parent
,
dep_node_index
,
n
),
NodeMacroDef
(
n
)
=>
EntryMacroDef
(
dep_node_index
,
n
),
NodeItem
(
n
)
=>
Entry
Kind
::
Item
(
parent
,
dep_node_index
,
n
),
NodeForeignItem
(
n
)
=>
Entry
Kind
::
ForeignItem
(
parent
,
dep_node_index
,
n
),
NodeTraitItem
(
n
)
=>
Entry
Kind
::
TraitItem
(
parent
,
dep_node_index
,
n
),
NodeImplItem
(
n
)
=>
Entry
Kind
::
ImplItem
(
parent
,
dep_node_index
,
n
),
NodeVariant
(
n
)
=>
Entry
Kind
::
Variant
(
parent
,
dep_node_index
,
n
),
NodeField
(
n
)
=>
Entry
Kind
::
Field
(
parent
,
dep_node_index
,
n
),
NodeAnonConst
(
n
)
=>
Entry
Kind
::
AnonConst
(
parent
,
dep_node_index
,
n
),
NodeExpr
(
n
)
=>
Entry
Kind
::
Expr
(
parent
,
dep_node_index
,
n
),
NodeStmt
(
n
)
=>
Entry
Kind
::
Stmt
(
parent
,
dep_node_index
,
n
),
NodeTy
(
n
)
=>
Entry
Kind
::
Ty
(
parent
,
dep_node_index
,
n
),
NodeTraitRef
(
n
)
=>
Entry
Kind
::
TraitRef
(
parent
,
dep_node_index
,
n
),
NodeBinding
(
n
)
=>
Entry
Kind
::
Binding
(
parent
,
dep_node_index
,
n
),
NodePat
(
n
)
=>
Entry
Kind
::
Pat
(
parent
,
dep_node_index
,
n
),
NodeBlock
(
n
)
=>
Entry
Kind
::
Block
(
parent
,
dep_node_index
,
n
),
NodeStructCtor
(
n
)
=>
Entry
Kind
::
StructCtor
(
parent
,
dep_node_index
,
n
),
NodeLifetime
(
n
)
=>
Entry
Kind
::
Lifetime
(
parent
,
dep_node_index
,
n
),
NodeGenericParam
(
n
)
=>
Entry
Kind
::
GenericParam
(
parent
,
dep_node_index
,
n
),
NodeVisibility
(
n
)
=>
Entry
Kind
::
Visibility
(
parent
,
dep_node_index
,
n
),
NodeLocal
(
n
)
=>
Entry
Kind
::
Local
(
parent
,
dep_node_index
,
n
),
NodeMacroDef
(
n
)
=>
Entry
Kind
::
MacroDef
(
dep_node_index
,
n
),
};
// Make sure that the DepNode of some node coincides with the HirId
...
...
src/librustc/hir/map/mod.rs
浏览文件 @
a1a338fa
...
...
@@ -9,7 +9,6 @@
// except according to those terms.
pub
use
self
::
Node
::
*
;
use
self
::
MapEntry
::
*
;
use
self
::
collector
::
NodeCollector
;
pub
use
self
::
def_collector
::{
DefCollector
,
MacroInvocationData
};
pub
use
self
::
definitions
::{
Definitions
,
DefKey
,
DefPath
,
DefPathData
,
...
...
@@ -76,125 +75,124 @@ pub enum Node<'hir> {
/// Represents an entry and its parent NodeID.
/// The odd layout is to bring down the total size.
#[derive(Copy,
Debug)]
enum
MapEntry
<
'hir
>
{
pub
enum
EntryKind
<
'hir
>
{
/// Placeholder for holes in the map.
NotPresent
,
/// All the node types, with a parent ID.
EntryItem
(
NodeId
,
DepNodeIndex
,
&
'hir
Item
),
EntryForeignItem
(
NodeId
,
DepNodeIndex
,
&
'hir
ForeignItem
),
EntryTraitItem
(
NodeId
,
DepNodeIndex
,
&
'hir
TraitItem
),
EntryImplItem
(
NodeId
,
DepNodeIndex
,
&
'hir
ImplItem
),
EntryVariant
(
NodeId
,
DepNodeIndex
,
&
'hir
Variant
),
EntryField
(
NodeId
,
DepNodeIndex
,
&
'hir
StructField
),
EntryAnonConst
(
NodeId
,
DepNodeIndex
,
&
'hir
AnonConst
),
EntryExpr
(
NodeId
,
DepNodeIndex
,
&
'hir
Expr
),
EntryStmt
(
NodeId
,
DepNodeIndex
,
&
'hir
Stmt
),
EntryTy
(
NodeId
,
DepNodeIndex
,
&
'hir
Ty
),
EntryTraitRef
(
NodeId
,
DepNodeIndex
,
&
'hir
TraitRef
),
EntryBinding
(
NodeId
,
DepNodeIndex
,
&
'hir
Pat
),
EntryPat
(
NodeId
,
DepNodeIndex
,
&
'hir
Pat
),
EntryBlock
(
NodeId
,
DepNodeIndex
,
&
'hir
Block
),
EntryStructCtor
(
NodeId
,
DepNodeIndex
,
&
'hir
VariantData
),
EntryLifetime
(
NodeId
,
DepNodeIndex
,
&
'hir
Lifetime
),
EntryGenericParam
(
NodeId
,
DepNodeIndex
,
&
'hir
GenericParam
),
EntryVisibility
(
NodeId
,
DepNodeIndex
,
&
'hir
Visibility
),
EntryLocal
(
NodeId
,
DepNodeIndex
,
&
'hir
Local
),
EntryMacroDef
(
DepNodeIndex
,
&
'hir
MacroDef
),
Item
(
NodeId
,
DepNodeIndex
,
&
'hir
Item
),
ForeignItem
(
NodeId
,
DepNodeIndex
,
&
'hir
ForeignItem
),
TraitItem
(
NodeId
,
DepNodeIndex
,
&
'hir
TraitItem
),
ImplItem
(
NodeId
,
DepNodeIndex
,
&
'hir
ImplItem
),
Variant
(
NodeId
,
DepNodeIndex
,
&
'hir
Variant
),
Field
(
NodeId
,
DepNodeIndex
,
&
'hir
StructField
),
AnonConst
(
NodeId
,
DepNodeIndex
,
&
'hir
AnonConst
),
Expr
(
NodeId
,
DepNodeIndex
,
&
'hir
Expr
),
Stmt
(
NodeId
,
DepNodeIndex
,
&
'hir
Stmt
),
Ty
(
NodeId
,
DepNodeIndex
,
&
'hir
Ty
),
TraitRef
(
NodeId
,
DepNodeIndex
,
&
'hir
TraitRef
),
Binding
(
NodeId
,
DepNodeIndex
,
&
'hir
Pat
),
Pat
(
NodeId
,
DepNodeIndex
,
&
'hir
Pat
),
Block
(
NodeId
,
DepNodeIndex
,
&
'hir
Block
),
StructCtor
(
NodeId
,
DepNodeIndex
,
&
'hir
VariantData
),
Lifetime
(
NodeId
,
DepNodeIndex
,
&
'hir
Lifetime
),
GenericParam
(
NodeId
,
DepNodeIndex
,
&
'hir
GenericParam
),
Visibility
(
NodeId
,
DepNodeIndex
,
&
'hir
Visibility
),
Local
(
NodeId
,
DepNodeIndex
,
&
'hir
Local
),
MacroDef
(
DepNodeIndex
,
&
'hir
MacroDef
),
/// Roots for node trees. The DepNodeIndex is the dependency node of the
/// crate's root module.
RootCrate
(
DepNodeIndex
),
}
impl
<
'hir
>
Clone
for
MapEntry
<
'hir
>
{
fn
clone
(
&
self
)
->
MapEntry
<
'hir
>
{
impl
<
'hir
>
Clone
for
EntryKind
<
'hir
>
{
fn
clone
(
&
self
)
->
EntryKind
<
'hir
>
{
*
self
}
}
impl
<
'hir
>
MapEntry
<
'hir
>
{
impl
<
'hir
>
EntryKind
<
'hir
>
{
fn
parent_node
(
self
)
->
Option
<
NodeId
>
{
Some
(
match
self
{
EntryItem
(
id
,
_
,
_
)
=>
id
,
EntryForeignItem
(
id
,
_
,
_
)
=>
id
,
EntryTraitItem
(
id
,
_
,
_
)
=>
id
,
EntryImplItem
(
id
,
_
,
_
)
=>
id
,
EntryVariant
(
id
,
_
,
_
)
=>
id
,
EntryField
(
id
,
_
,
_
)
=>
id
,
EntryAnonConst
(
id
,
_
,
_
)
=>
id
,
EntryExpr
(
id
,
_
,
_
)
=>
id
,
EntryStmt
(
id
,
_
,
_
)
=>
id
,
EntryTy
(
id
,
_
,
_
)
=>
id
,
EntryTraitRef
(
id
,
_
,
_
)
=>
id
,
EntryBinding
(
id
,
_
,
_
)
=>
id
,
EntryPat
(
id
,
_
,
_
)
=>
id
,
EntryBlock
(
id
,
_
,
_
)
=>
id
,
EntryStructCtor
(
id
,
_
,
_
)
=>
id
,
EntryLifetime
(
id
,
_
,
_
)
=>
id
,
EntryGenericParam
(
id
,
_
,
_
)
=>
id
,
EntryVisibility
(
id
,
_
,
_
)
=>
id
,
EntryLocal
(
id
,
_
,
_
)
=>
id
,
NotPresent
|
EntryMacroDef
(
..
)
|
RootCrate
(
_
)
=>
return
None
,
Entry
Kind
::
Item
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
ForeignItem
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
TraitItem
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
ImplItem
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
Variant
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
Field
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
AnonConst
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
Expr
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
Stmt
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
Ty
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
TraitRef
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
Binding
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
Pat
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
Block
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
StructCtor
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
Lifetime
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
GenericParam
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
Visibility
(
id
,
_
,
_
)
=>
id
,
Entry
Kind
::
Local
(
id
,
_
,
_
)
=>
id
,
EntryKind
::
NotPresent
|
Entry
Kind
::
MacroDef
(
..
)
|
EntryKind
::
RootCrate
(
_
)
=>
return
None
,
})
}
fn
to_node
(
self
)
->
Option
<
Node
<
'hir
>>
{
Some
(
match
self
{
EntryItem
(
_
,
_
,
n
)
=>
NodeItem
(
n
),
EntryForeignItem
(
_
,
_
,
n
)
=>
NodeForeignItem
(
n
),
EntryTraitItem
(
_
,
_
,
n
)
=>
NodeTraitItem
(
n
),
EntryImplItem
(
_
,
_
,
n
)
=>
NodeImplItem
(
n
),
EntryVariant
(
_
,
_
,
n
)
=>
NodeVariant
(
n
),
EntryField
(
_
,
_
,
n
)
=>
NodeField
(
n
),
EntryAnonConst
(
_
,
_
,
n
)
=>
NodeAnonConst
(
n
),
EntryExpr
(
_
,
_
,
n
)
=>
NodeExpr
(
n
),
EntryStmt
(
_
,
_
,
n
)
=>
NodeStmt
(
n
),
EntryTy
(
_
,
_
,
n
)
=>
NodeTy
(
n
),
EntryTraitRef
(
_
,
_
,
n
)
=>
NodeTraitRef
(
n
),
EntryBinding
(
_
,
_
,
n
)
=>
NodeBinding
(
n
),
EntryPat
(
_
,
_
,
n
)
=>
NodePat
(
n
),
EntryBlock
(
_
,
_
,
n
)
=>
NodeBlock
(
n
),
EntryStructCtor
(
_
,
_
,
n
)
=>
NodeStructCtor
(
n
),
EntryLifetime
(
_
,
_
,
n
)
=>
NodeLifetime
(
n
),
EntryGenericParam
(
_
,
_
,
n
)
=>
NodeGenericParam
(
n
),
EntryVisibility
(
_
,
_
,
n
)
=>
NodeVisibility
(
n
),
EntryLocal
(
_
,
_
,
n
)
=>
NodeLocal
(
n
),
EntryMacroDef
(
_
,
n
)
=>
NodeMacroDef
(
n
),
NotPresent
|
RootCrate
(
_
)
=>
return
None
Entry
Kind
::
Item
(
_
,
_
,
n
)
=>
NodeItem
(
n
),
Entry
Kind
::
ForeignItem
(
_
,
_
,
n
)
=>
NodeForeignItem
(
n
),
Entry
Kind
::
TraitItem
(
_
,
_
,
n
)
=>
NodeTraitItem
(
n
),
Entry
Kind
::
ImplItem
(
_
,
_
,
n
)
=>
NodeImplItem
(
n
),
Entry
Kind
::
Variant
(
_
,
_
,
n
)
=>
NodeVariant
(
n
),
Entry
Kind
::
Field
(
_
,
_
,
n
)
=>
NodeField
(
n
),
Entry
Kind
::
AnonConst
(
_
,
_
,
n
)
=>
NodeAnonConst
(
n
),
Entry
Kind
::
Expr
(
_
,
_
,
n
)
=>
NodeExpr
(
n
),
Entry
Kind
::
Stmt
(
_
,
_
,
n
)
=>
NodeStmt
(
n
),
Entry
Kind
::
Ty
(
_
,
_
,
n
)
=>
NodeTy
(
n
),
Entry
Kind
::
TraitRef
(
_
,
_
,
n
)
=>
NodeTraitRef
(
n
),
Entry
Kind
::
Binding
(
_
,
_
,
n
)
=>
NodeBinding
(
n
),
Entry
Kind
::
Pat
(
_
,
_
,
n
)
=>
NodePat
(
n
),
Entry
Kind
::
Block
(
_
,
_
,
n
)
=>
NodeBlock
(
n
),
Entry
Kind
::
StructCtor
(
_
,
_
,
n
)
=>
NodeStructCtor
(
n
),
Entry
Kind
::
Lifetime
(
_
,
_
,
n
)
=>
NodeLifetime
(
n
),
Entry
Kind
::
GenericParam
(
_
,
_
,
n
)
=>
NodeGenericParam
(
n
),
Entry
Kind
::
Visibility
(
_
,
_
,
n
)
=>
NodeVisibility
(
n
),
Entry
Kind
::
Local
(
_
,
_
,
n
)
=>
NodeLocal
(
n
),
Entry
Kind
::
MacroDef
(
_
,
n
)
=>
NodeMacroDef
(
n
),
EntryKind
::
NotPresent
|
EntryKind
::
RootCrate
(
_
)
=>
return
None
})
}
fn
fn_decl
(
&
self
)
->
Option
<&
FnDecl
>
{
match
self
{
EntryItem
(
_
,
_
,
ref
item
)
=>
{
Entry
Kind
::
Item
(
_
,
_
,
ref
item
)
=>
{
match
item
.node
{
ItemKind
::
Fn
(
ref
fn_decl
,
_
,
_
,
_
)
=>
Some
(
&
fn_decl
),
_
=>
None
,
}
}
EntryTraitItem
(
_
,
_
,
ref
item
)
=>
{
Entry
Kind
::
TraitItem
(
_
,
_
,
ref
item
)
=>
{
match
item
.node
{
TraitItemKind
::
Method
(
ref
method_sig
,
_
)
=>
Some
(
&
method_sig
.decl
),
_
=>
None
}
}
EntryImplItem
(
_
,
_
,
ref
item
)
=>
{
Entry
Kind
::
ImplItem
(
_
,
_
,
ref
item
)
=>
{
match
item
.node
{
ImplItemKind
::
Method
(
ref
method_sig
,
_
)
=>
Some
(
&
method_sig
.decl
),
_
=>
None
,
}
}
EntryExpr
(
_
,
_
,
ref
expr
)
=>
{
Entry
Kind
::
Expr
(
_
,
_
,
ref
expr
)
=>
{
match
expr
.node
{
ExprKind
::
Closure
(
_
,
ref
fn_decl
,
..
)
=>
Some
(
&
fn_decl
),
_
=>
None
,
...
...
@@ -207,7 +205,7 @@ fn fn_decl(&self) -> Option<&FnDecl> {
fn
associated_body
(
self
)
->
Option
<
BodyId
>
{
match
self
{
EntryItem
(
_
,
_
,
item
)
=>
{
Entry
Kind
::
Item
(
_
,
_
,
item
)
=>
{
match
item
.node
{
ItemKind
::
Const
(
_
,
body
)
|
ItemKind
::
Static
(
..
,
body
)
|
...
...
@@ -216,7 +214,7 @@ fn associated_body(self) -> Option<BodyId> {
}
}
EntryTraitItem
(
_
,
_
,
item
)
=>
{
Entry
Kind
::
TraitItem
(
_
,
_
,
item
)
=>
{
match
item
.node
{
TraitItemKind
::
Const
(
_
,
Some
(
body
))
|
TraitItemKind
::
Method
(
_
,
TraitMethod
::
Provided
(
body
))
=>
Some
(
body
),
...
...
@@ -224,7 +222,7 @@ fn associated_body(self) -> Option<BodyId> {
}
}
EntryImplItem
(
_
,
_
,
item
)
=>
{
Entry
Kind
::
ImplItem
(
_
,
_
,
item
)
=>
{
match
item
.node
{
ImplItemKind
::
Const
(
_
,
body
)
|
ImplItemKind
::
Method
(
_
,
body
)
=>
Some
(
body
),
...
...
@@ -232,9 +230,9 @@ fn associated_body(self) -> Option<BodyId> {
}
}
EntryAnonConst
(
_
,
_
,
constant
)
=>
Some
(
constant
.body
),
Entry
Kind
::
AnonConst
(
_
,
_
,
constant
)
=>
Some
(
constant
.body
),
EntryExpr
(
_
,
_
,
expr
)
=>
{
Entry
Kind
::
Expr
(
_
,
_
,
expr
)
=>
{
match
expr
.node
{
ExprKind
::
Closure
(
..
,
body
,
_
,
_
)
=>
Some
(
body
),
_
=>
None
,
...
...
@@ -296,7 +294,7 @@ pub struct Map<'hir> {
///
/// Also, indexing is pretty quick when you've got a vector and
/// plain old integers.
map
:
Vec
<
MapEntry
<
'hir
>>
,
map
:
Vec
<
EntryKind
<
'hir
>>
,
definitions
:
&
'hir
Definitions
,
...
...
@@ -315,30 +313,30 @@ impl<'hir> Map<'hir> {
pub
fn
read
(
&
self
,
id
:
NodeId
)
{
let
entry
=
self
.map
[
id
.as_usize
()];
match
entry
{
EntryItem
(
_
,
dep_node_index
,
_
)
|
EntryTraitItem
(
_
,
dep_node_index
,
_
)
|
EntryImplItem
(
_
,
dep_node_index
,
_
)
|
EntryVariant
(
_
,
dep_node_index
,
_
)
|
EntryForeignItem
(
_
,
dep_node_index
,
_
)
|
EntryField
(
_
,
dep_node_index
,
_
)
|
EntryStmt
(
_
,
dep_node_index
,
_
)
|
EntryTy
(
_
,
dep_node_index
,
_
)
|
EntryTraitRef
(
_
,
dep_node_index
,
_
)
|
EntryBinding
(
_
,
dep_node_index
,
_
)
|
EntryPat
(
_
,
dep_node_index
,
_
)
|
EntryBlock
(
_
,
dep_node_index
,
_
)
|
EntryStructCtor
(
_
,
dep_node_index
,
_
)
|
EntryLifetime
(
_
,
dep_node_index
,
_
)
|
EntryGenericParam
(
_
,
dep_node_index
,
_
)
|
EntryVisibility
(
_
,
dep_node_index
,
_
)
|
EntryAnonConst
(
_
,
dep_node_index
,
_
)
|
EntryExpr
(
_
,
dep_node_index
,
_
)
|
EntryLocal
(
_
,
dep_node_index
,
_
)
|
EntryMacroDef
(
dep_node_index
,
_
)
|
RootCrate
(
dep_node_index
)
=>
{
Entry
Kind
::
Item
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
TraitItem
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
ImplItem
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
Variant
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
ForeignItem
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
Field
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
Stmt
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
Ty
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
TraitRef
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
Binding
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
Pat
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
Block
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
StructCtor
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
Lifetime
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
GenericParam
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
Visibility
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
AnonConst
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
Expr
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
Local
(
_
,
dep_node_index
,
_
)
|
Entry
Kind
::
MacroDef
(
dep_node_index
,
_
)
|
EntryKind
::
RootCrate
(
dep_node_index
)
=>
{
self
.dep_graph
.read_index
(
dep_node_index
);
}
NotPresent
=>
{
EntryKind
::
NotPresent
=>
{
bug!
(
"called HirMap::read() with invalid NodeId"
)
}
}
...
...
@@ -509,7 +507,7 @@ fn entry_count(&self) -> usize {
self
.map
.len
()
}
fn
find_entry
(
&
self
,
id
:
NodeId
)
->
Option
<
MapEntry
<
'hir
>>
{
fn
find_entry
(
&
self
,
id
:
NodeId
)
->
Option
<
EntryKind
<
'hir
>>
{
self
.map
.get
(
id
.as_usize
())
.cloned
()
}
...
...
@@ -892,7 +890,7 @@ pub fn get_parent_did(&self, id: NodeId) -> DefId {
pub
fn
get_foreign_abi
(
&
self
,
id
:
NodeId
)
->
Abi
{
let
parent
=
self
.get_parent
(
id
);
let
abi
=
match
self
.find_entry
(
parent
)
{
Some
(
EntryItem
(
_
,
_
,
i
))
=>
{
Some
(
Entry
Kind
::
Item
(
_
,
_
,
i
))
=>
{
match
i
.node
{
ItemKind
::
ForeignMod
(
ref
nm
)
=>
Some
(
nm
.abi
),
_
=>
None
...
...
@@ -1034,32 +1032,32 @@ pub fn nodes_matching_suffix<'a>(&'a self, parts: &'a [String])
pub
fn
span
(
&
self
,
id
:
NodeId
)
->
Span
{
self
.read
(
id
);
// reveals span from node
match
self
.find_entry
(
id
)
{
Some
(
EntryItem
(
_
,
_
,
item
))
=>
item
.span
,
Some
(
EntryForeignItem
(
_
,
_
,
foreign_item
))
=>
foreign_item
.span
,
Some
(
EntryTraitItem
(
_
,
_
,
trait_method
))
=>
trait_method
.span
,
Some
(
EntryImplItem
(
_
,
_
,
impl_item
))
=>
impl_item
.span
,
Some
(
EntryVariant
(
_
,
_
,
variant
))
=>
variant
.span
,
Some
(
EntryField
(
_
,
_
,
field
))
=>
field
.span
,
Some
(
EntryAnonConst
(
_
,
_
,
constant
))
=>
self
.body
(
constant
.body
)
.value.span
,
Some
(
EntryExpr
(
_
,
_
,
expr
))
=>
expr
.span
,
Some
(
EntryStmt
(
_
,
_
,
stmt
))
=>
stmt
.span
,
Some
(
EntryTy
(
_
,
_
,
ty
))
=>
ty
.span
,
Some
(
EntryTraitRef
(
_
,
_
,
tr
))
=>
tr
.path.span
,
Some
(
EntryBinding
(
_
,
_
,
pat
))
=>
pat
.span
,
Some
(
EntryPat
(
_
,
_
,
pat
))
=>
pat
.span
,
Some
(
EntryBlock
(
_
,
_
,
block
))
=>
block
.span
,
Some
(
EntryStructCtor
(
_
,
_
,
_
))
=>
self
.expect_item
(
self
.get_parent
(
id
))
.span
,
Some
(
EntryLifetime
(
_
,
_
,
lifetime
))
=>
lifetime
.span
,
Some
(
EntryGenericParam
(
_
,
_
,
param
))
=>
param
.span
,
Some
(
EntryVisibility
(
_
,
_
,
&
Spanned
{
Some
(
Entry
Kind
::
Item
(
_
,
_
,
item
))
=>
item
.span
,
Some
(
Entry
Kind
::
ForeignItem
(
_
,
_
,
foreign_item
))
=>
foreign_item
.span
,
Some
(
Entry
Kind
::
TraitItem
(
_
,
_
,
trait_method
))
=>
trait_method
.span
,
Some
(
Entry
Kind
::
ImplItem
(
_
,
_
,
impl_item
))
=>
impl_item
.span
,
Some
(
Entry
Kind
::
Variant
(
_
,
_
,
variant
))
=>
variant
.span
,
Some
(
Entry
Kind
::
Field
(
_
,
_
,
field
))
=>
field
.span
,
Some
(
Entry
Kind
::
AnonConst
(
_
,
_
,
constant
))
=>
self
.body
(
constant
.body
)
.value.span
,
Some
(
Entry
Kind
::
Expr
(
_
,
_
,
expr
))
=>
expr
.span
,
Some
(
Entry
Kind
::
Stmt
(
_
,
_
,
stmt
))
=>
stmt
.span
,
Some
(
Entry
Kind
::
Ty
(
_
,
_
,
ty
))
=>
ty
.span
,
Some
(
Entry
Kind
::
TraitRef
(
_
,
_
,
tr
))
=>
tr
.path.span
,
Some
(
Entry
Kind
::
Binding
(
_
,
_
,
pat
))
=>
pat
.span
,
Some
(
Entry
Kind
::
Pat
(
_
,
_
,
pat
))
=>
pat
.span
,
Some
(
Entry
Kind
::
Block
(
_
,
_
,
block
))
=>
block
.span
,
Some
(
Entry
Kind
::
StructCtor
(
_
,
_
,
_
))
=>
self
.expect_item
(
self
.get_parent
(
id
))
.span
,
Some
(
Entry
Kind
::
Lifetime
(
_
,
_
,
lifetime
))
=>
lifetime
.span
,
Some
(
Entry
Kind
::
GenericParam
(
_
,
_
,
param
))
=>
param
.span
,
Some
(
Entry
Kind
::
Visibility
(
_
,
_
,
&
Spanned
{
node
:
VisibilityKind
::
Restricted
{
ref
path
,
..
},
..
}))
=>
path
.span
,
Some
(
EntryVisibility
(
_
,
_
,
v
))
=>
bug!
(
"unexpected Visibility {:?}"
,
v
),
Some
(
EntryLocal
(
_
,
_
,
local
))
=>
local
.span
,
Some
(
EntryMacroDef
(
_
,
macro_def
))
=>
macro_def
.span
,
Some
(
Entry
Kind
::
Visibility
(
_
,
_
,
v
))
=>
bug!
(
"unexpected Visibility {:?}"
,
v
),
Some
(
Entry
Kind
::
Local
(
_
,
_
,
local
))
=>
local
.span
,
Some
(
Entry
Kind
::
MacroDef
(
_
,
macro_def
))
=>
macro_def
.span
,
Some
(
RootCrate
(
_
))
=>
self
.forest.krate.span
,
Some
(
NotPresent
)
|
None
=>
{
Some
(
EntryKind
::
RootCrate
(
_
))
=>
self
.forest.krate.span
,
Some
(
EntryKind
::
NotPresent
)
|
None
=>
{
bug!
(
"hir::map::Map::span: id not in map: {:?}"
,
id
)
}
}
...
...
@@ -1155,12 +1153,12 @@ fn next(&mut self) -> Option<NodeId> {
}
self
.idx
=
NodeId
::
from_u32
(
self
.idx
.as_u32
()
+
1
);
let
name
=
match
self
.map
.find_entry
(
idx
)
{
Some
(
EntryItem
(
_
,
_
,
n
))
=>
n
.name
(),
Some
(
EntryForeignItem
(
_
,
_
,
n
))
=>
n
.name
(),
Some
(
EntryTraitItem
(
_
,
_
,
n
))
=>
n
.name
(),
Some
(
EntryImplItem
(
_
,
_
,
n
))
=>
n
.name
(),
Some
(
EntryVariant
(
_
,
_
,
n
))
=>
n
.name
(),
Some
(
EntryField
(
_
,
_
,
n
))
=>
n
.name
(),
Some
(
Entry
Kind
::
Item
(
_
,
_
,
n
))
=>
n
.name
(),
Some
(
Entry
Kind
::
ForeignItem
(
_
,
_
,
n
))
=>
n
.name
(),
Some
(
Entry
Kind
::
TraitItem
(
_
,
_
,
n
))
=>
n
.name
(),
Some
(
Entry
Kind
::
ImplItem
(
_
,
_
,
n
))
=>
n
.name
(),
Some
(
Entry
Kind
::
Variant
(
_
,
_
,
n
))
=>
n
.name
(),
Some
(
Entry
Kind
::
Field
(
_
,
_
,
n
))
=>
n
.name
(),
_
=>
continue
,
};
if
self
.matches_names
(
self
.map
.get_parent
(
idx
),
name
)
{
...
...
@@ -1211,7 +1209,7 @@ pub fn map_crate<'hir>(sess: &::session::Session,
// enumerate to count the number of entries.
let
(
entries_less_1
,
_
)
=
map
.iter
()
.filter
(|
&
x
|
{
match
*
x
{
NotPresent
=>
false
,
EntryKind
::
NotPresent
=>
false
,
_
=>
true
}
})
.enumerate
()
.last
()
.expect
(
"AST map was empty after folding?"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录