Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
6dc45233
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,发现更多精彩内容 >>
提交
6dc45233
编写于
4月 01, 2011
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: Get tag variants from the crate metadata
上级
ec9d7abf
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
78 addition
and
16 deletion
+78
-16
src/comp/front/creader.rs
src/comp/front/creader.rs
+49
-6
src/comp/middle/metadata.rs
src/comp/middle/metadata.rs
+24
-9
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+4
-1
src/comp/rustc.rc
src/comp/rustc.rc
+1
-0
未找到文件。
src/comp/front/creader.rs
浏览文件 @
6dc45233
...
...
@@ -8,6 +8,7 @@
import
lib
.llvm.mk_section_iter
;
import
middle
.fold
;
import
middle
.metadata
;
import
middle
.trans
;
import
middle
.ty
;
import
back
.x86
;
import
util
.common
;
...
...
@@ -324,7 +325,8 @@ fn parse_def_id(vec[u8] buf) -> ast.def_id {
auto
eqer
=
bind
eq_item
(
_
,
item_id
);
auto
hash
=
metadata
.hash_def_num
(
item_id
);
ebml
.move_to_sibling_with_id
(
ebml_r
,
metadata
.tag_items
);
lookup_hash_entry
(
ebml_r
,
eqer
,
hash
);
auto
found
=
lookup_hash_entry
(
ebml_r
,
eqer
,
hash
);
check
(
found
);
}
// Looks up an item in the given metadata and returns an EBML reader pointing
...
...
@@ -409,17 +411,17 @@ fn parse_external_def_id(int this_cnum, str s) -> ast.def_id {
ret
get_item_generic
[
@
ty
.t
](
ebml_r
,
metadata
.tag_items_data_item_type
,
f
);
}
impure
fn
get_item_ty_params
(
&
ebml
.reader
ebml_r
,
int
this_cnum
)
impure
fn
collect_def_ids
(
&
ebml
.reader
ebml_r
,
int
this_cnum
,
uint
tag_id
)
->
vec
[
ast
.def_id
]
{
let
vec
[
ast
.def_id
]
tp
s
=
vec
();
let
vec
[
ast
.def_id
]
def_id
s
=
vec
();
while
(
ebml
.bytes_left
(
ebml_r
)
>
0u
)
{
auto
ebml_tag
=
ebml
.peek
(
ebml_r
);
if
(
ebml_tag
.id
==
metadata
.tag_items_data_item_ty_param
)
{
if
(
ebml_tag
.id
==
tag_id
)
{
ebml
.move_to_first_child
(
ebml_r
);
auto
data
=
ebml
.read_data
(
ebml_r
);
auto
external_def_id
=
parse_def_id
(
data
);
tp
s
+=
vec
(
tup
(
this_cnum
,
external_def_id
._1
));
def_id
s
+=
vec
(
tup
(
this_cnum
,
external_def_id
._1
));
ebml
.move_to_parent
(
ebml_r
);
}
...
...
@@ -430,7 +432,19 @@ fn parse_external_def_id(int this_cnum, str s) -> ast.def_id {
ebml
.move_to_parent
(
ebml_r
);
ebml
.move_to_first_child
(
ebml_r
);
ret
tps
;
ret
def_ids
;
}
impure
fn
get_item_ty_params
(
&
ebml
.reader
ebml_r
,
int
this_cnum
)
->
vec
[
ast
.def_id
]
{
ret
collect_def_ids
(
ebml_r
,
this_cnum
,
metadata
.tag_items_data_item_ty_param
);
}
impure
fn
collect_tag_variant_ids
(
&
ebml
.reader
ebml_r
,
int
this_cnum
)
->
vec
[
ast
.def_id
]
{
ret
collect_def_ids
(
ebml_r
,
this_cnum
,
metadata
.tag_items_data_item_variant
);
}
...
...
@@ -590,6 +604,35 @@ fn get_symbol(session.session sess, ast.def_id def) -> str {
ret
get_item_symbol
(
ebml_r
);
}
fn
get_tag_variants
(
session
.session
sess
,
ast
.def_id
def
)
->
vec
[
trans
.variant_info
]
{
auto
external_crate_id
=
def
._0
;
auto
data
=
sess
.get_external_crate
(
external_crate_id
);
auto
ebml_r
=
lookup_item
(
def
._1
,
data
);
let
vec
[
trans
.variant_info
]
infos
=
vec
();
auto
variant_ids
=
collect_tag_variant_ids
(
ebml_r
,
external_crate_id
);
for
(
ast
.def_id
did
in
variant_ids
)
{
ebml
.reset_reader
(
ebml_r
,
0u
);
move_to_item
(
ebml_r
,
did
._1
);
auto
ctor_ty
=
get_item_type
(
ebml_r
,
external_crate_id
);
let
vec
[
@
ty
.t
]
arg_tys
=
vec
();
alt
(
ctor_ty
.struct
)
{
case
(
ty
.ty_fn
(
_
,
?
args
,
_
))
{
for
(
ty
.arg
a
in
args
)
{
arg_tys
+=
vec
(
a
.ty
);
}
}
case
(
_
)
{
// Nullary tag variant.
}
}
infos
+=
vec
(
rec
(
args
=
arg_tys
,
ctor_ty
=
ctor_ty
,
id
=
did
));
}
ret
infos
;
}
// Local Variables:
// mode: rust
// fill-column: 78;
...
...
src/comp/middle/metadata.rs
浏览文件 @
6dc45233
...
...
@@ -176,8 +176,12 @@ fn encode_def_id(&ebml.writer ebml_w, &ast.def_id id) {
ebml
.end_tag
(
ebml_w
);
}
fn
encode_tag_variant_paths
(
&
ebml
.writer
ebml_w
,
vec
[
ast
.variant
]
variants
)
{
fn
encode_tag_variant_paths
(
&
ebml
.writer
ebml_w
,
vec
[
ast
.variant
]
variants
,
vec
[
str
]
path
,
&
mutable
vec
[
tup
(
str
,
uint
)]
index
)
{
for
(
ast
.variant
variant
in
variants
)
{
add_to_index
(
ebml_w
,
path
,
index
,
variant
.node.name
);
ebml
.start_tag
(
ebml_w
,
tag_paths_data_item
);
encode_name
(
ebml_w
,
variant
.node.name
);
encode_def_id
(
ebml_w
,
variant
.node.id
);
...
...
@@ -266,9 +270,10 @@ fn encode_module_item_paths(&ebml.writer ebml_w,
add_to_index
(
ebml_w
,
path
,
index
,
id
);
ebml
.start_tag
(
ebml_w
,
tag_paths_data_item
);
encode_name
(
ebml_w
,
id
);
encode_tag_variant_paths
(
ebml_w
,
variants
);
encode_def_id
(
ebml_w
,
did
);
ebml
.end_tag
(
ebml_w
);
encode_tag_variant_paths
(
ebml_w
,
variants
,
path
,
index
);
}
case
(
ast
.item_obj
(
?
id
,
_
,
?
tps
,
?
odid
,
?
ann
))
{
add_to_index
(
ebml_w
,
path
,
index
,
id
);
...
...
@@ -314,6 +319,12 @@ fn encode_type_params(&ebml.writer ebml_w, vec[ast.ty_param] tps) {
}
}
fn
encode_variant_id
(
&
ebml
.writer
ebml_w
,
ast
.def_id
vid
)
{
ebml
.start_tag
(
ebml_w
,
tag_items_data_item_variant
);
ebml_w
.writer
.write
(
_
str
.bytes
(
def_to_str
(
vid
)));
ebml
.end_tag
(
ebml_w
);
}
fn
encode_type
(
&
ebml
.writer
ebml_w
,
@
ty
.t
typ
)
{
ebml
.start_tag
(
ebml_w
,
tag_items_data_item_type
);
auto
f
=
def_to_str
;
...
...
@@ -348,23 +359,24 @@ fn encode_obj_type_id(&ebml.writer ebml_w, &ast.def_id id) {
fn
encode_tag_variant_info
(
@
trans
.crate_ctxt
cx
,
&
ebml
.writer
ebml_w
,
ast
.def_id
did
,
vec
[
ast
.variant
]
variants
)
{
ast
.def_id
did
,
vec
[
ast
.variant
]
variants
,
&
mutable
vec
[
tup
(
int
,
uint
)]
index
)
{
for
(
ast
.variant
variant
in
variants
)
{
index
+=
vec
(
tup
(
variant
.node.id._1
,
ebml_w
.writer
.tell
()));
ebml
.start_tag
(
ebml_w
,
tag_items_data_item
);
encode_def_id
(
ebml_w
,
variant
.node.id
);
encode_kind
(
ebml_w
,
'v'
as
u8
);
encode_tag_id
(
ebml_w
,
did
);
encode_type
(
ebml_w
,
trans
.node_ann_type
(
cx
,
variant
.node.ann
));
if
(
_
vec
.len
[
ast
.variant_arg
](
variant
.node.args
)
>
0u
)
{
encode_symbol
(
cx
,
ebml_w
,
variant
.node.id
);
}
encode_symbol
(
cx
,
ebml_w
,
variant
.node.id
);
encode_discriminant
(
cx
,
ebml_w
,
variant
.node.id
);
ebml
.end_tag
(
ebml_w
);
}
}
fn
encode_info_for_item
(
@
trans
.crate_ctxt
cx
,
&
ebml
.writer
ebml_w
,
@
ast
.item
item
)
{
@
ast
.item
item
,
&
mutable
vec
[
tup
(
int
,
uint
)]
index
)
{
alt
(
item
.node
)
{
case
(
ast
.item_const
(
_
,
_
,
_
,
?
did
,
?
ann
))
{
ebml
.start_tag
(
ebml_w
,
tag_items_data_item
);
...
...
@@ -409,9 +421,12 @@ fn encode_info_for_item(@trans.crate_ctxt cx, &ebml.writer ebml_w,
encode_kind
(
ebml_w
,
't'
as
u8
);
encode_type_params
(
ebml_w
,
tps
);
encode_type
(
ebml_w
,
trans
.node_ann_type
(
cx
,
ann
));
for
(
ast
.variant
v
in
variants
)
{
encode_variant_id
(
ebml_w
,
v
.node.id
);
}
ebml
.end_tag
(
ebml_w
);
encode_tag_variant_info
(
cx
,
ebml_w
,
did
,
variants
);
encode_tag_variant_info
(
cx
,
ebml_w
,
did
,
variants
,
index
);
}
case
(
ast
.item_obj
(
?
id
,
_
,
?
tps
,
?
odid
,
?
ann
))
{
ebml
.start_tag
(
ebml_w
,
tag_items_data_item
);
...
...
@@ -458,7 +473,7 @@ fn encode_info_for_items(@trans.crate_ctxt cx, &ebml.writer ebml_w)
ebml
.start_tag
(
ebml_w
,
tag_items_data
);
for
each
(
@
tup
(
ast
.def_id
,
@
ast
.item
)
kvp
in
cx
.items
.items
())
{
index
+=
vec
(
tup
(
kvp
._0._1
,
ebml_w
.writer
.tell
()));
encode_info_for_item
(
cx
,
ebml_w
,
kvp
._1
);
encode_info_for_item
(
cx
,
ebml_w
,
kvp
._1
,
index
);
}
for
each
(
@
tup
(
ast
.def_id
,
@
ast
.native_item
)
kvp
in
cx
.native_items
.items
())
{
...
...
src/comp/middle/trans.rs
浏览文件 @
6dc45233
...
...
@@ -1911,7 +1911,10 @@ fn tag_ty_params(@crate_ctxt cx, ast.def_id id) -> vec[ast.def_id] {
// Returns information about the variants in a tag.
fn
tag_variants
(
@
crate_ctxt
cx
,
ast
.def_id
id
)
->
vec
[
variant_info
]
{
// FIXME: This doesn't work for external variants.
if
(
cx
.sess
.get_targ_crate_num
()
!=
id
._0
)
{
ret
creader
.get_tag_variants
(
cx
.sess
,
id
);
}
check
(
cx
.items
.contains_key
(
id
));
alt
(
cx
.items
.get
(
id
)
.node
)
{
case
(
ast
.item_tag
(
_
,
?
variants
,
_
,
_
,
_
))
{
...
...
src/comp/rustc.rc
浏览文件 @
6dc45233
...
...
@@ -47,6 +47,7 @@ auth front.creader.load_crate = unsafe;
auth
front
.creader.lookup_def
=
impure
;
auth
front
.creader.get_type
=
impure
;
auth
front
.creader.get_symbol
=
impure
;
auth
front
.creader.get_tag_variants
=
impure
;
auth
front
.creader.impure_no_op
=
impure
;
auth
middle
.metadata
=
unsafe
;
auth
middle
.metadata.encode_index
=
impure
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录