From 14b34a239fa23e1a28519ab87f450c0a440d4f85 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 18 Mar 2020 10:52:48 +0200 Subject: Cleanup variable type/visibility/overridability logic --- libbuild2/variable.cxx | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'libbuild2/variable.cxx') diff --git a/libbuild2/variable.cxx b/libbuild2/variable.cxx index f1c5515..48fcf40 100644 --- a/libbuild2/variable.cxx +++ b/libbuild2/variable.cxx @@ -1143,7 +1143,7 @@ namespace build2 // Check overridability (all overrides, if any, should already have // been entered; see context ctor for details). // - if (var.overrides != nullptr && (o == nullptr || !*o)) + if (o != nullptr && var.overrides != nullptr && !*o) fail << "variable " << var.name << " cannot be overridden"; bool ut (t != nullptr && var.type != t); @@ -1285,25 +1285,23 @@ namespace build2 var.aliases = &var; else // Note: overridden variable will always exist. { - if (pt != nullptr || pv != nullptr || po != nullptr) + // This is tricky: if the pattern does not require a match, then we + // should re-merge it with values that came from the variable. + // + bool vo; + if (pa != nullptr && !pa->match) { - // This is tricky: if the pattern does not require a match, then we - // should re-merge it with values that came from the variable. - // - bool vo; - if (pa != nullptr && !pa->match) - { - pt = t != nullptr ? t : var.type; - pv = v != nullptr ? v : &var.visibility; - po = o != nullptr ? o : &(vo = (var.overrides != nullptr)); - - merge_pattern (*pa, pt, pv, po); - } + pt = t != nullptr ? t : var.type; + pv = v != nullptr ? v : &var.visibility; + po = o != nullptr ? o : &(vo = true); - update (var, pt, pv, po); // Not changing the key. + merge_pattern (*pa, pt, pv, po); } - else if (var.overrides != nullptr) - fail << "variable " << var << " cannot be overridden"; + + if (po == nullptr) // NULL overridable falls back to false. + po = &(vo = false); + + update (var, pt, pv, po); // Not changing the key. } return var; @@ -1320,6 +1318,8 @@ namespace build2 nullptr /* override */, false /* pattern */)); + assert (a.overrides == nullptr); + if (a.aliases == &a) // Not aliased yet. { a.aliases = var.aliases; -- cgit v1.1