diff options
author | John Wiegley <johnw@newartisans.com> | 2008-08-02 06:42:36 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-08-02 06:42:36 -0400 |
commit | 9a9e06554eb9f57be8c839fb0af49a0473614172 (patch) | |
tree | c31019afc5a482ff3daeb8cf672af22a0910d5a3 /op.cc | |
parent | 5bf3f536b37e77b5dd663fffbd32e71b403d2c7a (diff) | |
download | fork-ledger-9a9e06554eb9f57be8c839fb0af49a0473614172.tar.gz fork-ledger-9a9e06554eb9f57be8c839fb0af49a0473614172.tar.bz2 fork-ledger-9a9e06554eb9f57be8c839fb0af49a0473614172.zip |
Formatting now relies exclusively on value expressions.
What this means is that the utility code, basic math, value expressions,
string formatting and option handling are now entirely decoupled from the rest
of the code. This decoupling not only greatly simplifies the more basic parts
of Ledger, but makes it much easier to test and verify its completeness.
For example, when the formatting code %X is seen by the format parser, it
turns into a call to the expression function fmt_X, which must be defined when
the format string is first compiled against an object. If that object is a
transaction, the transaction's scope will be the first to have a chance at
providing a definition. If an account is being reported, it will. If neither
does, the next scope in sequence -- soon to be the current report -- will, and
then the session object that "owns" the current Ledger session.
In 2.6, the formatting code new everything about transaction and accounts, and
relied on flags to communicate special details between them. Now the
transaction will offer the details for its own reporting, while the formatter
worries only about strings and how to output them.
Diffstat (limited to 'op.cc')
-rw-r--r-- | op.cc | 33 |
1 files changed, 25 insertions, 8 deletions
@@ -640,8 +640,8 @@ expr_t::ptr_op_t expr_t::op_t::compile(scope_t& scope) #if 1 return def; #else - // Aren't definitions compiled when they go in? Would - // recompiling here really add any benefit? + // jww (2008-08-02): Aren't definitions compiled when they go in? + // Would recompiling here really add any benefit? return def->compile(scope); #endif } @@ -655,7 +655,7 @@ expr_t::ptr_op_t expr_t::op_t::compile(scope_t& scope) return this; ptr_op_t lhs(left()->compile(scope)); - ptr_op_t rhs(right() ? right()->compile(scope) : ptr_op_t()); + ptr_op_t rhs(kind > UNARY_OPERATORS ? right()->compile(scope) : ptr_op_t()); if (lhs == left() && (! rhs || rhs == right())) return this; @@ -675,10 +675,12 @@ value_t expr_t::op_t::calc(scope_t& scope) return as_value(); case IDENT: +#if 0 if (ptr_op_t reference = compile(scope)) { if (reference != this) return reference->calc(scope); } +#endif throw_(calc_error, "Unknown identifier '" << as_ident() << "'"); case FUNCTION: { @@ -698,6 +700,9 @@ value_t expr_t::op_t::calc(scope_t& scope) ptr_op_t func = left(); string name; +#if 0 + // The expression must be compiled beforehand in order to resolve this + // into a function. if (func->kind == IDENT) { name = func->as_ident(); ptr_op_t def = func->compile(scope); @@ -706,6 +711,7 @@ value_t expr_t::op_t::calc(scope_t& scope) "Calling unknown function '" << name << "'"); func = def; } +#endif if (func->kind != FUNCTION) throw_(calc_error, "Calling non-function"); @@ -713,8 +719,12 @@ value_t expr_t::op_t::calc(scope_t& scope) return func->as_function()(call_args); } + case O_MATCH: + assert(left()->is_mask()); + return left()->as_mask().match(right()->calc(scope).to_string()); + case INDEX: { - call_scope_t args(scope); + const call_scope_t& args(downcast<const call_scope_t>(scope)); if (as_index() < args.size()) return args[as_index()]; @@ -755,6 +765,7 @@ value_t expr_t::op_t::calc(scope_t& scope) case O_AND: return ! left()->calc(scope) ? value_t(false) : right()->calc(scope); + case O_OR: if (value_t temp = left()->calc(scope)) return temp; @@ -957,6 +968,15 @@ bool expr_t::op_t::print(std::ostream& out, print_context_t& context) const out << ")"; break; + case O_MATCH: + out << '/'; + if (left() && left()->print(out, context)) + found = true; + out << "/ =~ "; + if (right() && right()->print(out, context)) + found = true; + break; + case LAST: default: assert(false); @@ -1002,6 +1022,7 @@ void expr_t::op_t::dump(std::ostream& out, const int depth) const break; case O_CALL: out << "O_CALL"; break; + case O_MATCH: out << "O_MATCH"; break; case O_NOT: out << "O_NOT"; break; case O_NEG: out << "O_NEG"; break; @@ -1042,10 +1063,6 @@ void expr_t::op_t::dump(std::ostream& out, const int depth) const } } -void expr_t::op_t::read(std::ostream& in) -{ -} - void expr_t::op_t::read(const char *& data) { #if 0 |