3

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.

Wandering Fool
  • 2,170
  • 3
  • 18
  • 48
Aaron
  • 594
  • 2
  • 12

1 Answers1

3

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.

Eric Niebler
  • 5,927
  • 2
  • 29
  • 43
  • Thanks! Seems obvious now, but was less so while I was lost in the meta-programming jungle :-) – Aaron Aug 13 '15 at 22:23