diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-24 20:37:08 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-24 20:37:12 -0400 |
commit | 011bf030a27f75c8b127b9b044a6580fc124a986 (patch) | |
tree | c90db8fe268a97a7eb9a05514a31f931b84ffd4b /src/op.cc | |
parent | 35da9ad4665416fe8b016f3fd7cad4975fc3e090 (diff) | |
download | fork-ledger-011bf030a27f75c8b127b9b044a6580fc124a986.tar.gz fork-ledger-011bf030a27f75c8b127b9b044a6580fc124a986.tar.bz2 fork-ledger-011bf030a27f75c8b127b9b044a6580fc124a986.zip |
Generalized the semantics of FOO.BAR in valexprs
Previously, FOO was evaluated to return a scope, and BAR was an
identifier looked up in that scope. However, this prevented scope-local
functions from being called (since that is a CALL, not a plain IDENT).
Now the meaning of the "." operator is that it evaluates the left
operand in a scope type context, pushes that scope as the current object
context, and then evaluates BAR in that context.
Thus the bare word "amount" in an account context calls the same
function that "account.amount" would if evaluated in a posting context.
Diffstat (limited to 'src/op.cc')
-rw-r--r-- | src/op.cc | 24 |
1 files changed, 7 insertions, 17 deletions
@@ -226,26 +226,16 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus, const int depth) case O_LOOKUP: { context_scope_t context_scope(scope, value_t::SCOPE); + bool scope_error = true; if (value_t obj = left()->calc(context_scope, locus, depth + 1)) { - if (obj.is_scope()) { - if (obj.as_scope() == NULL) { - throw_(calc_error, _("Left operand of . operator is NULL")); - } else { - scope_t& objscope(*obj.as_scope()); - if (ptr_op_t member = - objscope.lookup(symbol_t::FUNCTION, right()->as_ident())) { - result = member->calc(objscope, NULL, depth + 1); - break; - } - } + if (obj.is_scope() && obj.as_scope() != NULL) { + bind_scope_t bound_scope(scope, *obj.as_scope()); + result = right()->calc(bound_scope, locus, depth + 1); + scope_error = false; } } - if (right()->kind != IDENT) - throw_(calc_error, - _("Right operand of . operator must be an identifier")); - else - throw_(calc_error, - _("Failed to lookup member '%1'") << right()->as_ident()); + if (scope_error) + throw_(calc_error, _("Left operand does not evaluate to an object")); break; } |