diff options
Diffstat (limited to 'src/scope.h')
-rw-r--r-- | src/scope.h | 93 |
1 files changed, 78 insertions, 15 deletions
diff --git a/src/scope.h b/src/scope.h index 36eb54f1..7cf89c3e 100644 --- a/src/scope.h +++ b/src/scope.h @@ -55,6 +55,61 @@ namespace ledger { * * Long. */ +struct symbol_t +{ + enum kind_t { + UNKNOWN, + FUNCTION, + OPTION, + PRECOMMAND, + COMMAND, + DIRECTIVE + }; + + kind_t kind; + string name; + expr_t::ptr_op_t definition; + + symbol_t() : kind(UNKNOWN), name(""), definition(NULL) { + TRACE_CTOR(symbol_t, ""); + } + symbol_t(kind_t _kind, string _name, expr_t::ptr_op_t _definition = NULL) + : kind(_kind), name(_name), definition(_definition) { + TRACE_CTOR(symbol_t, "symbol_t::kind_t, string"); + } + symbol_t(const symbol_t& sym) + : kind(sym.kind), name(sym.name), + definition(sym.definition) { + TRACE_CTOR(symbol_t, "copy"); + } + ~symbol_t() throw() { + TRACE_DTOR(symbol_t); + } + + bool operator<(const symbol_t& sym) const { + return kind < sym.kind || name < sym.name; + } + +#if defined(HAVE_BOOST_SERIALIZATION) +private: + /** Serialization. */ + + friend class boost::serialization::access; + + template<class Archive> + void serialize(Archive& ar, const unsigned int /* version */) { + ar & kind; + ar & name; + ar & definition; + } +#endif // HAVE_BOOST_SERIALIZATION +}; + +/** + * @brief Brief + * + * Long. + */ class scope_t { public: @@ -65,8 +120,10 @@ public: TRACE_DTOR(scope_t); } - virtual void define(const string&, expr_t::ptr_op_t) {} - virtual expr_t::ptr_op_t lookup(const string& name) = 0; + virtual void define(const symbol_t::kind_t, const string&, + expr_t::ptr_op_t) {} + virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind, + const string& name) = 0; #if defined(HAVE_BOOST_SERIALIZATION) private: @@ -100,14 +157,16 @@ public: TRACE_DTOR(child_scope_t); } - virtual void define(const string& name, expr_t::ptr_op_t def) { + virtual void define(const symbol_t::kind_t kind, + const string& name, expr_t::ptr_op_t def) { if (parent) - parent->define(name, def); + parent->define(kind, name, def); } - virtual expr_t::ptr_op_t lookup(const string& name) { + virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind, + const string& name) { if (parent) - return parent->lookup(name); + return parent->lookup(kind, name); return NULL; } @@ -132,7 +191,7 @@ private: */ class symbol_scope_t : public child_scope_t { - typedef std::map<const string, expr_t::ptr_op_t> symbol_map; + typedef std::map<symbol_t, expr_t::ptr_op_t> symbol_map; symbol_map symbols; @@ -147,9 +206,11 @@ public: TRACE_DTOR(symbol_scope_t); } - virtual void define(const string& name, expr_t::ptr_op_t def); + virtual void define(const symbol_t::kind_t kind, const string& name, + expr_t::ptr_op_t def); - virtual expr_t::ptr_op_t lookup(const string& name); + virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind, + const string& name); #if defined(HAVE_BOOST_SERIALIZATION) private: @@ -259,15 +320,17 @@ public: TRACE_DTOR(bind_scope_t); } - virtual void define(const string& name, expr_t::ptr_op_t def) { - parent->define(name, def); - grandchild.define(name, def); + virtual void define(const symbol_t::kind_t kind, const string& name, + expr_t::ptr_op_t def) { + parent->define(kind, name, def); + grandchild.define(kind, name, def); } - virtual expr_t::ptr_op_t lookup(const string& name) { - if (expr_t::ptr_op_t def = grandchild.lookup(name)) + virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind, + const string& name) { + if (expr_t::ptr_op_t def = grandchild.lookup(kind, name)) return def; - return child_scope_t::lookup(name); + return child_scope_t::lookup(kind, name); } #if defined(HAVE_BOOST_SERIALIZATION) |