From 54fb34bb1ccfac35addd381921be316302276b1b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 2 Apr 2016 09:06:26 +0200 Subject: Add notion of lookup depth, fix bug with NULL overrides --- build2/target | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'build2/target') diff --git a/build2/target b/build2/target index af573fa..eb6154a 100644 --- a/build2/target +++ b/build2/target @@ -276,7 +276,10 @@ namespace build2 // (and note that there will be no overrides). // lookup - operator[] (const variable&) const; + operator[] (const variable& var) const + { + return find (var).first; + } lookup operator[] (const string& name) const @@ -284,6 +287,21 @@ namespace build2 return operator[] (var_pool.find (name)); } + // As above but also return the depth at which the value is found. The + // depth is calculated by adding 1 for each test performed. So a value + // that is from the target will have depth 1. That from the group -- 2. + // From the innermost scope's target type/patter-specific variables -- + // 3. From the innermost scope's variables -- 4. And so on. The idea is + // that given two lookups from the same target, we can say which one came + // earlier. If no value is found, then the depth is set to ~0. + // + pair + find (const variable&) const; + + pair + find (const string& name) const {return find (var_pool.find (name));} + + // Return a value suitable for assignment. See class scope for // details. // -- cgit v1.1