Skip to content

Commit f1d0478

Browse files
committed
Add cfg attrs to handle auto_encode transition
1 parent fc582bc commit f1d0478

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

src/libstd/ebml.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,14 @@ pub mod reader {
379379
f()
380380
}
381381

382+
#[cfg(stage0)]
383+
fn read_struct<T>(&self, name: &str, f: fn() -> T) -> T {
384+
debug!("read_struct(name=%s)", name);
385+
f()
386+
}
387+
#[cfg(stage1)]
388+
#[cfg(stage2)]
389+
#[cfg(stage3)]
382390
fn read_struct<T>(&self, name: &str, _len: uint, f: fn() -> T) -> T {
383391
debug!("read_struct(name=%s)", name);
384392
f()
@@ -658,6 +666,11 @@ pub mod writer {
658666
}
659667

660668
fn emit_rec(&self, f: fn()) { f() }
669+
#[cfg(stage0)]
670+
fn emit_struct(&self, _name: &str, f: fn()) { f() }
671+
#[cfg(stage1)]
672+
#[cfg(stage2)]
673+
#[cfg(stage3)]
661674
fn emit_struct(&self, _name: &str, _len: uint, f: fn()) { f() }
662675
fn emit_field(&self, name: &str, _idx: uint, f: fn()) {
663676
self._emit_label(name);

src/libstd/json.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ pub impl Encoder: serialize::Encoder {
157157
f();
158158
self.wr.write_char('}');
159159
}
160+
#[cfg(stage0)]
161+
fn emit_struct(&self, _name: &str, f: fn()) {
162+
self.wr.write_char('{');
163+
f();
164+
self.wr.write_char('}');
165+
}
166+
#[cfg(stage1)]
167+
#[cfg(stage2)]
168+
#[cfg(stage3)]
160169
fn emit_struct(&self, _name: &str, _len: uint, f: fn()) {
161170
self.wr.write_char('{');
162171
f();
@@ -270,6 +279,13 @@ pub impl PrettyEncoder: serialize::Encoder {
270279
self.indent -= 2;
271280
self.wr.write_char('}');
272281
}
282+
#[cfg(stage0)]
283+
fn emit_struct(&self, _name: &str, f: fn()) {
284+
self.emit_rec(f)
285+
}
286+
#[cfg(stage1)]
287+
#[cfg(stage2)]
288+
#[cfg(stage3)]
273289
fn emit_struct(&self, _name: &str, _len: uint, f: fn()) {
274290
self.emit_rec(f)
275291
}
@@ -870,6 +886,16 @@ pub impl Decoder: serialize::Decoder {
870886
move value
871887
}
872888

889+
#[cfg(stage0)]
890+
fn read_struct<T>(&self, _name: &str, f: fn() -> T) -> T {
891+
debug!("read_struct()");
892+
let value = f();
893+
self.pop();
894+
move value
895+
}
896+
#[cfg(stage1)]
897+
#[cfg(stage2)]
898+
#[cfg(stage3)]
873899
fn read_struct<T>(&self, _name: &str, _len: uint, f: fn() -> T) -> T {
874900
debug!("read_struct()");
875901
let value = f();

src/libstd/prettyprint.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ pub impl Serializer: serialize::Encoder {
162162
self.wr.write_str(~"}");
163163
}
164164

165+
#[cfg(stage0)]
166+
fn emit_struct(&self, name: &str, f: fn()) {
167+
self.wr.write_str(fmt!("%s {", name));
168+
f();
169+
self.wr.write_str(~"}");
170+
}
171+
#[cfg(stage1)]
172+
#[cfg(stage2)]
173+
#[cfg(stage3)]
165174
fn emit_struct(&self, name: &str, _len: uint, f: fn()) {
166175
self.wr.write_str(fmt!("%s {", name));
167176
f();

src/libstd/serialize.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ pub trait Encoder {
5858
fn emit_vec_elt(&self, idx: uint, f: fn());
5959

6060
fn emit_rec(&self, f: fn());
61+
#[cfg(stage0)]
62+
fn emit_struct(&self, name: &str, f: fn());
63+
#[cfg(stage1)]
64+
#[cfg(stage2)]
65+
#[cfg(stage3)]
6166
fn emit_struct(&self, name: &str, _len: uint, f: fn());
6267
fn emit_field(&self, f_name: &str, f_idx: uint, f: fn());
6368

@@ -99,6 +104,11 @@ pub trait Decoder {
99104
fn read_vec_elt<T>(&self, idx: uint, f: fn() -> T) -> T;
100105

101106
fn read_rec<T>(&self, f: fn() -> T) -> T;
107+
#[cfg(stage0)]
108+
fn read_struct<T>(&self, name: &str, f: fn() -> T) -> T;
109+
#[cfg(stage1)]
110+
#[cfg(stage2)]
111+
#[cfg(stage3)]
102112
fn read_struct<T>(&self, name: &str, _len: uint, f: fn() -> T) -> T;
103113
fn read_field<T>(&self, name: &str, idx: uint, f: fn() -> T) -> T;
104114

0 commit comments

Comments
 (0)