Throughout the compiler bits of Mesa, we used a list-walking pattern that looked like:
foreach_list(node, list) { actual_type *thing = (actual_type *)node; ... } Instead, just make the macros take the types of the iterator and perform the cast themselves: foreach_in_list(fs_inst, inst, &instructions) { use inst; ... } This simplifies the code and removes a bunch of code: 76 files changed, 441 insertions(+), 817 deletions(-) I add the new foreach_in_* macros and then transition over parts of Mesa. I took this as an opportunity to add "in" to the macro names, since foreach-in-list better describes the operation than foreach-list. There is some inconsistency now, since I added a foreach_list_typed_safe (to be consistent with the existing foreach_list_typed, which I didn't remove). We could rename these easily if we want to. Part of the reason for this series is that I'd like to embed exec_node in some places (i965's backend_instruction) rather than inheriting it, so that those data structures are usable from C. I think this series gets us a little closer to that goal. Kristian suggested making the macros take an iterator variable name (declared before the macro) and then using typeof to do the casts. I don't know how that gets us closer to the previously stated goal or towards type-safe lists, so I didn't do that. (It would also add back a bunch of the deleted lines of code, declaring variables at a scope larger than just the list-walk loop) This code is available in my foreach branch: git://people.freedesktop.org/~mattst88/mesa foreach I haven't tested the IR-to-Mesa or GLSL-to-TGSI bits, but I have compile tested them. _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev