diff options
author | John Wiegley <johnw@newartisans.com> | 2010-05-30 02:26:17 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-05-30 02:38:32 -0600 |
commit | 4d372a8e1ecd4203fe8d9de24e945ef793e4f039 (patch) | |
tree | 499c03038bf5ee077a8e565b90616bf9f1f01797 /src/scope.h | |
parent | 8f17d01f5e48ae5097f4cb38d481b00577329b8c (diff) | |
download | fork-ledger-4d372a8e1ecd4203fe8d9de24e945ef793e4f039.tar.gz fork-ledger-4d372a8e1ecd4203fe8d9de24e945ef793e4f039.tar.bz2 fork-ledger-4d372a8e1ecd4203fe8d9de24e945ef793e4f039.zip |
Added value_scope_t, for wrapping a value in a scope
The value expression "value" may be used to extract the wrapped value.
This is currently only used by the upcoming --group-title-format option.
Diffstat (limited to 'src/scope.h')
-rw-r--r-- | src/scope.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/scope.h b/src/scope.h index 30ba6823..1e6f24a1 100644 --- a/src/scope.h +++ b/src/scope.h @@ -354,6 +354,30 @@ inline T& find_scope(child_scope_t& scope, bool skip_this = true) return reinterpret_cast<T&>(scope); // never executed } +class value_scope_t : public scope_t +{ + value_t value; + + value_t get_value(call_scope_t&) { + return value; + } + +public: + value_scope_t(const value_t& _value) : value(_value) {} + + virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind, + const string& name) + { + if (kind != symbol_t::FUNCTION) + return NULL; + + if (name == "value") + return MAKE_FUNCTOR(value_scope_t::get_value); + + return NULL; + } +}; + } // namespace ledger #endif // _SCOPE_H |