Skip to content

Commit

Permalink
Add some basic debug info for dumping flows.
Browse files Browse the repository at this point in the history
  • Loading branch information
larsbergstrom committed Nov 11, 2013
1 parent bdc7e98 commit b675618
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/components/main/layout/block.rs
Expand Up @@ -506,5 +506,19 @@ impl FlowContext for BlockFlow {

*first_in_flow = false;
}

fn debug_str(&self) -> ~str {
if self.is_root {
~"BlockFlow(root)"
} else {
let txt = ~"BlockFlow: ";
txt.append(match self.box {
Some(rb) => {
rb.debug_str()
}
None => { ~"" }
})

This comment has been minimized.

Copy link
@kmcallister

kmcallister Nov 11, 2013

Since each arm is a single expression I'd go with

match self.box {
    Some(rb) => rb.debug_str(),
    None => ~""
}

Or use the Option methods, but I don't remember offhand which one is appropriate here, since they keep changing.

This comment has been minimized.

Copy link
@huonw

huonw Nov 11, 2013

self.box.map_default(~"", |rb| rb.debug_str()) (docs) if you can cope with the ~"" allocation always happening.

}
}
}

3 changes: 3 additions & 0 deletions src/components/main/layout/float.rs
Expand Up @@ -315,5 +315,8 @@ impl FlowContext for FloatFlow {
// Margins between a floated box and any other box do not collapse.
*collapsing = Au::new(0);
}
fn debug_str(&self) -> ~str {
~"FloatFlow"
}
}

24 changes: 22 additions & 2 deletions src/components/main/layout/flow.rs
Expand Up @@ -35,7 +35,7 @@ use layout::float_context::{FloatContext, Invalid};
use layout::incremental::RestyleDamage;
use layout::inline::InlineFlow;

use extra::dlist::{DList,MutDListIterator};
use extra::dlist::{DList, DListIterator, MutDListIterator};
use extra::container::Deque;
use geom::point::Point2D;
use geom::rect::Rect;
Expand Down Expand Up @@ -127,6 +127,11 @@ pub fn base<'a>(this: &'a FlowContext) -> &'a FlowData {
}
}

/// Iterates over the children of this immutable flow.
pub fn imm_child_iter<'a>(flow: &'a FlowContext) -> DListIterator<'a,~FlowContext:> {

This comment has been minimized.

Copy link
@kmcallister

kmcallister Nov 11, 2013

Stray colon in ~FlowContext:, unless an empty trait bound is needed here for some reason.

base(flow).children.iter()
}

#[inline(always)]
pub fn mut_base<'a>(this: &'a mut FlowContext) -> &'a mut FlowData {
unsafe {
Expand Down Expand Up @@ -162,6 +167,9 @@ pub trait ImmutableFlowUtils {

/// Dumps the flow tree for debugging.
fn dump(self);

/// Dumps the flow tree for debugging, with a prefix to indicate that we're at the given level.
fn dump_with_level(self, level: uint);
}

pub trait MutableFlowUtils {
Expand Down Expand Up @@ -411,7 +419,19 @@ impl<'self> ImmutableFlowUtils for &'self FlowContext {

/// Dumps the flow tree for debugging.
fn dump(self) {
// TODO(pcwalton): Fill this in.
self.dump_with_level(0)
}

/// Dumps the flow tree for debugging, with a prefix to indicate that we're at the given level.
fn dump_with_level(self, level: uint) {
let mut indent = ~"";
for _ in range(0, level) {
indent.push_str("| ")
}
debug!("{}+ {}", indent, self.debug_str());
for kid in imm_child_iter(self) {
kid.dump_with_level(level + 1)
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/components/main/layout/inline.rs
Expand Up @@ -891,5 +891,9 @@ impl FlowContext for InlineFlow {
*collapsible = Au::new(0);
}
}

fn debug_str(&self) -> ~str {
~"InlineFlow"
}
}

1 comment on commit b675618

@brson
Copy link

@brson brson commented on b675618 Nov 11, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Please sign in to comment.