From 5c369faa461ec4416d2d4b231a5b36963a7315ce Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 4 Apr 2016 13:06:50 +0200 Subject: Implement value typing, null support via value attributes For example: v = [null] v = [string] abc v += ABC # abcABC --- build2/target.cxx | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'build2/target.cxx') diff --git a/build2/target.cxx b/build2/target.cxx index c9e6fde..782a7dd 100644 --- a/build2/target.cxx +++ b/build2/target.cxx @@ -115,12 +115,10 @@ namespace build2 } pair target:: - find (const variable& var) const + find_original (const variable& var) const { pair r (lookup (), 0); - scope& s (base_scope ()); - ++r.second; if (auto p = vars.find (var)) r.first = lookup (p, &vars); @@ -135,37 +133,39 @@ namespace build2 } } - // Delegate to scope's find(). + // Delegate to scope's find_original(). // if (!r.first) { - auto p (s.find_original (var, - &type (), - &name, - group != nullptr ? &group->type () : nullptr, - group != nullptr ? &group->name : nullptr)); + auto p (base_scope ().find_original ( + var, + &type (), + &name, + group != nullptr ? &group->type () : nullptr, + group != nullptr ? &group->name : nullptr)); r.first = move (p.first); r.second = r.first ? r.second + p.second : p.second; } - return var.override == nullptr - ? r - : s.find_override (var, move (r), true); + return r; } value& target:: append (const variable& var) { - auto l (operator[] (var)); + // Note that here we want the original value without any overrides + // applied. + // + lookup l (find_original (var).first); - if (l && l.belongs (*this)) // Existing variable in this target. - return const_cast (*l); + if (l.defined () && l.belongs (*this)) // Existing var in this target. + return const_cast (*l); // Ok since this is original. - value& r (assign (var)); + value& r (assign (var)); // NULL. - if (l) - r = *l; // Copy value from the outer scope. + if (l.defined ()) + r = *l; // Copy value (and type) from the outer scope. return r; } -- cgit v1.1