hpcc-systems/HPCC-Platform — pull request #2320 by rengolin (2012-05-18 14:55:42+00:00)
Title: Add ExpressionDumper basic logic

This is the first draft of the tree dumper to help debug and trace compiler expressions. It's implemented as a transformer and it walks down the tree with max depth defined on any IHqlExpression.

Some examples of the dump:

00879AE0 : op(:=)
00896C60 : op(.)
008968D0 : op(SELF)
00895DE0 : op(RECORD)
00896200 : op(), name
00879A30 : op( | )
00879980 : op( | )
00896E00 : op(), Value = Charlie
00879840 : op()
00897120 : op(), Value = Bravo

008968D0 : op(SELF)
00895DE0 : op(RECORD)
00896170 : op(), id
00896200 : op(), name

00898EF0 : op(), Value = 10

It's by no means complete, but it's a start to add more complex dump capabilities.

For instance, I've added this to ```foldConstantOperator()``` and to ```CTreeOptimizer::analyseExpr()``` to dump the expressions coming to the optimiser. I also tested in GDB, while stepping through code, you can easily inspect the expression by:

(gdb) p dump_expression(expr, 4)

and you'll see a tree like the ones above.

In my TODO list:

* Make sure all transform methods are properly voided
* Add flags and tags to known nodes (ALL, DISTRIBUTED, LOCAL, etc)
* Add a list of ignored nodes (or dumped nodes, whichever is shorter)

This class, or the dump function are not added anywhere, so there's no impact on current execution. This first use is probably in GDB, but it could be added to specific places around optimisations, if thought relevant.

Enjoy!