#ifndef EXPRESSION_REFERENCE_H #define EXPRESSION_REFERENCE_H #include "tree_reference.h" #include "expression_node.h" #include template class ExpressionReference : public TreeReference { public: using TreeReference::TreeReference; /* Allow every ExpressionReference to be transformed into an * ExpressionReference, i.e. ExpressionRef */ operator ExpressionReference() const { return ExpressionReference(this->node()); } static TreeNode * FailedAllocationStaticNode(); ExpressionReference childAtIndex(int i) { return ExpressionReference(TreeReference::treeChildAtIndex(i).node()); } void replaceChildAtIndex(int oldChildIndex, ExpressionReference newChild) { TreeReference::replaceChildAtIndex(oldChildIndex, newChild); } float approximate() const { return this->typedNode()->approximate(); } ExpressionReference deepReduce() { ExpressionReference result = ExpressionReference(this->clone().node()); result.typedNode()->deepReduce(); return result; } void shallowReduce() { return this->typedNode()->shallowReduce(); } void sortChildren() { for (int i = this->numberOfChildren()-1; i > 0; i--) { bool isSorted = true; for (int j = 0; j < this->numberOfChildren()-1; j++) { if (this->childAtIndex(j).typedNode()->type() > this->childAtIndex(j+1).typedNode()->type()) { this->swapChildren(j, j+1); isSorted = false; } } if (isSorted) { return; } } } }; typedef ExpressionReference ExpressionRef; #endif