From d1b3ad7b302d037c8154bab9c4810d499c0bf1e4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 14 Mar 2019 17:19:01 +0200 Subject: Change variable::override list order, make doubly-linked --- build2/context.cxx | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'build2/context.cxx') 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 ( + 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 (o)->override.reset ( - new variable {n + k, nullptr , nullptr, nullptr, v}); + if (o == nullptr) + { + unique_ptr 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 (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 -- cgit v1.1