davidchisnall / dtc

FreeBSD Device Tree Compiler
18 stars 15 forks source link

Extend node::visit to include parent node and allow control of recursion #42

Closed kevans91 closed 6 years ago

kevans91 commented 6 years ago

The callable's return value may indicate whether the recursion should happen or not. parent as passed to visit will be passed on to the callable, and the recursive call will pass the current node as the parent to its children.

I've submitted this separately from /delete-if-unreferenced/ since it's worth of review on its own.

davidchisnall commented 6 years ago

I think I'd prefer that this return a tri-state enumeration:

kevans91 commented 6 years ago

I've about got that hammered out- would it make sense that a child node that's been visited may halt recursion through the rest of its siblings without halting the visit entirely? i.e. we'd bubble up the DONT_RECURSE and break out of the loop in visit(), but allow iteration over the grandfather node's siblings.

davidchisnall commented 6 years ago

Yup. Look at libclang's visitor implementation for a good example of a well-designed tree visitor interface.

kevans91 commented 6 years ago

I've pushed a second cut of it- I wasn't too positive of the placement of the enum, but it seemed like within the node class was a good candidate. I'd considered just dropping it into dtc::fdt directly, but then flipped a coin and put it into node.

I also wasn't sure on enum naming or name of the children, but I did like libclang's terminology for the three behaviors.

davidchisnall commented 6 years ago

Merged, but at some point please will you add Doxygen comments for the enum values?