diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-07-29 12:20:53 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-07-29 12:20:53 +0200 |
commit | 729b56300c441a0d63c7d2013eb5a881211d352b (patch) | |
tree | d363c5f282b910e1f014161e24c6dfc6a5fcba40 /build/target.cxx | |
parent | 1cf1603cae3064aff734f52d23c06098e81a8111 (diff) |
Initial support for target type/pattern-specific variables
Diffstat (limited to 'build/target.cxx')
-rw-r--r-- | build/target.cxx | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/build/target.cxx b/build/target.cxx index df7e2aa..cdcc6b0 100644 --- a/build/target.cxx +++ b/build/target.cxx @@ -85,7 +85,50 @@ namespace build if (group != nullptr) return (*group)[var]; - return base_scope ()[var]; + // Cannot simply delegate to scope's operator[] since we also + // need to check target type/pattern-specific variables. + // + const target_type& btt (type ()); + + for (const scope* s (&base_scope ()); s != nullptr; s = s->parent_scope ()) + { + if (!s->target_vars.empty ()) + { + // Search across target type hierarchy. + // + for (auto tt (&btt); tt != nullptr; tt = tt->base) + { + auto i (s->target_vars.find (*tt)); + + if (i == s->target_vars.end ()) + continue; + + //@@ TODO: match pattern. For now, we only handle '*'. + + auto j (i->second.find ("*")); + + if (j == i->second.end ()) + continue; + + auto k (j->second.find (var)); + + if (k != j->second.end ()) + { + // Note that we use the scope's vars, not from target_vars. + // We use it to identify whether the variable belongs to a + // specific scope/target. + // + return value_proxy (&const_cast<value_ptr&> (k->second), &s->vars); + } + } + } + + auto i (s->vars.find (var)); + if (i != s->vars.end ()) + return value_proxy (&const_cast<value_ptr&> (i->second), &s->vars); + } + + return value_proxy (nullptr, nullptr); } value_proxy target:: |