#include #include "value.h" #include "evaluator.h" value::value(enum value_type type) : m_type(type) { } enum value_type value::get_type() { return m_type; } tree_value::tree_value( evaluator * evaluator, value * lchild, value * rchild) : value(VALUE_TYPE_TREE), m_evaluator(evaluator), m_lchild(lchild), m_rchild(rchild) { } value * tree_value::simplify() { if (!m_evaluator) { return this->clone(); } return m_evaluator->evaluate( m_lchild ? m_lchild->simplify() : NULL, m_rchild ? m_rchild->simplify() : NULL); } value * tree_value::clone() { return new tree_value(m_evaluator, (m_lchild ? m_lchild->clone() : NULL), (m_rchild ? m_rchild->clone() : NULL)); } std::string tree_value::to_string() { return "(" + (m_lchild ? m_lchild->to_string() : "?") + ") " + (m_evaluator ? m_evaluator->to_string() : "?") + " (" + (m_rchild ? m_rchild->to_string() : "?") + ")"; } float_value::float_value() : value(VALUE_TYPE_FLOAT), m_has_value(false) { } float_value::float_value(float init_value) : /* XXX: Can we call the other constructor here? */ value(VALUE_TYPE_FLOAT), m_has_value(true), m_value(init_value) { } value * float_value::simplify() { return this; } value * float_value::clone() { return new float_value(*this); } std::string float_value::to_string() { std::ostringstream s; if (!m_has_value) { s << "?"; } else { s << m_value; } return s.str(); } void float_value::set_value(float value) { m_has_value = true; m_value = value; } const_value::const_value( register_address address, float_value * value_ptr) : value(VALUE_TYPE_CONST), m_reg_address(address), m_value(value_ptr) { } value * const_value::simplify() { if (m_value->m_has_value) { return m_value->clone(); } else { return this->clone(); } } value * const_value::clone() { return new const_value(m_reg_address, m_value); } std::string const_value::to_string() { return m_reg_address.to_string(); }