diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-03-31 09:01:50 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-03-31 09:01:50 +0200 |
commit | 6417a4e6af2b7732ec0da6af24f1a56f7cdada3f (patch) | |
tree | 58ffae7ef0cdac55acd6d498dfc66ce0967f4e9a /build2/variable.cxx | |
parent | 31bd69c56bc29ec1c154a7c0623b6f0ccce78af1 (diff) |
Set part of variable override implementation
Diffstat (limited to 'build2/variable.cxx')
-rw-r--r-- | build2/variable.cxx | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/build2/variable.cxx b/build2/variable.cxx index 7b7f16d..4597e9e 100644 --- a/build2/variable.cxx +++ b/build2/variable.cxx @@ -552,6 +552,46 @@ namespace build2 // variable_pool // + const variable& variable_pool:: + insert (string n, + const build2::value_type* t, + variable_visibility v, + bool o) + { + auto p (variable_pool_base::insert (variable {move (n), t, nullptr, v})); + const variable& r (*p.first); + + if (!p.second) + { + // Update type? + // + if (t != nullptr && r.type != t) + { + assert (r.type == nullptr); + const_cast<variable&> (r).type = t; // Not changing the key. + } + + // Change visibility? While this might at first seem like a bad idea, + // it can happen that the variable lookup happens before any values + // were set, in which case the variable will be entered with the + // default visibility. + // + if (r.visibility != v) + { + assert (r.visibility == variable_visibility::normal); // Default. + const_cast<variable&> (r).visibility = v; // Not changing the key. + } + + // Check overridability (all overrides, if any, should already have + // been enetered (see context.cxx:reset()). + // + if (r.override != nullptr && !o) + fail << "variable " << r.name << " cannot be overridden"; + } + + return r; + } + variable_pool var_pool; // variable_map |