From 29c3e3b8912b784d9e2e4a4bec4c2378c7ffef7a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 8 Apr 2015 11:29:43 +0200 Subject: Get rid of need to store scope in variable value --- build/cxx/module.cxx | 10 +++++----- build/parser.cxx | 8 ++++---- build/variable | 34 ++++++++-------------------------- build/variable.ixx | 7 +++---- 4 files changed, 20 insertions(+), 39 deletions(-) diff --git a/build/cxx/module.cxx b/build/cxx/module.cxx index 04b1ae5..435e54c 100644 --- a/build/cxx/module.cxx +++ b/build/cxx/module.cxx @@ -49,7 +49,7 @@ namespace build if (val) { - if (&val.scope () != global_scope) + if (val.scope != global_scope) break; // A value from config.build. v = val.as (); @@ -110,7 +110,7 @@ namespace build // if (auto val = root["config.cxx.poptions"]) { - if (&val.scope () == global_scope) + if (val.scope == global_scope) root.variables["config.cxx.poptions"] = val; } else @@ -118,7 +118,7 @@ namespace build if (auto val = root["config.cxx.coptions"]) { - if (&val.scope () == global_scope) + if (val.scope == global_scope) root.variables["config.cxx.coptions"] = val; } else @@ -126,7 +126,7 @@ namespace build if (auto val = root["config.cxx.loptions"]) { - if (&val.scope () == global_scope) + if (val.scope == global_scope) root.variables["config.cxx.loptions"] = val; } else @@ -134,7 +134,7 @@ namespace build if (auto val = root["config.cxx.libs"]) { - if (&val.scope () == global_scope) + if (val.scope == global_scope) root.variables["config.cxx.libs"] = val; } else diff --git a/build/parser.cxx b/build/parser.cxx index 2845143..24a1e98 100644 --- a/build/parser.cxx +++ b/build/parser.cxx @@ -700,7 +700,7 @@ namespace build if (val == nullptr) // Initialization. { - val.reset (new list_value (*scope_, move (vns))); + val.reset (new list_value (move (vns))); } else // Assignment. { @@ -717,9 +717,9 @@ namespace build // list_value* lv (&val.as ()); - if (&lv->scope != scope_) // Append to value from parent scope? + if (val.scope != scope_) // Append to value from parent scope? { - list_value_ptr nval (new list_value (*scope_, lv->data)); + list_value_ptr nval (new list_value (lv->data)); lv = nval.get (); // Append to. scope_->variables.emplace (var, move (nval)); } @@ -730,7 +730,7 @@ namespace build } else // Initialization. { - list_value_ptr nval (new list_value (*scope_, move (vns))); + list_value_ptr nval (new list_value (move (vns))); scope_->variables.emplace (var, move (nval)); } } diff --git a/build/variable b/build/variable index aca0bed..fc0ba2b 100644 --- a/build/variable +++ b/build/variable @@ -53,15 +53,9 @@ namespace build struct value { - typedef build::scope scope_type; - - scope_type& scope; // Scope to which this value belongs. - public: - value (scope_type& s): scope (s) {} - virtual value_ptr - clone (scope_type& s) const = 0; + clone () const = 0; virtual bool compare (const value&) const = 0; @@ -75,24 +69,15 @@ namespace build names data; public: - list_value (scope_type& s, names d): value (s), data (std::move (d)) {} - - list_value (scope_type& s, std::string d) - : value (s) - { - data.emplace_back (std::move (d)); - } + list_value (names d): data (std::move (d)) {} + list_value (std::string d) {data.emplace_back (std::move (d));} // Note: stored in name as a directory. // - list_value (scope_type& s, path d) - : value (s) - { - data.emplace_back (std::move (d)); - } + list_value (path d) {data.emplace_back (std::move (d));} virtual value_ptr - clone (scope_type& s) const {return value_ptr (new list_value (s, data));} + clone () const {return value_ptr (new list_value (data));} virtual bool compare (const value& v) const @@ -112,8 +97,7 @@ namespace build explicit operator bool () const {return p != nullptr && *p != nullptr;} explicit operator value_ptr& () const {return *p;} - scope_type& - scope () const {return *s;} + scope_type* scope; // Get interface. See available specializations below. // @@ -139,12 +123,10 @@ namespace build // Implementation details. // - explicit - value_proxy (value_ptr* p, scope_type* s): p (p), s (s) {} + value_proxy (value_ptr* p, scope_type* s): p (p), scope (s) {} - protected: + private: value_ptr* p; - scope_type* s; }; template <> diff --git a/build/variable.ixx b/build/variable.ixx index 85fdd50..ca5a24a 100644 --- a/build/variable.ixx +++ b/build/variable.ixx @@ -7,7 +7,6 @@ namespace build inline const value_proxy& value_proxy:: operator= (value_ptr v) const { - assert (v == nullptr || &v->scope == s); *p = std::move (v); return *this; } @@ -18,7 +17,7 @@ namespace build if (this != &v) { if (v) - *p = v.as ().clone (*s); + *p = v.as ().clone (); else p->reset (); } @@ -33,14 +32,14 @@ namespace build // don't bother trying to optimize for the case where p is not // NULL. // - p->reset (new list_value (*s, std::move (v))); + p->reset (new list_value (std::move (v))); return *this; } inline const value_proxy& value_proxy:: operator= (path v) const { - p->reset (new list_value (*s, std::move (v))); + p->reset (new list_value (std::move (v))); return *this; } } -- cgit v1.1