[LLVMdev] Patch for llvm::DepthFirstIterator.h and llvm::PostOrderIterator.h

Olaf Krzikalla Olaf.Krzikalla at tu-dresden.de
Fri Jun 26 05:32:44 PDT 2009


Hi @clang and @llvm,

attached you'll find a patch dealing with some iterator issues I already 
mentioned in both lists. Since there was no reaction I cross-post again 
- now IMHO production-ready code.
The patch is considered to get checked-in out of the box. It should not 
affect the behavior of existing and working code. I really need it for 
clang AST processing.

Changes:
1. Both iterators now can deal with sub-nodes==0 - they just skip them 
silently. For AST processing this is badly needed as you sometimes have 
0-nodes in the AST (e.g. in 'for(;;) {}'). Until now both iterators 
crash if they traverse a sub-node==0.
2. In llvm::PostOrderIterator.h I fixed a compile bug which occured if 
used with external storage (which apparently nobody does until now).
3. I changed the behavior of llvm::DepthFirstIterator.h regarding the 
retrieving of the first child. This is now retrieved in exactly that 
moment it's needed. Until now it was retrieved too early, thus you 
actually couldn't change the childs of a just processed node. I can't 
think of an insane working example, which would break due to this change.
4. I added a public skipChilds member function to df_iterator which acts 
similiar to operator++. However it skips all childs of the currently 
processed node and returns *this. You can use it like in
for (i = df_begin(), e = df_end(); i!=e;)
{
  foo() ? i.skipChilds() : ++i;
}


Best
Olaf Krzikalla
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: llvm-iterator.patch
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090626/55728f28/attachment.ksh>


More information about the llvm-dev mailing list