aboutsummaryrefslogtreecommitdiff
path: root/build2/context.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-03-14 17:19:01 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-03-14 17:19:01 +0200
commitd1b3ad7b302d037c8154bab9c4810d499c0bf1e4 (patch)
tree8c6ce63cb0a71bc670c3c5d46c2c1a06366956ad /build2/context.cxx
parent8d8d7784d5fe0dc3cd8d7fbd4196c2337d389fd1 (diff)
Change variable::override list order, make doubly-linked
Diffstat (limited to 'build2/context.cxx')
-rw-r--r--build2/context.cxx36
1 files changed, 27 insertions, 9 deletions
diff --git a/build2/context.cxx b/build2/context.cxx
index 7b473e2..633f3ff 100644
--- a/build2/context.cxx
+++ b/build2/context.cxx
@@ -682,27 +682,45 @@ namespace build2
c == '%' ? variable_visibility::project :
variable_visibility::normal);
- const variable& var (vp.insert (n, true)); // Allow overrides.
+ variable& var (const_cast<variable&> (
+ vp.insert (n, true /* overridable */)));
const char* k (tt == token_type::assign ? ".__override" :
tt == token_type::append ? ".__suffix" : ".__prefix");
// We might already have a variable for this kind of override.
//
- const variable* o (&var); // Step behind.
- for (; o->override != nullptr; o = o->override.get ())
+ const variable* o (var.override.get ());
+ for (; o != nullptr; o = o->override.get ())
{
- if (o->override->visibility == v &&
- o->override->name.rfind (k) != string::npos)
+ if (o->visibility == v && o->name.rfind (k) != string::npos)
break;
}
// Add it if not found.
//
- if (o->override == nullptr)
- const_cast<variable*> (o)->override.reset (
- new variable {n + k, nullptr , nullptr, nullptr, v});
+ if (o == nullptr)
+ {
+ unique_ptr<variable> p (
+ new variable {
+ n + k,
+ nullptr /* alias */,
+ nullptr /* type */,
+ nullptr /* override */,
+ v});
+
+ // Back link.
+ //
+ p->alias = p.get ();
+ if (var.override != nullptr)
+ swap (p->alias, const_cast<variable*> (var.override.get ())->alias);
- o = o->override.get ();
+ // Forward link.
+ //
+ p->override = move (var.override);
+ var.override = move (p);
+
+ o = var.override.get ();
+ }
// Currently we expand project overrides in the global scope to keep
// things simple. Pass original variable for diagnostics. Use current