std: rename {read,emit}_field to {read,emit}_struct_field
This commit is contained in:
parent
97cc571358
commit
419f6acf0e
5 changed files with 183 additions and 10 deletions
|
@ -556,6 +556,7 @@ trait read_method_map_entry_helper {
|
||||||
-> method_map_entry;
|
-> method_map_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
fn encode_method_map_entry(ecx: @e::EncodeContext,
|
fn encode_method_map_entry(ecx: @e::EncodeContext,
|
||||||
ebml_w: writer::Encoder,
|
ebml_w: writer::Encoder,
|
||||||
mme: method_map_entry) {
|
mme: method_map_entry) {
|
||||||
|
@ -572,7 +573,27 @@ fn encode_method_map_entry(ecx: @e::EncodeContext,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage1)]
|
||||||
|
#[cfg(stage2)]
|
||||||
|
#[cfg(stage3)]
|
||||||
|
fn encode_method_map_entry(ecx: @e::EncodeContext,
|
||||||
|
ebml_w: writer::Encoder,
|
||||||
|
mme: method_map_entry) {
|
||||||
|
do ebml_w.emit_struct("method_map_entry", 3) {
|
||||||
|
do ebml_w.emit_struct_field("self_arg", 0u) {
|
||||||
|
ebml_w.emit_arg(ecx, mme.self_arg);
|
||||||
|
}
|
||||||
|
do ebml_w.emit_struct_field("explicit_self", 2u) {
|
||||||
|
mme.explicit_self.encode(&ebml_w);
|
||||||
|
}
|
||||||
|
do ebml_w.emit_struct_field("origin", 1u) {
|
||||||
|
mme.origin.encode(&ebml_w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl read_method_map_entry_helper for reader::Decoder {
|
impl read_method_map_entry_helper for reader::Decoder {
|
||||||
|
#[cfg(stage0)]
|
||||||
fn read_method_map_entry(&self, xcx: @ExtendedDecodeContext)
|
fn read_method_map_entry(&self, xcx: @ExtendedDecodeContext)
|
||||||
-> method_map_entry {
|
-> method_map_entry {
|
||||||
do self.read_struct("method_map_entry", 3) {
|
do self.read_struct("method_map_entry", 3) {
|
||||||
|
@ -592,6 +613,29 @@ impl read_method_map_entry_helper for reader::Decoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage1)]
|
||||||
|
#[cfg(stage2)]
|
||||||
|
#[cfg(stage3)]
|
||||||
|
fn read_method_map_entry(&self, xcx: @ExtendedDecodeContext)
|
||||||
|
-> method_map_entry {
|
||||||
|
do self.read_struct("method_map_entry", 3) {
|
||||||
|
method_map_entry {
|
||||||
|
self_arg: self.read_struct_field("self_arg", 0u, || {
|
||||||
|
self.read_arg(xcx)
|
||||||
|
}),
|
||||||
|
explicit_self: self.read_struct_field("explicit_self", 2u, || {
|
||||||
|
let self_type: ast::self_ty_ = Decodable::decode(self);
|
||||||
|
self_type
|
||||||
|
}),
|
||||||
|
origin: self.read_struct_field("origin", 1u, || {
|
||||||
|
let method_origin: method_origin =
|
||||||
|
Decodable::decode(self);
|
||||||
|
method_origin.tr(xcx)
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl tr for method_origin {
|
impl tr for method_origin {
|
||||||
|
@ -782,6 +826,7 @@ impl ebml_writer_helpers for writer::Encoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
fn emit_tpbt(&self, ecx: @e::EncodeContext,
|
fn emit_tpbt(&self, ecx: @e::EncodeContext,
|
||||||
tpbt: ty::ty_param_bounds_and_ty) {
|
tpbt: ty::ty_param_bounds_and_ty) {
|
||||||
do self.emit_struct("ty_param_bounds_and_ty", 2) {
|
do self.emit_struct("ty_param_bounds_and_ty", 2) {
|
||||||
|
@ -804,6 +849,32 @@ impl ebml_writer_helpers for writer::Encoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage1)]
|
||||||
|
#[cfg(stage2)]
|
||||||
|
#[cfg(stage3)]
|
||||||
|
fn emit_tpbt(&self, ecx: @e::EncodeContext,
|
||||||
|
tpbt: ty::ty_param_bounds_and_ty) {
|
||||||
|
do self.emit_struct("ty_param_bounds_and_ty", 2) {
|
||||||
|
do self.emit_struct_field("generics", 0) {
|
||||||
|
do self.emit_struct("Generics", 2) {
|
||||||
|
do self.emit_struct_field("type_param_defs", 0) {
|
||||||
|
do self.emit_from_vec(*tpbt.generics.type_param_defs)
|
||||||
|
|type_param_def|
|
||||||
|
{
|
||||||
|
self.emit_type_param_def(ecx, type_param_def);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
do self.emit_struct_field("region_param", 1) {
|
||||||
|
tpbt.generics.region_param.encode(self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
do self.emit_struct_field("ty", 1) {
|
||||||
|
self.emit_ty(ecx, tpbt.ty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait write_tag_and_id {
|
trait write_tag_and_id {
|
||||||
|
@ -1053,6 +1124,7 @@ impl ebml_decoder_decoder_helpers for reader::Decoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
fn read_ty_param_bounds_and_ty(&self, xcx: @ExtendedDecodeContext)
|
fn read_ty_param_bounds_and_ty(&self, xcx: @ExtendedDecodeContext)
|
||||||
-> ty::ty_param_bounds_and_ty
|
-> ty::ty_param_bounds_and_ty
|
||||||
{
|
{
|
||||||
|
@ -1075,6 +1147,31 @@ impl ebml_decoder_decoder_helpers for reader::Decoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage1)]
|
||||||
|
#[cfg(stage2)]
|
||||||
|
#[cfg(stage3)]
|
||||||
|
fn read_ty_param_bounds_and_ty(&self, xcx: @ExtendedDecodeContext)
|
||||||
|
-> ty::ty_param_bounds_and_ty
|
||||||
|
{
|
||||||
|
do self.read_struct("ty_param_bounds_and_ty", 2) {
|
||||||
|
ty::ty_param_bounds_and_ty {
|
||||||
|
generics: do self.read_struct("Generics", 2) {
|
||||||
|
ty::Generics {
|
||||||
|
type_param_defs: self.read_struct_field("type_param_defs", 0, || {
|
||||||
|
@self.read_to_vec(|| self.read_type_param_def(xcx))
|
||||||
|
}),
|
||||||
|
region_param: self.read_struct_field(~"region_param", 1, || {
|
||||||
|
Decodable::decode(self)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ty: self.read_struct_field("ty", 1, || {
|
||||||
|
self.read_ty(xcx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn convert_def_id(&self, xcx: @ExtendedDecodeContext,
|
fn convert_def_id(&self, xcx: @ExtendedDecodeContext,
|
||||||
source: tydecode::DefIdSource,
|
source: tydecode::DefIdSource,
|
||||||
did: ast::def_id) -> ast::def_id {
|
did: ast::def_id) -> ast::def_id {
|
||||||
|
|
|
@ -340,8 +340,18 @@ pub mod reader {
|
||||||
f()
|
f()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
fn read_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T {
|
fn read_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T {
|
||||||
debug!("read_field(name=%s, idx=%u)", name, idx);
|
debug!("read_field(name=%?, idx=%u)", name, idx);
|
||||||
|
self._check_label(name);
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(stage1)]
|
||||||
|
#[cfg(stage2)]
|
||||||
|
#[cfg(stage3)]
|
||||||
|
fn read_struct_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T {
|
||||||
|
debug!("read_struct_field(name=%?, idx=%u)", name, idx);
|
||||||
self._check_label(name);
|
self._check_label(name);
|
||||||
f()
|
f()
|
||||||
}
|
}
|
||||||
|
@ -614,10 +624,18 @@ pub mod writer {
|
||||||
fn emit_enum_variant_arg(&self, _idx: uint, f: &fn()) { f() }
|
fn emit_enum_variant_arg(&self, _idx: uint, f: &fn()) { f() }
|
||||||
|
|
||||||
fn emit_struct(&self, _name: &str, _len: uint, f: &fn()) { f() }
|
fn emit_struct(&self, _name: &str, _len: uint, f: &fn()) { f() }
|
||||||
|
#[cfg(stage0)]
|
||||||
fn emit_field(&self, name: &str, _idx: uint, f: &fn()) {
|
fn emit_field(&self, name: &str, _idx: uint, f: &fn()) {
|
||||||
self._emit_label(name);
|
self._emit_label(name);
|
||||||
f()
|
f()
|
||||||
}
|
}
|
||||||
|
#[cfg(stage1)]
|
||||||
|
#[cfg(stage2)]
|
||||||
|
#[cfg(stage3)]
|
||||||
|
fn emit_struct_field(&self, name: &str, _idx: uint, f: &fn()) {
|
||||||
|
self._emit_label(name);
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
|
||||||
fn emit_option(&self, f: &fn()) {
|
fn emit_option(&self, f: &fn()) {
|
||||||
self.emit_enum("Option", f);
|
self.emit_enum("Option", f);
|
||||||
|
|
|
@ -135,12 +135,22 @@ impl serialize::Encoder for Encoder {
|
||||||
f();
|
f();
|
||||||
self.wr.write_char('}');
|
self.wr.write_char('}');
|
||||||
}
|
}
|
||||||
|
#[cfg(stage0)]
|
||||||
fn emit_field(&self, name: &str, idx: uint, f: &fn()) {
|
fn emit_field(&self, name: &str, idx: uint, f: &fn()) {
|
||||||
if idx != 0 { self.wr.write_char(','); }
|
if idx != 0 { self.wr.write_char(','); }
|
||||||
self.wr.write_str(escape_str(name));
|
self.wr.write_str(escape_str(name));
|
||||||
self.wr.write_char(':');
|
self.wr.write_char(':');
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
|
#[cfg(stage1)]
|
||||||
|
#[cfg(stage2)]
|
||||||
|
#[cfg(stage3)]
|
||||||
|
fn emit_struct_field(&self, name: &str, idx: uint, f: &fn()) {
|
||||||
|
if idx != 0 { self.wr.write_char(','); }
|
||||||
|
self.wr.write_str(escape_str(name));
|
||||||
|
self.wr.write_char(':');
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
|
||||||
fn emit_option(&self, f: &fn()) { f(); }
|
fn emit_option(&self, f: &fn()) { f(); }
|
||||||
fn emit_option_none(&self) { self.emit_nil(); }
|
fn emit_option_none(&self) { self.emit_nil(); }
|
||||||
|
@ -254,6 +264,7 @@ impl serialize::Encoder for PrettyEncoder {
|
||||||
self.wr.write_char('}');
|
self.wr.write_char('}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(stage0)]
|
||||||
fn emit_field(&self, name: &str, idx: uint, f: &fn()) {
|
fn emit_field(&self, name: &str, idx: uint, f: &fn()) {
|
||||||
if idx == 0 {
|
if idx == 0 {
|
||||||
self.wr.write_char('\n');
|
self.wr.write_char('\n');
|
||||||
|
@ -265,6 +276,20 @@ impl serialize::Encoder for PrettyEncoder {
|
||||||
self.wr.write_str(": ");
|
self.wr.write_str(": ");
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
|
#[cfg(stage1)]
|
||||||
|
#[cfg(stage2)]
|
||||||
|
#[cfg(stage3)]
|
||||||
|
fn emit_struct_field(&self, name: &str, idx: uint, f: &fn()) {
|
||||||
|
if idx == 0 {
|
||||||
|
self.wr.write_char('\n');
|
||||||
|
} else {
|
||||||
|
self.wr.write_str(",\n");
|
||||||
|
}
|
||||||
|
self.wr.write_str(spaces(self.indent));
|
||||||
|
self.wr.write_str(escape_str(name));
|
||||||
|
self.wr.write_str(": ");
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
|
||||||
fn emit_option(&self, f: &fn()) { f(); }
|
fn emit_option(&self, f: &fn()) { f(); }
|
||||||
fn emit_option_none(&self) { self.emit_nil(); }
|
fn emit_option_none(&self) { self.emit_nil(); }
|
||||||
|
@ -834,8 +859,31 @@ impl serialize::Decoder for Decoder {
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(stage0)]
|
||||||
fn read_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T {
|
fn read_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T {
|
||||||
debug!("read_field(%s, idx=%u)", name, idx);
|
debug!("read_field(name=%?, idx=%u)", name, idx);
|
||||||
|
match self.stack.pop() {
|
||||||
|
Object(obj) => {
|
||||||
|
let mut obj = obj;
|
||||||
|
let value = match obj.pop(&name.to_owned()) {
|
||||||
|
None => fail!(fmt!("no such field: %s", name)),
|
||||||
|
Some(json) => {
|
||||||
|
self.stack.push(json);
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
self.stack.push(Object(obj));
|
||||||
|
value
|
||||||
|
}
|
||||||
|
value => fail!(fmt!("not an object: %?", value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(stage1)]
|
||||||
|
#[cfg(stage2)]
|
||||||
|
#[cfg(stage3)]
|
||||||
|
fn read_struct_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T {
|
||||||
|
debug!("read_struct_field(name=%?, idx=%u)", name, idx);
|
||||||
match self.stack.pop() {
|
match self.stack.pop() {
|
||||||
Object(obj) => {
|
Object(obj) => {
|
||||||
let mut obj = obj;
|
let mut obj = obj;
|
||||||
|
|
|
@ -48,8 +48,13 @@ pub trait Encoder {
|
||||||
fn emit_enum_variant(&self, v_name: &str, v_id: uint, sz: uint, f: &fn());
|
fn emit_enum_variant(&self, v_name: &str, v_id: uint, sz: uint, f: &fn());
|
||||||
fn emit_enum_variant_arg(&self, idx: uint, f: &fn());
|
fn emit_enum_variant_arg(&self, idx: uint, f: &fn());
|
||||||
|
|
||||||
fn emit_struct(&self, name: &str, _len: uint, f: &fn());
|
fn emit_struct(&self, name: &str, len: uint, f: &fn());
|
||||||
|
#[cfg(stage0)]
|
||||||
fn emit_field(&self, f_name: &str, f_idx: uint, f: &fn());
|
fn emit_field(&self, f_name: &str, f_idx: uint, f: &fn());
|
||||||
|
#[cfg(stage1)]
|
||||||
|
#[cfg(stage2)]
|
||||||
|
#[cfg(stage3)]
|
||||||
|
fn emit_struct_field(&self, f_name: &str, f_idx: uint, f: &fn());
|
||||||
|
|
||||||
// Specialized types:
|
// Specialized types:
|
||||||
fn emit_option(&self, f: &fn());
|
fn emit_option(&self, f: &fn());
|
||||||
|
@ -89,8 +94,13 @@ pub trait Decoder {
|
||||||
fn read_enum_variant<T>(&self, names: &[&str], f: &fn(uint) -> T) -> T;
|
fn read_enum_variant<T>(&self, names: &[&str], f: &fn(uint) -> T) -> T;
|
||||||
fn read_enum_variant_arg<T>(&self, idx: uint, f: &fn() -> T) -> T;
|
fn read_enum_variant_arg<T>(&self, idx: uint, f: &fn() -> T) -> T;
|
||||||
|
|
||||||
fn read_struct<T>(&self, name: &str, _len: uint, f: &fn() -> T) -> T;
|
fn read_struct<T>(&self, s_name: &str, len: uint, f: &fn() -> T) -> T;
|
||||||
fn read_field<T>(&self, name: &str, idx: uint, f: &fn() -> T) -> T;
|
#[cfg(stage0)]
|
||||||
|
fn read_field<T>(&self, f_name: &str, f_idx: uint, f: &fn() -> T) -> T;
|
||||||
|
#[cfg(stage1)]
|
||||||
|
#[cfg(stage2)]
|
||||||
|
#[cfg(stage3)]
|
||||||
|
fn read_struct_field<T>(&self, f_name: &str, f_idx: uint, f: &fn() -> T) -> T;
|
||||||
|
|
||||||
// Specialized types:
|
// Specialized types:
|
||||||
fn read_option<T>(&self, f: &fn(bool) -> T) -> T;
|
fn read_option<T>(&self, f: &fn(bool) -> T) -> T;
|
||||||
|
|
|
@ -732,12 +732,12 @@ fn mk_struct_ser_impl(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// ast for `__s.emit_field($(name), $(idx), $(expr_lambda))`
|
// ast for `__s.emit_struct_field($(name), $(idx), $(expr_lambda))`
|
||||||
cx.stmt(
|
cx.stmt(
|
||||||
cx.expr_method_call(
|
cx.expr_method_call(
|
||||||
span,
|
span,
|
||||||
cx.expr_var(span, ~"__s"),
|
cx.expr_var(span, ~"__s"),
|
||||||
cx.ident_of(~"emit_field"),
|
cx.ident_of(~"emit_struct_field"),
|
||||||
~[
|
~[
|
||||||
cx.lit_str(span, @cx.str_of(field.ident)),
|
cx.lit_str(span, @cx.str_of(field.ident)),
|
||||||
cx.lit_uint(span, idx),
|
cx.lit_uint(span, idx),
|
||||||
|
@ -786,11 +786,11 @@ fn mk_struct_deser_impl(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// ast for `__d.read_field($(name), $(idx), $(expr_lambda))`
|
// ast for `__d.read_struct_field($(name), $(idx), $(expr_lambda))`
|
||||||
let expr: @ast::expr = cx.expr_method_call(
|
let expr: @ast::expr = cx.expr_method_call(
|
||||||
span,
|
span,
|
||||||
cx.expr_var(span, ~"__d"),
|
cx.expr_var(span, ~"__d"),
|
||||||
cx.ident_of(~"read_field"),
|
cx.ident_of(~"read_struct_field"),
|
||||||
~[
|
~[
|
||||||
cx.lit_str(span, @cx.str_of(field.ident)),
|
cx.lit_str(span, @cx.str_of(field.ident)),
|
||||||
cx.lit_uint(span, idx),
|
cx.lit_uint(span, idx),
|
||||||
|
@ -1256,7 +1256,7 @@ mod test {
|
||||||
fn emit_struct(&self, name: &str, +len: uint, f: &fn()) {
|
fn emit_struct(&self, name: &str, +len: uint, f: &fn()) {
|
||||||
self.add_to_log(CallToEmitStruct (name.to_str(),len)); f();
|
self.add_to_log(CallToEmitStruct (name.to_str(),len)); f();
|
||||||
}
|
}
|
||||||
fn emit_field(&self, name: &str, +idx: uint, f: &fn()) {
|
fn emit_struct_field(&self, name: &str, +idx: uint, f: &fn()) {
|
||||||
self.add_to_log(CallToEmitField (name.to_str(),idx)); f();
|
self.add_to_log(CallToEmitField (name.to_str(),idx)); f();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue