Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ec0c029a
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,发现更多精彩内容 >>
提交
ec0c029a
编写于
11月 24, 2012
作者:
T
Tim Chevalier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Split EBML module into a reader and a writer module
Minor refactoring, no review. Closes #2739
上级
236fd32f
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
660 addition
and
642 deletion
+660
-642
src/librustc/metadata/csearch.rs
src/librustc/metadata/csearch.rs
+2
-1
src/librustc/metadata/decoder.rs
src/librustc/metadata/decoder.rs
+104
-101
src/librustc/metadata/encoder.rs
src/librustc/metadata/encoder.rs
+43
-42
src/librustc/middle/astencode.rs
src/librustc/middle/astencode.rs
+30
-27
src/libstd/ebml.rs
src/libstd/ebml.rs
+474
-466
src/test/run-pass/auto_serialize.rs
src/test/run-pass/auto_serialize.rs
+7
-5
未找到文件。
src/librustc/metadata/csearch.rs
浏览文件 @
ec0c029a
// Searching for information from the cstore
use
std
::
ebml
;
use
Reader
=
std
::
ebml
::
Reader
;
use
syntax
::
ast
;
use
syntax
::
ast_util
;
use
syntax
::
ast_map
;
...
...
@@ -181,7 +182,7 @@ fn get_field_type(tcx: ty::ctxt, class_id: ast::def_id,
def
:
ast
::
def_id
)
->
ty
::
ty_param_bounds_and_ty
{
let
cstore
=
tcx
.cstore
;
let
cdata
=
cstore
::
get_crate_data
(
cstore
,
class_id
.crate
);
let
all_items
=
ebml
::
get_doc
(
ebml
::
Doc
(
cdata
.data
),
tag_items
);
let
all_items
=
Reader
::
get_doc
(
Reader
::
Doc
(
cdata
.data
),
tag_items
);
debug!
(
"Looking up %?"
,
class_id
);
let
class_doc
=
expect
(
tcx
.diag
,
decoder
::
maybe_find_item
(
class_id
.node
,
all_items
),
...
...
src/librustc/metadata/decoder.rs
浏览文件 @
ec0c029a
此差异已折叠。
点击以展开。
src/librustc/metadata/encoder.rs
浏览文件 @
ec0c029a
...
...
@@ -5,7 +5,7 @@
use
std
::{
ebml
,
map
};
use
std
::
map
::
HashMap
;
use
io
::
WriterUtil
;
use
ebml
::
Serializ
er
;
use
Writer
=
ebml
::
Writ
er
;
use
syntax
::
ast
::
*
;
use
syntax
::
print
::
pprust
;
use
syntax
::{
ast_util
,
visit
};
...
...
@@ -40,7 +40,7 @@
type
abbrev_map
=
map
::
HashMap
<
ty
::
t
,
tyencode
::
ty_abbrev
>
;
type
encode_inlined_item
=
fn
@
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
ebml_w
:
Writer
::
Serializer
,
path
:
ast_map
::
path
,
ii
:
ast
::
inlined_item
);
...
...
@@ -86,21 +86,21 @@ fn reachable(ecx: @encode_ctxt, id: node_id) -> bool {
ecx
.reachable
.contains_key
(
id
)
}
fn
encode_name
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
name
:
ident
)
{
fn
encode_name
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
name
:
ident
)
{
ebml_w
.wr_tagged_str
(
tag_paths_data_name
,
ecx
.tcx.sess
.str_of
(
name
));
}
fn
encode_impl_type_basename
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_impl_type_basename
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
name
:
ident
)
{
ebml_w
.wr_tagged_str
(
tag_item_impl_type_basename
,
ecx
.tcx.sess
.str_of
(
name
));
}
fn
encode_def_id
(
ebml_w
:
ebml
::
Serializer
,
id
:
def_id
)
{
fn
encode_def_id
(
ebml_w
:
Writer
::
Serializer
,
id
:
def_id
)
{
ebml_w
.wr_tagged_str
(
tag_def_id
,
def_to_str
(
id
));
}
fn
encode_region_param
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_region_param
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
it
:
@
ast
::
item
)
{
let
opt_rp
=
ecx
.tcx.region_paramd_items
.find
(
it
.id
);
for
opt_rp
.each
|
rp
|
{
...
...
@@ -110,7 +110,7 @@ fn encode_region_param(ecx: @encode_ctxt, ebml_w: ebml::Serializer,
}
}
fn
encode_mutability
(
ebml_w
:
ebml
::
Serializer
,
mt
:
class_mutability
)
{
fn
encode_mutability
(
ebml_w
:
Writer
::
Serializer
,
mt
:
class_mutability
)
{
do
ebml_w
.wr_tag
(
tag_class_mut
)
{
let
val
=
match
mt
{
class_immutable
=>
'a'
,
...
...
@@ -122,7 +122,7 @@ fn encode_mutability(ebml_w: ebml::Serializer, mt: class_mutability) {
type
entry
<
T
>
=
{
val
:
T
,
pos
:
uint
};
fn
add_to_index
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
path
:
&
[
ident
],
fn
add_to_index
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
path
:
&
[
ident
],
index
:
&
mut
~
[
entry
<~
str
>
],
name
:
ident
)
{
let
mut
full_path
=
~
[];
full_path
.push_all
(
path
);
...
...
@@ -133,7 +133,7 @@ fn add_to_index(ecx: @encode_ctxt, ebml_w: ebml::Serializer, path: &[ident],
pos
:
ebml_w
.writer
.tell
()});
}
fn
encode_trait_ref
(
ebml_w
:
ebml
::
Serializer
,
ecx
:
@
encode_ctxt
,
fn
encode_trait_ref
(
ebml_w
:
Writer
::
Serializer
,
ecx
:
@
encode_ctxt
,
t
:
@
trait_ref
)
{
ebml_w
.start_tag
(
tag_impl_trait
);
encode_type
(
ecx
,
ebml_w
,
node_id_to_type
(
ecx
.tcx
,
t
.ref_id
));
...
...
@@ -142,7 +142,7 @@ fn encode_trait_ref(ebml_w: ebml::Serializer, ecx: @encode_ctxt,
// Item info table encoding
fn
encode_family
(
ebml_w
:
ebml
::
Serializer
,
c
:
char
)
{
fn
encode_family
(
ebml_w
:
Writer
::
Serializer
,
c
:
char
)
{
ebml_w
.start_tag
(
tag_items_data_item_family
);
ebml_w
.writer
.write
(
&
[
c
as
u8
]);
ebml_w
.end_tag
();
...
...
@@ -150,7 +150,7 @@ fn encode_family(ebml_w: ebml::Serializer, c: char) {
fn
def_to_str
(
did
:
def_id
)
->
~
str
{
fmt!
(
"%d:%d"
,
did
.crate
,
did
.node
)
}
fn
encode_ty_type_param_bounds
(
ebml_w
:
ebml
::
Serializer
,
ecx
:
@
encode_ctxt
,
fn
encode_ty_type_param_bounds
(
ebml_w
:
Writer
::
Serializer
,
ecx
:
@
encode_ctxt
,
params
:
@~
[
ty
::
param_bounds
])
{
let
ty_str_ctxt
=
@
{
diag
:
ecx
.diag
,
ds
:
def_to_str
,
...
...
@@ -164,7 +164,7 @@ fn encode_ty_type_param_bounds(ebml_w: ebml::Serializer, ecx: @encode_ctxt,
}
}
fn
encode_type_param_bounds
(
ebml_w
:
ebml
::
Serializer
,
ecx
:
@
encode_ctxt
,
fn
encode_type_param_bounds
(
ebml_w
:
Writer
::
Serializer
,
ecx
:
@
encode_ctxt
,
params
:
~
[
ty_param
])
{
let
ty_param_bounds
=
@
params
.map
(|
param
|
ecx
.tcx.ty_param_bounds
.get
(
param
.id
));
...
...
@@ -172,13 +172,13 @@ fn encode_type_param_bounds(ebml_w: ebml::Serializer, ecx: @encode_ctxt,
}
fn
encode_variant_id
(
ebml_w
:
ebml
::
Serializer
,
vid
:
def_id
)
{
fn
encode_variant_id
(
ebml_w
:
Writer
::
Serializer
,
vid
:
def_id
)
{
ebml_w
.start_tag
(
tag_items_data_item_variant
);
ebml_w
.writer
.write
(
str
::
to_bytes
(
def_to_str
(
vid
)));
ebml_w
.end_tag
();
}
fn
write_type
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
typ
:
ty
::
t
)
{
fn
write_type
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
typ
:
ty
::
t
)
{
let
ty_str_ctxt
=
@
{
diag
:
ecx
.diag
,
ds
:
def_to_str
,
...
...
@@ -188,7 +188,7 @@ fn write_type(ecx: @encode_ctxt, ebml_w: ebml::Serializer, typ: ty::t) {
tyencode
::
enc_ty
(
ebml_w
.writer
,
ty_str_ctxt
,
typ
);
}
fn
write_vstore
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
write_vstore
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
vstore
:
ty
::
vstore
)
{
let
ty_str_ctxt
=
@
{
diag
:
ecx
.diag
,
...
...
@@ -199,13 +199,13 @@ fn write_vstore(ecx: @encode_ctxt, ebml_w: ebml::Serializer,
tyencode
::
enc_vstore
(
ebml_w
.writer
,
ty_str_ctxt
,
vstore
);
}
fn
encode_type
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
typ
:
ty
::
t
)
{
fn
encode_type
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
typ
:
ty
::
t
)
{
ebml_w
.start_tag
(
tag_items_data_item_type
);
write_type
(
ecx
,
ebml_w
,
typ
);
ebml_w
.end_tag
();
}
fn
encode_symbol
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
id
:
node_id
)
{
fn
encode_symbol
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
id
:
node_id
)
{
ebml_w
.start_tag
(
tag_items_data_item_symbol
);
let
sym
=
match
ecx
.item_symbols
.find
(
id
)
{
Some
(
x
)
=>
x
,
...
...
@@ -218,27 +218,27 @@ fn encode_symbol(ecx: @encode_ctxt, ebml_w: ebml::Serializer, id: node_id) {
ebml_w
.end_tag
();
}
fn
encode_discriminant
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_discriminant
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
id
:
node_id
)
{
ebml_w
.start_tag
(
tag_items_data_item_symbol
);
ebml_w
.writer
.write
(
str
::
to_bytes
(
ecx
.discrim_symbols
.get
(
id
)));
ebml_w
.end_tag
();
}
fn
encode_disr_val
(
_
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_disr_val
(
_
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
disr_val
:
int
)
{
ebml_w
.start_tag
(
tag_disr_val
);
ebml_w
.writer
.write
(
str
::
to_bytes
(
int
::
to_str
(
disr_val
,
10u
)));
ebml_w
.end_tag
();
}
fn
encode_parent_item
(
ebml_w
:
ebml
::
Serializer
,
id
:
def_id
)
{
fn
encode_parent_item
(
ebml_w
:
Writer
::
Serializer
,
id
:
def_id
)
{
ebml_w
.start_tag
(
tag_items_data_parent_item
);
ebml_w
.writer
.write
(
str
::
to_bytes
(
def_to_str
(
id
)));
ebml_w
.end_tag
();
}
fn
encode_enum_variant_info
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_enum_variant_info
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
id
:
node_id
,
variants
:
~
[
variant
],
path
:
ast_map
::
path
,
index
:
@
mut
~
[
entry
<
int
>
],
ty_params
:
~
[
ty_param
])
{
...
...
@@ -275,9 +275,9 @@ fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: ebml::Serializer,
}
}
fn
encode_path
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_path
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
path
:
ast_map
::
path
,
name
:
ast_map
::
path_elt
)
{
fn
encode_path_elt
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_path_elt
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
elt
:
ast_map
::
path_elt
)
{
let
(
tag
,
name
)
=
match
elt
{
ast_map
::
path_mod
(
name
)
=>
(
tag_path_elt_mod
,
name
),
...
...
@@ -296,8 +296,9 @@ fn encode_path_elt(ecx: @encode_ctxt, ebml_w: ebml::Serializer,
}
}
fn
encode_info_for_mod
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
md
:
_
mod
,
id
:
node_id
,
path
:
ast_map
::
path
,
name
:
ident
)
{
fn
encode_info_for_mod
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
md
:
_
mod
,
id
:
node_id
,
path
:
ast_map
::
path
,
name
:
ident
)
{
ebml_w
.start_tag
(
tag_items_data_item
);
encode_def_id
(
ebml_w
,
local_def
(
id
));
encode_family
(
ebml_w
,
'm'
);
...
...
@@ -354,7 +355,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::Serializer, md: _mod,
ebml_w
.end_tag
();
}
fn
encode_visibility
(
ebml_w
:
ebml
::
Serializer
,
visibility
:
visibility
)
{
fn
encode_visibility
(
ebml_w
:
Writer
::
Serializer
,
visibility
:
visibility
)
{
encode_family
(
ebml_w
,
match
visibility
{
public
=>
'g'
,
private
=>
'j'
,
...
...
@@ -362,7 +363,7 @@ fn encode_visibility(ebml_w: ebml::Serializer, visibility: visibility) {
});
}
fn
encode_self_type
(
ebml_w
:
ebml
::
Serializer
,
self_type
:
ast
::
self_ty_
)
{
fn
encode_self_type
(
ebml_w
:
Writer
::
Serializer
,
self_type
:
ast
::
self_ty_
)
{
ebml_w
.start_tag
(
tag_item_trait_method_self_ty
);
// Encode the base self type.
...
...
@@ -394,14 +395,14 @@ fn encode_self_type(ebml_w: ebml::Serializer, self_type: ast::self_ty_) {
ebml_w
.end_tag
();
}
fn
encode_method_sort
(
ebml_w
:
ebml
::
Serializer
,
sort
:
char
)
{
fn
encode_method_sort
(
ebml_w
:
Writer
::
Serializer
,
sort
:
char
)
{
ebml_w
.start_tag
(
tag_item_trait_method_sort
);
ebml_w
.writer
.write
(
&
[
sort
as
u8
]);
ebml_w
.end_tag
();
}
/* Returns an index of items in this class */
fn
encode_info_for_class
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_info_for_class
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
id
:
node_id
,
path
:
ast_map
::
path
,
class_tps
:
~
[
ty_param
],
fields
:
~
[
@
struct_field
],
...
...
@@ -457,7 +458,7 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::Serializer,
}
// This is for encoding info for ctors and dtors
fn
encode_info_for_ctor
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_info_for_ctor
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
id
:
node_id
,
ident
:
ident
,
path
:
ast_map
::
path
,
item
:
Option
<
inlined_item
>
,
tps
:
~
[
ty_param
])
{
ebml_w
.start_tag
(
tag_items_data_item
);
...
...
@@ -482,7 +483,7 @@ fn encode_info_for_ctor(ecx: @encode_ctxt, ebml_w: ebml::Serializer,
ebml_w
.end_tag
();
}
fn
encode_info_for_method
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_info_for_method
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
impl_path
:
ast_map
::
path
,
should_inline
:
bool
,
parent_id
:
node_id
,
m
:
@
method
,
all_tps
:
~
[
ty_param
])
{
...
...
@@ -537,7 +538,7 @@ fn should_inline(attrs: ~[attribute]) -> bool {
}
fn
encode_info_for_item
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_info_for_item
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
item
:
@
item
,
index
:
@
mut
~
[
entry
<
int
>
],
path
:
ast_map
::
path
)
{
...
...
@@ -550,7 +551,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::Serializer,
};
if
!
must_write
&&
!
reachable
(
ecx
,
item
.id
)
{
return
;
}
fn
add_to_index_
(
item
:
@
item
,
ebml_w
:
ebml
::
Serializer
,
fn
add_to_index_
(
item
:
@
item
,
ebml_w
:
Writer
::
Serializer
,
index
:
@
mut
~
[
entry
<
int
>
])
{
index
.push
({
val
:
item
.id
,
pos
:
ebml_w
.writer
.tell
()});
}
...
...
@@ -835,7 +836,7 @@ fn add_to_index_(item: @item, ebml_w: ebml::Serializer,
}
}
fn
encode_info_for_foreign_item
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_info_for_foreign_item
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
nitem
:
@
foreign_item
,
index
:
@
mut
~
[
entry
<
int
>
],
path
:
ast_map
::
path
,
abi
:
foreign_abi
)
{
...
...
@@ -868,7 +869,7 @@ fn encode_info_for_foreign_item(ecx: @encode_ctxt, ebml_w: ebml::Serializer,
ebml_w
.end_tag
();
}
fn
encode_info_for_items
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_info_for_items
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
crate
:
@
crate
)
->
~
[
entry
<
int
>
]
{
let
index
=
@
mut
~
[];
ebml_w
.start_tag
(
tag_items_data
);
...
...
@@ -923,7 +924,7 @@ fn create_index<T: Copy Hash IterBytes>(index: ~[entry<T>]) ->
return
buckets_frozen
;
}
fn
encode_index
<
T
>
(
ebml_w
:
ebml
::
Serializer
,
buckets
:
~
[
@~
[
entry
<
T
>
]],
fn
encode_index
<
T
>
(
ebml_w
:
Writer
::
Serializer
,
buckets
:
~
[
@~
[
entry
<
T
>
]],
write_fn
:
fn
(
io
::
Writer
,
T
))
{
let
writer
=
ebml_w
.writer
;
ebml_w
.start_tag
(
tag_index
);
...
...
@@ -958,7 +959,7 @@ fn write_int(writer: io::Writer, &&n: int) {
writer
.write_be_u32
(
n
as
u32
);
}
fn
encode_meta_item
(
ebml_w
:
ebml
::
Serializer
,
mi
:
meta_item
)
{
fn
encode_meta_item
(
ebml_w
:
Writer
::
Serializer
,
mi
:
meta_item
)
{
match
mi
.node
{
meta_word
(
name
)
=>
{
ebml_w
.start_tag
(
tag_meta_item_word
);
...
...
@@ -995,7 +996,7 @@ fn encode_meta_item(ebml_w: ebml::Serializer, mi: meta_item) {
}
}
fn
encode_attributes
(
ebml_w
:
ebml
::
Serializer
,
attrs
:
~
[
attribute
])
{
fn
encode_attributes
(
ebml_w
:
Writer
::
Serializer
,
attrs
:
~
[
attribute
])
{
ebml_w
.start_tag
(
tag_attributes
);
for
attrs
.each
|
attr
|
{
ebml_w
.start_tag
(
tag_attribute
);
...
...
@@ -1056,7 +1057,7 @@ fn synthesize_link_attr(ecx: @encode_ctxt, items: ~[@meta_item]) ->
return
attrs
;
}
fn
encode_crate_deps
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_crate_deps
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
cstore
:
cstore
::
CStore
)
{
fn
get_ordered_deps
(
ecx
:
@
encode_ctxt
,
cstore
:
cstore
::
CStore
)
...
...
@@ -1102,7 +1103,7 @@ fn get_ordered_deps(ecx: @encode_ctxt, cstore: cstore::CStore)
ebml_w
.end_tag
();
}
fn
encode_crate_dep
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
fn
encode_crate_dep
(
ecx
:
@
encode_ctxt
,
ebml_w
:
Writer
::
Serializer
,
dep
:
decoder
::
crate_dep
)
{
ebml_w
.start_tag
(
tag_crate_dep
);
ebml_w
.start_tag
(
tag_crate_dep_name
);
...
...
@@ -1117,7 +1118,7 @@ fn encode_crate_dep(ecx: @encode_ctxt, ebml_w: ebml::Serializer,
ebml_w
.end_tag
();
}
fn
encode_hash
(
ebml_w
:
ebml
::
Serializer
,
hash
:
~
str
)
{
fn
encode_hash
(
ebml_w
:
Writer
::
Serializer
,
hash
:
~
str
)
{
ebml_w
.start_tag
(
tag_crate_hash
);
ebml_w
.writer
.write
(
str
::
to_bytes
(
hash
));
ebml_w
.end_tag
();
...
...
@@ -1155,7 +1156,7 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
type_abbrevs
:
ty
::
new_ty_hash
()
});
let
ebml_w
=
ebml
::
Serializer
(
wr
as
io
::
Writer
);
let
ebml_w
=
Writer
::
Serializer
(
wr
as
io
::
Writer
);
encode_hash
(
ebml_w
,
ecx
.link_meta.extras_hash
);
...
...
src/librustc/middle/astencode.rs
浏览文件 @
ec0c029a
...
...
@@ -8,7 +8,10 @@
use
syntax
::
ast_util
;
use
syntax
::
codemap
::
span
;
use
std
::
ebml
;
use
std
::
ebml
::{
Serializer
,
get_doc
};
use
Writer
=
std
::
ebml
::
Writer
;
use
Reader
=
std
::
ebml
::
Reader
;
use
Reader
::
get_doc
;
use
Writer
::
Serializer
;
use
std
::
map
::
HashMap
;
use
std
::
serialization
;
use
std
::
serialization
::{
Serializable
,
...
...
@@ -73,7 +76,7 @@ trait tr {
// Top-level methods.
fn
encode_inlined_item
(
ecx
:
@
e
::
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
ebml_w
:
Writer
::
Serializer
,
path
:
ast_map
::
path
,
ii
:
ast
::
inlined_item
,
maps
:
maps
)
{
...
...
@@ -106,7 +109,7 @@ fn decode_inlined_item(cdata: cstore::crate_metadata,
Some
(
ast_doc
)
=>
{
debug!
(
"> Decoding inlined fn: %s::?"
,
ast_map
::
path_to_str
(
path
,
tcx
.sess.parse_sess.interner
));
let
ast_dsr
=
&
ebml
::
Deserializer
(
ast_doc
);
let
ast_dsr
=
&
Reader
::
Deserializer
(
ast_doc
);
let
from_id_range
=
deserialize
(
ast_dsr
);
let
to_id_range
=
reserve_id_range
(
dcx
.tcx.sess
,
from_id_range
);
let
xcx
=
extended_decode_ctxt_
(
@
{
dcx
:
dcx
,
...
...
@@ -217,7 +220,7 @@ fn read_def_id(xcx: extended_decode_ctxt) -> ast::def_id {
// We also have to adjust the spans: for now we just insert a dummy span,
// but eventually we should add entries to the local codemap as required.
fn
encode_ast
(
ebml_w
:
ebml
::
Serializer
,
item
:
ast
::
inlined_item
)
{
fn
encode_ast
(
ebml_w
:
Writer
::
Serializer
,
item
:
ast
::
inlined_item
)
{
do
ebml_w
.wr_tag
(
c
::
tag_tree
as
uint
)
{
item
.serialize
(
&
ebml_w
)
}
...
...
@@ -272,7 +275,7 @@ fn drop_nested_items(blk: ast::blk_, fld: fold::ast_fold) -> ast::blk_ {
fn
decode_ast
(
par_doc
:
ebml
::
Doc
)
->
ast
::
inlined_item
{
let
chi_doc
=
par_doc
[
c
::
tag_tree
as
uint
];
let
d
=
&
ebml
::
Deserializer
(
chi_doc
);
let
d
=
&
Reader
::
Deserializer
(
chi_doc
);
deserialize
(
d
)
}
...
...
@@ -312,12 +315,12 @@ fn renumber_ast(xcx: extended_decode_ctxt, ii: ast::inlined_item)
// ______________________________________________________________________
// Encoding and decoding of ast::def
fn
encode_def
(
ebml_w
:
ebml
::
Serializer
,
def
:
ast
::
def
)
{
fn
encode_def
(
ebml_w
:
Writer
::
Serializer
,
def
:
ast
::
def
)
{
def
.serialize
(
&
ebml_w
)
}
fn
decode_def
(
xcx
:
extended_decode_ctxt
,
doc
:
ebml
::
Doc
)
->
ast
::
def
{
let
dsr
=
&
ebml
::
Deserializer
(
doc
);
let
dsr
=
&
Reader
::
Deserializer
(
doc
);
let
def
:
ast
::
def
=
deserialize
(
dsr
);
def
.tr
(
xcx
)
}
...
...
@@ -405,7 +408,7 @@ fn tr(xcx: extended_decode_ctxt) -> ty::bound_region {
// ______________________________________________________________________
// Encoding and decoding of freevar information
fn
encode_freevar_entry
(
ebml_w
:
ebml
::
Serializer
,
fv
:
@
freevar_entry
)
{
fn
encode_freevar_entry
(
ebml_w
:
Writer
::
Serializer
,
fv
:
@
freevar_entry
)
{
(
*
fv
)
.serialize
(
&
ebml_w
)
}
...
...
@@ -413,7 +416,7 @@ trait ebml_deserializer_helper {
fn
read_freevar_entry
(
xcx
:
extended_decode_ctxt
)
->
freevar_entry
;
}
impl
ebml
::
Deserializer
:
ebml_deserializer_helper
{
impl
Reader
::
Deserializer
:
ebml_deserializer_helper
{
fn
read_freevar_entry
(
xcx
:
extended_decode_ctxt
)
->
freevar_entry
{
let
fv
:
freevar_entry
=
deserialize
(
&
self
);
fv
.tr
(
xcx
)
...
...
@@ -434,7 +437,7 @@ trait read_method_map_entry_helper {
}
fn
serialize_method_map_entry
(
ecx
:
@
e
::
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
ebml_w
:
Writer
::
Serializer
,
mme
:
method_map_entry
)
{
do
ebml_w
.emit_rec
{
do
ebml_w
.emit_field
(
~
"self_arg"
,
0u
)
{
...
...
@@ -446,7 +449,7 @@ fn serialize_method_map_entry(ecx: @e::encode_ctxt,
}
}
impl
ebml
::
Deserializer
:
read_method_map_entry_helper
{
impl
Reader
::
Deserializer
:
read_method_map_entry_helper
{
fn
read_method_map_entry
(
xcx
:
extended_decode_ctxt
)
->
method_map_entry
{
do
self
.read_rec
{
{
self_arg
:
...
...
@@ -485,7 +488,7 @@ fn tr(xcx: extended_decode_ctxt) -> method_origin {
// Encoding and decoding vtable_res
fn
encode_vtable_res
(
ecx
:
@
e
::
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
ebml_w
:
Writer
::
Serializer
,
dr
:
typeck
::
vtable_res
)
{
// can't autogenerate this code because automatic serialization of
// ty::t doesn't work, and there is no way (atm) to have
...
...
@@ -497,7 +500,7 @@ fn encode_vtable_res(ecx: @e::encode_ctxt,
}
fn
encode_vtable_origin
(
ecx
:
@
e
::
encode_ctxt
,
ebml_w
:
ebml
::
Serializer
,
ebml_w
:
Writer
::
Serializer
,
vtable_origin
:
typeck
::
vtable_origin
)
{
do
ebml_w
.emit_enum
(
~
"vtable_origin"
)
{
match
vtable_origin
{
...
...
@@ -544,7 +547,7 @@ trait vtable_deserialization_helpers {
fn
read_vtable_origin
(
xcx
:
extended_decode_ctxt
)
->
typeck
::
vtable_origin
;
}
impl
ebml
::
Deserializer
:
vtable_deserialization_helpers
{
impl
Reader
::
Deserializer
:
vtable_deserialization_helpers
{
fn
read_vtable_res
(
xcx
:
extended_decode_ctxt
)
->
typeck
::
vtable_res
{
@
self
.read_to_vec
(||
self
.read_vtable_origin
(
xcx
)
)
}
...
...
@@ -621,7 +624,7 @@ trait ebml_writer_helpers {
fn
emit_tpbt
(
ecx
:
@
e
::
encode_ctxt
,
tpbt
:
ty
::
ty_param_bounds_and_ty
);
}
impl
ebml
::
Serializer
:
ebml_writer_helpers
{
impl
Writer
::
Serializer
:
ebml_writer_helpers
{
fn
emit_ty
(
ecx
:
@
e
::
encode_ctxt
,
ty
:
ty
::
t
)
{
do
self
.emit_opaque
{
e
::
write_type
(
ecx
,
self
,
ty
)
...
...
@@ -674,7 +677,7 @@ trait write_tag_and_id {
fn
id
(
id
:
ast
::
node_id
);
}
impl
ebml
::
Serializer
:
write_tag_and_id
{
impl
Writer
::
Serializer
:
write_tag_and_id
{
fn
tag
(
tag_id
:
c
::
astencode_tag
,
f
:
fn
())
{
do
self
.wr_tag
(
tag_id
as
uint
)
{
f
()
}
}
...
...
@@ -686,7 +689,7 @@ fn id(id: ast::node_id) {
fn
encode_side_tables_for_ii
(
ecx
:
@
e
::
encode_ctxt
,
maps
:
maps
,
ebml_w
:
ebml
::
Serializer
,
ebml_w
:
Writer
::
Serializer
,
ii
:
ast
::
inlined_item
)
{
do
ebml_w
.wr_tag
(
c
::
tag_table
as
uint
)
{
ast_util
::
visit_ids_for_inlined_item
(
...
...
@@ -702,7 +705,7 @@ fn encode_side_tables_for_ii(ecx: @e::encode_ctxt,
fn
encode_side_tables_for_id
(
ecx
:
@
e
::
encode_ctxt
,
maps
:
maps
,
ebml_w
:
ebml
::
Serializer
,
ebml_w
:
Writer
::
Serializer
,
id
:
ast
::
node_id
)
{
let
tcx
=
ecx
.tcx
;
...
...
@@ -835,9 +838,9 @@ trait doc_decoder_helpers {
}
impl
ebml
::
Doc
:
doc_decoder_helpers
{
fn
as_int
()
->
int
{
ebml
::
doc_as_u64
(
self
)
as
int
}
fn
as_int
()
->
int
{
Reader
::
doc_as_u64
(
self
)
as
int
}
fn
opt_child
(
tag
:
c
::
astencode_tag
)
->
Option
<
ebml
::
Doc
>
{
ebml
::
maybe_get_doc
(
self
,
tag
as
uint
)
Reader
::
maybe_get_doc
(
self
,
tag
as
uint
)
}
}
...
...
@@ -850,7 +853,7 @@ fn read_ty_param_bounds_and_ty(xcx: extended_decode_ctxt)
->
ty
::
ty_param_bounds_and_ty
;
}
impl
ebml
::
Deserializer
:
ebml_deserializer_decoder_helpers
{
impl
Reader
::
Deserializer
:
ebml_deserializer_decoder_helpers
{
fn
read_arg
(
xcx
:
extended_decode_ctxt
)
->
ty
::
arg
{
do
self
.read_opaque
|
doc
|
{
...
...
@@ -908,7 +911,7 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
ast_doc
:
ebml
::
Doc
)
{
let
dcx
=
xcx
.dcx
;
let
tbl_doc
=
ast_doc
[
c
::
tag_table
as
uint
];
for
ebml
::
docs
(
tbl_doc
)
|
tag
,
entry_doc
|
{
for
Reader
::
docs
(
tbl_doc
)
|
tag
,
entry_doc
|
{
let
id0
=
entry_doc
[
c
::
tag_table_id
as
uint
]
.as_int
();
let
id
=
xcx
.tr_id
(
id0
);
...
...
@@ -922,7 +925,7 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
dcx
.tcx.legacy_boxed_traits
.insert
(
id
,
());
}
else
{
let
val_doc
=
entry_doc
[
c
::
tag_table_val
as
uint
];
let
val_dsr
=
&
ebml
::
Deserializer
(
val_doc
);
let
val_dsr
=
&
Reader
::
Deserializer
(
val_doc
);
if
tag
==
(
c
::
tag_table_def
as
uint
)
{
let
def
=
decode_def
(
xcx
,
val_doc
);
dcx
.tcx.def_map
.insert
(
id
,
def
);
...
...
@@ -975,7 +978,7 @@ fn decode_side_tables(xcx: extended_decode_ctxt,
// Testing of astencode_gen
#[cfg(test)]
fn
encode_item_ast
(
ebml_w
:
ebml
::
Serializer
,
item
:
@
ast
::
item
)
{
fn
encode_item_ast
(
ebml_w
:
Writer
::
Serializer
,
item
:
@
ast
::
item
)
{
do
ebml_w
.wr_tag
(
c
::
tag_tree
as
uint
)
{
(
*
item
)
.serialize
(
&
ebml_w
)
}
...
...
@@ -984,7 +987,7 @@ fn encode_item_ast(ebml_w: ebml::Serializer, item: @ast::item) {
#[cfg(test)]
fn
decode_item_ast
(
par_doc
:
ebml
::
Doc
)
->
@
ast
::
item
{
let
chi_doc
=
par_doc
[
c
::
tag_tree
as
uint
];
let
d
=
&
ebml
::
Deserializer
(
chi_doc
);
let
d
=
&
Reader
::
Deserializer
(
chi_doc
);
@
deserialize
(
d
)
}
...
...
@@ -1011,10 +1014,10 @@ fn mk_ctxt() -> fake_ext_ctxt {
#[cfg(test)]
fn
roundtrip
(
in_item
:
@
ast
::
item
)
{
let
bytes
=
do
io
::
with_bytes_writer
|
wr
|
{
let
ebml_w
=
ebml
::
Serializer
(
wr
);
let
ebml_w
=
Writer
::
Serializer
(
wr
);
encode_item_ast
(
ebml_w
,
in_item
);
};
let
ebml_doc
=
ebml
::
Doc
(
@
bytes
);
let
ebml_doc
=
Reader
::
Doc
(
@
bytes
);
let
out_item
=
decode_item_ast
(
ebml_doc
);
let
exp_str
=
do
io
::
with_str_writer
|
w
|
{
...
...
src/libstd/ebml.rs
浏览文件 @
ec0c029a
此差异已折叠。
点击以展开。
src/test/run-pass/auto_serialize.rs
浏览文件 @
ec0c029a
...
...
@@ -5,6 +5,8 @@
use
cmp
::
Eq
;
use
std
::
ebml
;
use
EBReader
=
std
::
ebml
::
Reader
;
use
EBWriter
=
std
::
ebml
::
Writer
;
use
io
::
Writer
;
use
std
::
serialization
::{
Serializable
,
Deserializable
,
deserialize
};
use
std
::
prettyprint
;
...
...
@@ -22,15 +24,15 @@ fn test_prettyprint<A: Serializable<prettyprint::Serializer>>(
fn
test_ebml
<
A
:
Eq
Serializable
<
ebml
::
Serializer
>
Deserializable
<
ebml
::
Deserializer
>
Serializable
<
EBWriter
::
Serializer
>
Deserializable
<
EBReader
::
Deserializer
>
>
(
a1
:
&
A
)
{
let
bytes
=
do
io
::
with_bytes_writer
|
wr
|
{
let
ebml_w
=
&
ebml
::
Serializer
(
wr
);
let
ebml_w
=
&
EBWriter
::
Serializer
(
wr
);
a1
.serialize
(
ebml_w
)
};
let
d
=
ebml
::
Doc
(
@
bytes
);
let
a2
:
A
=
deserialize
(
&
ebml
::
Deserializer
(
d
));
let
d
=
EBReader
::
Doc
(
@
bytes
);
let
a2
:
A
=
deserialize
(
&
EBReader
::
Deserializer
(
d
));
assert
*
a1
==
a2
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录