From 56507798d9eb7bcf95bfca15b3c6f18997adae63 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 3 May 2013 15:45:55 -0700 Subject: [PATCH] libcore: Remove mutable fields from repr --- src/libcore/repr.rs | 71 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 13 deletions(-) diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs index 3d5259932592..b75ac60ff28e 100644 --- a/src/libcore/repr.rs +++ b/src/libcore/repr.rs @@ -144,28 +144,30 @@ enum VariantState { } pub struct ReprVisitor { - mut ptr: *c_void, - mut ptr_stk: ~[*c_void], - mut var_stk: ~[VariantState], + ptr: @mut *c_void, + ptr_stk: @mut ~[*c_void], + var_stk: @mut ~[VariantState], writer: @Writer } pub fn ReprVisitor(ptr: *c_void, writer: @Writer) -> ReprVisitor { - ReprVisitor { ptr: ptr, - ptr_stk: ~[], - var_stk: ~[], - writer: writer } + ReprVisitor { + ptr: @mut ptr, + ptr_stk: @mut ~[], + var_stk: @mut ~[], + writer: writer, + } } impl MovePtr for ReprVisitor { #[inline(always)] fn move_ptr(&self, adjustment: &fn(*c_void) -> *c_void) { - self.ptr = adjustment(self.ptr); + *self.ptr = adjustment(*self.ptr); } fn push_ptr(&self) { - self.ptr_stk.push(self.ptr); + self.ptr_stk.push(*self.ptr); } fn pop_ptr(&self) { - self.ptr = self.ptr_stk.pop(); + *self.ptr = self.ptr_stk.pop(); } } @@ -176,14 +178,14 @@ pub impl ReprVisitor { #[inline(always)] fn get(&self, f: &fn(&T)) -> bool { unsafe { - f(transmute::<*c_void,&T>(copy self.ptr)); + f(transmute::<*c_void,&T>(*self.ptr)); } true } #[inline(always)] fn visit_inner(&self, inner: *TyDesc) -> bool { - self.visit_ptr_inner(self.ptr, inner) + self.visit_ptr_inner(*self.ptr, inner) } #[inline(always)] @@ -482,8 +484,31 @@ impl TyVisitor for ReprVisitor { true } +<<<<<<< HEAD fn visit_enum_variant_field(&self, i: uint, _offset: uint, inner: *TyDesc) -> bool { match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] { +======= + #[cfg(stage0)] + fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool { + match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { + Degenerate | TagMatch => { + if i != 0 { + self.writer.write_str(", "); + } + if ! self.visit_inner(inner) { + return false; + } + } + TagMismatch => () + } + true + } + + #[cfg(not(stage0))] + fn visit_enum_variant_field(&self, i: uint, _: uint, inner: *TyDesc) + -> bool { + match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { +>>>>>>> libcore: Remove mutable fields from repr Matched => { if i != 0 { self.writer.write_str(", "); @@ -497,11 +522,31 @@ impl TyVisitor for ReprVisitor { true } +<<<<<<< HEAD +======= + #[cfg(stage0)] fn visit_leave_enum_variant(&self, _variant: uint, _disr_val: int, n_fields: uint, _name: &str) -> bool { - match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] { + match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { + Degenerate | TagMatch => { + if n_fields > 0 { + self.writer.write_char(')'); + } + } + TagMismatch => () + } + true + } + + #[cfg(not(stage0))] +>>>>>>> libcore: Remove mutable fields from repr + fn visit_leave_enum_variant(&self, _variant: uint, + _disr_val: int, + n_fields: uint, + _name: &str) -> bool { + match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { Matched => { if n_fields > 0 { self.writer.write_char(')');