I want to generate expression trees that have "reverse" references from child to parent. Is there a way to customize the Proto generator or domain so that the expression wrapper class (using proto::extends<>
) contains a reference to the parent expression?
The goal behind this is to create expression trees that cache evaluated results, so that they can be re-evaluated efficiently. My strategy is to update terminal values, and then walk up the tree marking parent nodes as "dirty" so that they will be re-evaluated when the root expression is evaluated.
The technique you describe can't work. Expressions are built bottom-up. For the expression a + (b * c)
, the parent node (+
) doesn't exist at the time the child node (b * c
) is constructed. The child can't store a pointer to an object that doesn't exist yet.
You would have to post-process expressions to set the parent pointers using a transform or context.