diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-05 04:24:15 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-05 04:24:15 -0500 |
commit | 15555d497f56e4b4d39e9a14f74b2c82cce52b90 (patch) | |
tree | 1e6c661379f02fdc52ef107fd500438ab69f3e60 /src/scope.h | |
parent | 94b2518c4156e5a6b2be45bdbeeacf1ced0cd17f (diff) | |
parent | 060fc0e00bacb96d1d16163779d98c45c3999014 (diff) | |
download | fork-ledger-15555d497f56e4b4d39e9a14f74b2c82cce52b90.tar.gz fork-ledger-15555d497f56e4b4d39e9a14f74b2c82cce52b90.tar.bz2 fork-ledger-15555d497f56e4b4d39e9a14f74b2c82cce52b90.zip |
Merge branch 'next'
Diffstat (limited to 'src/scope.h')
-rw-r--r-- | src/scope.h | 108 |
1 files changed, 88 insertions, 20 deletions
diff --git a/src/scope.h b/src/scope.h index 7f2680d6..c2c9df20 100644 --- a/src/scope.h +++ b/src/scope.h @@ -55,9 +55,66 @@ 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: + static scope_t * default_scope; + explicit scope_t() { TRACE_CTOR(scope_t, ""); } @@ -65,8 +122,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: @@ -75,7 +134,7 @@ private: friend class boost::serialization::access; template<class Archive> - void serialize(Archive &, const unsigned int /* version */) {} + void serialize(Archive&, const unsigned int /* version */) {} #endif // HAVE_BOOST_SERIALIZATION }; @@ -100,14 +159,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; } @@ -118,7 +179,7 @@ private: friend class boost::serialization::access; template<class Archive> - void serialize(Archive & ar, const unsigned int /* version */) { + void serialize(Archive& ar, const unsigned int /* version */) { ar & boost::serialization::base_object<scope_t>(*this); ar & parent; } @@ -132,7 +193,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 +208,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: @@ -158,7 +221,7 @@ private: friend class boost::serialization::access; template<class Archive> - void serialize(Archive & ar, const unsigned int /* version */) { + void serialize(Archive& ar, const unsigned int /* version */) { ar & boost::serialization::base_object<child_scope_t>(*this); ar & symbols; } @@ -196,6 +259,9 @@ public: return args[index]; } + void push_front(const value_t& val) { + args.push_front(val); + } void push_back(const value_t& val) { args.push_back(val); } @@ -228,7 +294,7 @@ private: friend class boost::serialization::access; template<class Archive> - void serialize(Archive & ar, const unsigned int /* version */) { + void serialize(Archive& ar, const unsigned int /* version */) { ar & boost::serialization::base_object<child_scope_t>(*this); ar & args; } @@ -256,15 +322,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) @@ -274,7 +342,7 @@ private: friend class boost::serialization::access; template<class Archive> - void serialize(Archive & ar, const unsigned int /* version */) { + void serialize(Archive& ar, const unsigned int /* version */) { ar & boost::serialization::base_object<child_scope_t>(*this); ar & grandchild; } |