Codebase: Macro to iterate over nodes of known type
There is a pattern in the codebase when a list of nodes is iterated and the type of each of the nodes is equal and known. This is for example to iterate over lists of pins, etc.
This introduces a macro ASTNODE_ITERATE that has three parameters:
- type: Is the type of the nodes (Ast<type> is the matching class name)
- it: Name of the iterator variable
- init: Initialization statement for iterator
All occurrences of this pattern have been accordingly replaced:
for (Ast<type> *<it> = <init>; <it>; <it>=<it>->nextp()->cast<type>())
This improves readability and some time in the future this may be a good marker to replace data containers or similar.
#4 Updated by Wilson Snyder over 1 year ago
- Status changed from New to WillNotFix
For the time being I don't think we want to change this, but I appreciate your efforts to clean up and in general expect to accept other cleanups.
There's two main concerns. First, it makes the code harder to read for people not familiar with the code - if there was thousands it might be worth it but not for only 58. Second, in a few years once C++11 compilers are common (not yet), we can use the C++11 for loop syntax ("for (AstFoo* itp : nodep->itemsp()") for this and a lot of other things.
Also available in: Atom