From d65140f2d265cf7a1e9dec305ba97b0db7010769 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Mon, 19 Nov 2012 13:05:22 -0800 Subject: [PATCH] Make DebugMethods pure; fix uses in flow and box (somewhat barbarically). --- src/servo/dom/node.rs | 13 ++++++++----- src/servo/layout/box.rs | 6 +++--- src/servo/layout/debug.rs | 12 ++++++------ src/servo/layout/flow.rs | 13 ++++++++----- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/servo/dom/node.rs b/src/servo/dom/node.rs index 6f990397f14c..d3460de023d4 100644 --- a/src/servo/dom/node.rs +++ b/src/servo/dom/node.rs @@ -52,11 +52,11 @@ impl Node { impl Node : DebugMethods { /* Dumps the subtree rooted at this node, for debugging. */ - fn dump(&self) { + pure fn dump(&self) { self.dump_indent(0u); } /* Dumps the node tree, for debugging, with indentation. */ - fn dump_indent(&self, indent: uint) { + pure fn dump_indent(&self, indent: uint) { let mut s = ~""; for uint::range(0u, indent) |_i| { s += ~" "; @@ -65,12 +65,15 @@ impl Node : DebugMethods { s += self.debug_str(); debug!("%s", s); - for NodeTree.each_child(self) |kid| { - kid.dump_indent(indent + 1u) + // FIXME: this should have a pure version? + unsafe { + for NodeTree.each_child(self) |kid| { + kid.dump_indent(indent + 1u) + } } } - fn debug_str(&self) -> ~str { + pure fn debug_str(&self) -> ~str unsafe { do self.read |n| { fmt!("%?", n.kind) } } } diff --git a/src/servo/layout/box.rs b/src/servo/layout/box.rs index f1462aa533b3..da280bd22fde 100644 --- a/src/servo/layout/box.rs +++ b/src/servo/layout/box.rs @@ -576,12 +576,12 @@ impl RenderBox : RenderBoxMethods { } impl RenderBox : BoxedDebugMethods { - fn dump(@self) { + pure fn dump(@self) { self.dump_indent(0u); } /* Dumps the node tree, for debugging, with indentation. */ - fn dump_indent(@self, indent: uint) { + pure fn dump_indent(@self, indent: uint) { let mut s = ~""; for uint::range(0u, indent) |_i| { s += ~" "; @@ -591,7 +591,7 @@ impl RenderBox : BoxedDebugMethods { debug!("%s", s); } - fn debug_str(@self) -> ~str { + pure fn debug_str(@self) -> ~str { let repr = match self { @GenericBox(*) => ~"GenericBox", @ImageBox(*) => ~"ImageBox", diff --git a/src/servo/layout/debug.rs b/src/servo/layout/debug.rs index 033706fa746b..5833abb76e0c 100644 --- a/src/servo/layout/debug.rs +++ b/src/servo/layout/debug.rs @@ -1,11 +1,11 @@ trait BoxedDebugMethods { - fn dump(@self); - fn dump_indent(@self, ident: uint); - fn debug_str(@self) -> ~str; + pure fn dump(@self); + pure fn dump_indent(@self, ident: uint); + pure fn debug_str(@self) -> ~str; } trait DebugMethods { - fn dump(&self); - fn dump_indent(&self, ident: uint); - fn debug_str(&self) -> ~str; + pure fn dump(&self); + pure fn dump_indent(&self, ident: uint); + pure fn debug_str(&self) -> ~str; } diff --git a/src/servo/layout/flow.rs b/src/servo/layout/flow.rs index 00a4e5b6c39b..ad3a894d7466 100644 --- a/src/servo/layout/flow.rs +++ b/src/servo/layout/flow.rs @@ -242,12 +242,12 @@ impl FlowTree : tree::WriteMethods<@FlowContext> { impl FlowContext : BoxedDebugMethods { - fn dump(@self) { + pure fn dump(@self) { self.dump_indent(0u); } /** Dumps the flow tree, for debugging, with indentation. */ - fn dump_indent(@self, indent: uint) { + pure fn dump_indent(@self, indent: uint) { let mut s = ~"|"; for uint::range(0u, indent) |_i| { s += ~"---- "; @@ -256,12 +256,15 @@ impl FlowContext : BoxedDebugMethods { s += self.debug_str(); debug!("%s", s); - for FlowTree.each_child(self) |child| { - child.dump_indent(indent + 1u) + // FIXME: this should have a pure/const version? + unsafe { + for FlowTree.each_child(self) |child| { + child.dump_indent(indent + 1u) + } } } - fn debug_str(@self) -> ~str { + pure fn debug_str(@self) -> ~str { let repr = match *self { InlineFlow(*) => { let mut s = self.inline().boxes.foldl(~"InlineFlow(children=", |s, box| {