diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-12 22:18:16 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-13 01:03:48 -0400 |
commit | 1bc5b894dfd9412a60c4db16e9a4e49ddddad5fd (patch) | |
tree | 482c6d0143b56c61b43fadb141384fb89184279e /src/scope.h | |
parent | 536e3e73228b6168437704ede89499406b87391d (diff) | |
download | fork-ledger-1bc5b894dfd9412a60c4db16e9a4e49ddddad5fd.tar.gz fork-ledger-1bc5b894dfd9412a60c4db16e9a4e49ddddad5fd.tar.bz2 fork-ledger-1bc5b894dfd9412a60c4db16e9a4e49ddddad5fd.zip |
Expression evaluations now have a "type context"
Thus, an expression can know if the context in which it's being
evaluated requires a string, and if so, determine it's output
accordingly. For example:
account ; returns the full name of the posting's account
account.total ; here the context is SCOPE, so account is an obj
Diffstat (limited to 'src/scope.h')
-rw-r--r-- | src/scope.h | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/scope.h b/src/scope.h index e3dd3e3f..1b10d7a6 100644 --- a/src/scope.h +++ b/src/scope.h @@ -114,6 +114,10 @@ public: virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind, const string& name) = 0; + virtual value_t::type_t type_context() const { + return value_t::VOID; + } + #if defined(HAVE_BOOST_SERIALIZATION) private: /** Serialization. */ @@ -205,13 +209,34 @@ private: #endif // HAVE_BOOST_SERIALIZATION }; -class call_scope_t : public child_scope_t +class context_scope_t : public child_scope_t +{ + value_t::type_t value_type_context; + +public: + explicit context_scope_t(scope_t& _parent, + value_t::type_t _type_context = value_t::VOID) + : child_scope_t(_parent), value_type_context(_type_context) { + TRACE_CTOR(context_scope_t, "scope_t&, value_t::type_t"); + } + virtual ~context_scope_t() { + TRACE_DTOR(context_scope_t); + } + + virtual value_t::type_t type_context() const { + return value_type_context; + } +}; + +class call_scope_t : public context_scope_t { value_t args; public: - explicit call_scope_t(scope_t& _parent) : child_scope_t(_parent) { - TRACE_CTOR(call_scope_t, "scope_t&"); + explicit call_scope_t(scope_t& _parent, + value_t::type_t _type_context = value_t::VOID) + : context_scope_t(_parent, _type_context) { + TRACE_CTOR(call_scope_t, "scope_t&, value_t::type_t"); } virtual ~call_scope_t() { TRACE_DTOR(call_scope_t); |