Eliminate warnings in util::tree

This commit is contained in:
Brian Anderson 2012-10-08 17:56:42 -07:00
parent e8ee1be88e
commit a272a50635
8 changed files with 45 additions and 45 deletions

View file

@ -108,8 +108,8 @@ impl StyleApplicator {
fn apply_css_style(layout_ctx: &LayoutContext) { fn apply_css_style(layout_ctx: &LayoutContext) {
let reflow = copy self.reflow; let reflow = copy self.reflow;
do NodeTree.each_child(self.node) |child| { do NodeTree.each_child(&self.node) |child| {
inheritance_wrapper(layout_ctx, child, reflow); true inheritance_wrapper(layout_ctx, *child, reflow); true
} }
} }

View file

@ -146,7 +146,7 @@ impl Node : StyleMethods {
let mut i = 0u; let mut i = 0u;
// Compute the styles of each of our children in parallel // Compute the styles of each of our children in parallel
for NodeTree.each_child(self) |kid| { for NodeTree.each_child(&self) |kid| {
i = i + 1u; i = i + 1u;
let new_styles = clone(&styles); let new_styles = clone(&styles);

View file

@ -27,8 +27,8 @@ enum NodeData = {
enum NodeTree { NodeTree } enum NodeTree { NodeTree }
impl NodeTree : tree::ReadMethods<Node> { impl NodeTree : tree::ReadMethods<Node> {
fn each_child(node: Node, f: fn(Node) -> bool) { fn each_child(node: &Node, f: fn(&Node) -> bool) {
tree::each_child(self, node, f) tree::each_child(&self, node, f)
} }
fn with_tree_fields<R>(&&n: Node, f: fn(tree::Tree<Node>) -> R) -> R { fn with_tree_fields<R>(&&n: Node, f: fn(tree::Tree<Node>) -> R) -> R {
@ -39,11 +39,11 @@ impl NodeTree : tree::ReadMethods<Node> {
impl Node { impl Node {
fn traverse_preorder(preorder_cb: &fn(Node)) { fn traverse_preorder(preorder_cb: &fn(Node)) {
preorder_cb(self); preorder_cb(self);
do NodeTree.each_child(self) |child| { child.traverse_preorder(preorder_cb); true } do NodeTree.each_child(&self) |child| { child.traverse_preorder(preorder_cb); true }
} }
fn traverse_postorder(postorder_cb: &fn(Node)) { fn traverse_postorder(postorder_cb: &fn(Node)) {
do NodeTree.each_child(self) |child| { child.traverse_postorder(postorder_cb); true } do NodeTree.each_child(&self) |child| { child.traverse_postorder(postorder_cb); true }
postorder_cb(self); postorder_cb(self);
} }
} }
@ -77,7 +77,7 @@ impl Node : DebugMethods {
s += self.debug_str(); s += self.debug_str();
debug!("%s", s); debug!("%s", s);
for NodeTree.each_child(*self) |kid| { for NodeTree.each_child(self) |kid| {
kid.dump_indent(indent + 1u) kid.dump_indent(indent + 1u)
} }
} }
@ -153,12 +153,12 @@ impl NodeScope : NodeScopeExtensions {
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
impl NodeScope : tree::ReadMethods<Node> { impl NodeScope : tree::ReadMethods<Node> {
fn each_child(node: Node, f: fn(Node) -> bool) { fn each_child(node: &Node, f: fn(&Node) -> bool) {
tree::each_child(self, node, f) tree::each_child(&self, node, f)
} }
fn get_parent(node: Node) -> Option<Node> { fn get_parent(node: &Node) -> Option<Node> {
tree::get_parent(self, node) tree::get_parent(&self, node)
} }
fn with_tree_fields<R>(node: Node, f: fn(tree::Tree<Node>) -> R) -> R { fn with_tree_fields<R>(node: Node, f: fn(tree::Tree<Node>) -> R) -> R {
@ -168,8 +168,8 @@ impl NodeScope : tree::ReadMethods<Node> {
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
impl NodeScope : tree::WriteMethods<Node> { impl NodeScope : tree::WriteMethods<Node> {
fn add_child(node: Node, child: Node) { fn add_child(+node: Node, +child: Node) {
tree::add_child(self, node, child) tree::add_child(&self, node, child)
} }
fn with_tree_fields<R>(node: Node, f: fn(tree::Tree<Node>) -> R) -> R { fn with_tree_fields<R>(node: Node, f: fn(tree::Tree<Node>) -> R) -> R {

View file

@ -304,8 +304,8 @@ trait ImageBoxMethods {
pub enum RenderBoxTree { RenderBoxTree } pub enum RenderBoxTree { RenderBoxTree }
impl RenderBoxTree : tree::ReadMethods<@RenderBox> { impl RenderBoxTree : tree::ReadMethods<@RenderBox> {
fn each_child(node: @RenderBox, f: fn(&&box: @RenderBox) -> bool) { fn each_child(node: @RenderBox, f: fn(box: @RenderBox) -> bool) {
tree::each_child(self, node, f) tree::each_child(&self, &node, |box| f(*box) )
} }
fn with_tree_fields<R>(&&b: @RenderBox, f: fn(tree::Tree<@RenderBox>) -> R) -> R { fn with_tree_fields<R>(&&b: @RenderBox, f: fn(tree::Tree<@RenderBox>) -> R) -> R {
@ -316,7 +316,7 @@ impl RenderBoxTree : tree::ReadMethods<@RenderBox> {
impl RenderBoxTree : tree::WriteMethods<@RenderBox> { impl RenderBoxTree : tree::WriteMethods<@RenderBox> {
fn add_child(parent: @RenderBox, child: @RenderBox) { fn add_child(parent: @RenderBox, child: @RenderBox) {
assert !core::box::ptr_eq(parent, child); assert !core::box::ptr_eq(parent, child);
tree::add_child(self, parent, child) tree::add_child(&self, parent, child)
} }
fn with_tree_fields<R>(&&b: @RenderBox, f: fn(tree::Tree<@RenderBox>) -> R) -> R { fn with_tree_fields<R>(&&b: @RenderBox, f: fn(tree::Tree<@RenderBox>) -> R) -> R {
@ -384,8 +384,8 @@ mod test {
fn flat_bounds(root: @RenderBox) -> ~[Rect<au>] { fn flat_bounds(root: @RenderBox) -> ~[Rect<au>] {
let mut r = ~[]; let mut r = ~[];
for tree::each_child(RenderBoxTree, root) |c| { for tree::each_child(&RenderBoxTree, &root) |c| {
push_all(&mut r, flat_bounds(c)); push_all(&mut r, flat_bounds(*c));
} }
push(&mut r, copy root.d().position); push(&mut r, copy root.d().position);

View file

@ -126,8 +126,8 @@ impl LayoutTreeBuilder {
} }
// recurse // recurse
// TODO: don't set parent box unless this is an inline flow? // TODO: don't set parent box unless this is an inline flow?
do NodeTree.each_child(cur_node) |child_node| { do NodeTree.each_child(&cur_node) |child_node| {
self.construct_recursively(layout_ctx, child_node, next_ctx, Some(new_box)); true self.construct_recursively(layout_ctx, *child_node, next_ctx, Some(new_box)); true
} }
// Fixup any irregularities, such as split inlines (CSS 2.1 Section 9.2.1.1) // Fixup any irregularities, such as split inlines (CSS 2.1 Section 9.2.1.1)

View file

@ -213,8 +213,8 @@ impl FlowContext {
enum FlowTree { FlowTree } enum FlowTree { FlowTree }
impl FlowTree : tree::ReadMethods<@FlowContext> { impl FlowTree : tree::ReadMethods<@FlowContext> {
fn each_child(ctx: @FlowContext, f: fn(&&box: @FlowContext) -> bool) { fn each_child(ctx: @FlowContext, f: fn(box: @FlowContext) -> bool) {
tree::each_child(self, ctx, f) tree::each_child(&self, &ctx, |box| f(*box) )
} }
fn with_tree_fields<R>(&&box: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R { fn with_tree_fields<R>(&&box: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R {
@ -225,7 +225,7 @@ impl FlowTree : tree::ReadMethods<@FlowContext> {
impl FlowTree : tree::WriteMethods<@FlowContext> { impl FlowTree : tree::WriteMethods<@FlowContext> {
fn add_child(parent: @FlowContext, child: @FlowContext) { fn add_child(parent: @FlowContext, child: @FlowContext) {
assert !core::box::ptr_eq(parent, child); assert !core::box::ptr_eq(parent, child);
tree::add_child(self, parent, child) tree::add_child(&self, parent, child)
} }
fn with_tree_fields<R>(&&box: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R { fn with_tree_fields<R>(&&box: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R {

View file

@ -69,13 +69,13 @@ impl Color {
mod parsing { mod parsing {
export parse_color; export parse_color;
fn fail_unrecognized(col : ~str) -> Option<Color> { fn fail_unrecognized(col : &str) -> Option<Color> {
warn!("Unrecognized color %s", col); warn!("Unrecognized color %s", col);
return None; return None;
} }
/** Match an exact color keyword. */ /** Match an exact color keyword. */
fn parse_by_name(color : ~str) -> Option<Color> { fn parse_by_name(color : &str) -> Option<Color> {
let col = match color.to_lower() { let col = match color.to_lower() {
~"black" => black(), ~"black" => black(),
~"silver" => silver(), ~"silver" => silver(),
@ -101,7 +101,7 @@ mod parsing {
} }
/** Parses a color specification in the form rgb(foo,bar,baz) */ /** Parses a color specification in the form rgb(foo,bar,baz) */
fn parse_rgb(color : ~str) -> Option<Color> { fn parse_rgb(color : &str) -> Option<Color> {
// Shave off the rgb( and the ) // Shave off the rgb( and the )
let only_colors = color.substr(4u, color.len() - 5u); let only_colors = color.substr(4u, color.len() - 5u);
@ -117,7 +117,7 @@ mod parsing {
} }
/** Parses a color specification in the form rgba(foo,bar,baz,qux) */ /** Parses a color specification in the form rgba(foo,bar,baz,qux) */
fn parse_rgba(color : ~str) -> Option<Color> { fn parse_rgba(color : &str) -> Option<Color> {
// Shave off the rgba( and the ) // Shave off the rgba( and the )
let only_vals = color.substr(5u, color.len() - 6u); let only_vals = color.substr(5u, color.len() - 6u);
@ -133,7 +133,7 @@ mod parsing {
} }
/** Parses a color specification in the form hsl(foo,bar,baz) */ /** Parses a color specification in the form hsl(foo,bar,baz) */
fn parse_hsl(color : ~str) -> Option<Color> { fn parse_hsl(color : &str) -> Option<Color> {
// Shave off the hsl( and the ) // Shave off the hsl( and the )
let only_vals = color.substr(4u, color.len() - 5u); let only_vals = color.substr(4u, color.len() - 5u);
@ -149,7 +149,7 @@ mod parsing {
} }
/** Parses a color specification in the form hsla(foo,bar,baz,qux) */ /** Parses a color specification in the form hsla(foo,bar,baz,qux) */
fn parse_hsla(color : ~str) -> Option<Color> { fn parse_hsla(color : &str) -> Option<Color> {
// Shave off the hsla( and the ) // Shave off the hsla( and the )
let only_vals = color.substr(5u, color.len() - 6u); let only_vals = color.substr(5u, color.len() - 6u);
@ -166,12 +166,12 @@ mod parsing {
// Currently colors are supported in rgb(a,b,c) form and also by // Currently colors are supported in rgb(a,b,c) form and also by
// keywords for several common colors. // keywords for several common colors.
// TODO: extend this // TODO: extend this
fn parse_color(color : ~str) -> Option<Color> { fn parse_color(color : &str) -> Option<Color> {
match color { match color {
c if c.starts_with(~"rgb(") => parse_rgb(c), c if c.starts_with("rgb(") => parse_rgb(c),
c if c.starts_with(~"rgba(") => parse_rgba(c), c if c.starts_with("rgba(") => parse_rgba(c),
c if c.starts_with(~"hsl(") => parse_hsl(c), c if c.starts_with("hsl(") => parse_hsl(c),
c if c.starts_with(~"hsla(") => parse_hsla(c), c if c.starts_with("hsla(") => parse_hsla(c),
c => parse_by_name(c) c => parse_by_name(c)
} }
} }

View file

@ -20,14 +20,14 @@ pub trait WriteMethods<T> {
fn with_tree_fields<R>(T, f: fn(Tree<T>) -> R) -> R; fn with_tree_fields<R>(T, f: fn(Tree<T>) -> R) -> R;
} }
pub fn each_child<T:Copy,O:ReadMethods<T>>(ops: O, node: T, f: fn(T) -> bool) { pub fn each_child<T:Copy,O:ReadMethods<T>>(ops: &O, node: &T, f: fn(&T) -> bool) {
let mut p = ops.with_tree_fields(node, |f| f.first_child); let mut p = ops.with_tree_fields(*node, |f| f.first_child);
loop { loop {
match copy p { match copy p {
None => { return; } None => { return; }
Some(c) => { Some(ref c) => {
if !f(c) { return; } if !f(c) { return; }
p = ops.with_tree_fields(c, |f| f.next_sibling); p = ops.with_tree_fields(*c, |f| f.next_sibling);
} }
} }
} }
@ -41,7 +41,7 @@ pub fn empty<T>() -> Tree<T> {
mut next_sibling: None} mut next_sibling: None}
} }
pub fn add_child<T:Copy,O:WriteMethods<T>>(ops: O, parent: T, child: T) { pub fn add_child<T:Copy,O:WriteMethods<T>>(ops: &O, +parent: T, +child: T) {
ops.with_tree_fields(child, |child_tf| { ops.with_tree_fields(child, |child_tf| {
match child_tf.parent { match child_tf.parent {
@ -72,8 +72,8 @@ pub fn add_child<T:Copy,O:WriteMethods<T>>(ops: O, parent: T, child: T) {
}); });
} }
pub fn get_parent<T:Copy,O:ReadMethods<T>>(ops: O, node: T) -> Option<T> { pub fn get_parent<T:Copy,O:ReadMethods<T>>(ops: &O, node: &T) -> Option<T> {
ops.with_tree_fields(node, |tf| tf.parent) ops.with_tree_fields(*node, |tf| tf.parent)
} }
#[cfg(test)] #[cfg(test)]
@ -108,7 +108,7 @@ mod test {
let p = new_dummy(3u); let p = new_dummy(3u);
for vec::each(children) |c| { for vec::each(children) |c| {
add_child(dtree, p, *c); add_child(&dtree, p, *c);
} }
return {p: p, children: children}; return {p: p, children: children};
@ -118,7 +118,7 @@ mod test {
fn add_child_0() { fn add_child_0() {
let {p, children} = parent_with_3_children(); let {p, children} = parent_with_3_children();
let mut i = 0u; let mut i = 0u;
for each_child(dtree, p) |c| { for each_child(&dtree, &p) |c| {
assert c.value == i; assert c.value == i;
i += 1u; i += 1u;
} }
@ -129,7 +129,7 @@ mod test {
fn add_child_break() { fn add_child_break() {
let {p, _} = parent_with_3_children(); let {p, _} = parent_with_3_children();
let mut i = 0u; let mut i = 0u;
for each_child(dtree, p) |_c| { for each_child(&dtree, &p) |_c| {
i += 1u; i += 1u;
break; break;
} }