diff options
author | John Wiegley <johnw@newartisans.com> | 2010-05-08 02:00:35 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-05-08 02:00:35 -0400 |
commit | 2d28b34ff35f78ace6e95a652c30c02be7ef5a06 (patch) | |
tree | c974e373ba0703f0fda521680a6f86bf39ef1509 /src/value.cc | |
parent | 4028f0bcb455ce4ea23c355b6a43dc6122447a78 (diff) | |
download | fork-ledger-2d28b34ff35f78ace6e95a652c30c02be7ef5a06.tar.gz fork-ledger-2d28b34ff35f78ace6e95a652c30c02be7ef5a06.tar.bz2 fork-ledger-2d28b34ff35f78ace6e95a652c30c02be7ef5a06.zip |
Allow expr_t& to be passed in a value_t
Diffstat (limited to 'src/value.cc')
-rw-r--r-- | src/value.cc | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/value.cc b/src/value.cc index 54798162..ce9b0e6a 100644 --- a/src/value.cc +++ b/src/value.cc @@ -36,6 +36,7 @@ #include "annotate.h" #include "pool.h" #include "unistring.h" // for justify() +#include "op.h" namespace ledger { @@ -115,6 +116,8 @@ value_t::operator bool() const return false; case SCOPE: return as_scope() != NULL; + case EXPR: + return as_expr(); default: break; } @@ -140,6 +143,12 @@ void value_t::set_type(type_t new_type) } } +void value_t::set_expr(const expr_t& val) +{ + set_type(EXPR); + storage->data = new expr_t(val); +} + bool value_t::to_boolean() const { if (is_boolean()) { @@ -1272,6 +1281,8 @@ bool value_t::is_realzero() const case SCOPE: return as_scope() == NULL; + case EXPR: + return ! as_expr(); default: throw_(value_error, _("Cannot determine if %1 is really zero") << label()); @@ -1301,6 +1312,8 @@ bool value_t::is_zero() const case SCOPE: return as_scope() == NULL; + case EXPR: + return ! as_expr(); default: throw_(value_error, _("Cannot determine if %1 is zero") << label()); @@ -1565,6 +1578,7 @@ value_t value_t::strip_annotations(const keep_details_t& what_to_keep) const case STRING: case MASK: case SCOPE: + case EXPR: return *this; case SEQUENCE: { @@ -1673,7 +1687,15 @@ void value_t::print(std::ostream& out, } case SCOPE: - out << "<SCOPE>"; + out << "<#SCOPE>"; + break; + case EXPR: + out << "<#EXPR "; + if (as_expr()) + as_expr().print(out); + else + out << "null"; + out << ">"; break; default: @@ -1743,6 +1765,12 @@ void value_t::dump(std::ostream& out, const bool relaxed) const case SCOPE: out << as_scope(); break; + case EXPR: + if (as_expr()) + as_expr().dump(out); + else + out << "null"; + break; case SEQUENCE: { out << '('; @@ -1855,6 +1883,7 @@ void to_xml(std::ostream& out, const value_t& value) } case value_t::SCOPE: + case value_t::EXPR: default: assert(false); break; |