diff options
author | John Wiegley <johnw@newartisans.com> | 2008-08-02 16:23:58 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-08-02 16:32:16 -0400 |
commit | e52a6a9bd8e2bbf3a497696eed735eb00a8b9dde (patch) | |
tree | 2eb460e8512c91af08ff5884b680d1a49fe0c743 /expr.cc | |
parent | 9a9e06554eb9f57be8c839fb0af49a0473614172 (diff) | |
download | ledger-e52a6a9bd8e2bbf3a497696eed735eb00a8b9dde.tar.gz ledger-e52a6a9bd8e2bbf3a497696eed735eb00a8b9dde.tar.bz2 ledger-e52a6a9bd8e2bbf3a497696eed735eb00a8b9dde.zip |
More infrastructure work toward getting journal objects to provide their own
information in an abstract manner.
Diffstat (limited to 'expr.cc')
-rw-r--r-- | expr.cc | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -44,7 +44,7 @@ expr_t::expr_t() : compiled(false) } expr_t::expr_t(const expr_t& other) - : ptr(other.ptr), str(other.str), compiled(false) + : ptr(other.ptr), str(other.str), compiled(other.compiled) { TRACE_CTOR(expr_t, "copy"); } @@ -109,7 +109,7 @@ void expr_t::parse(std::istream& in, const unsigned int flags) void expr_t::compile(scope_t& scope) { - if (ptr.get()) { + if (ptr.get() && ! compiled) { ptr = ptr->compile(scope); compiled = true; } @@ -127,9 +127,16 @@ value_t expr_t::calc(scope_t& scope) bool expr_t::is_constant() const { + assert(compiled); return ptr.get() && ptr->is_value(); } +bool expr_t::is_function() const +{ + assert(compiled); + return ptr.get() && ptr->is_function(); +} + value_t& expr_t::constant_value() { assert(is_constant()); @@ -142,6 +149,12 @@ const value_t& expr_t::constant_value() const return ptr->as_value(); } +function_t& expr_t::get_function() +{ + assert(is_function()); + return ptr->as_function_lval(); +} + value_t expr_t::eval(const string& _expr, scope_t& scope) { return expr_t(_expr).calc(scope); |