From 9891b20350021ce41a950645dd76df20a45c92cc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 2 Dec 2015 11:37:15 +0200 Subject: Implement optional module loading The syntax is: using? cli Now each module use results in two bool variables: .loaded and .configured. Also implement variable visibility (the above two variables are limited to project). --- build/scope.cxx | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'build/scope.cxx') diff --git a/build/scope.cxx b/build/scope.cxx index 305950b..dfddf20 100644 --- a/build/scope.cxx +++ b/build/scope.cxx @@ -13,37 +13,33 @@ namespace build // scope // lookup scope:: - operator[] (const variable& var) const + lookup (const target_type* tt, const string* name, const variable& var) const { using result = build::lookup; - const value* r (nullptr); - const scope* s (this); - - for (; s != nullptr; s = s->parent_scope ()) + for (const scope* s (this); s != nullptr; ) { - if ((r = s->vars.find (var)) != nullptr) - break; - } - - return result (r, &s->vars); - } - - lookup scope:: - lookup (const target_type& tt, const string& name, const variable& var) const - { - using result = build::lookup; - - for (const scope* s (this); s != nullptr; s = s->parent_scope ()) - { - if (!s->target_vars.empty ()) + if (tt != nullptr && !s->target_vars.empty ()) { - if (auto l = s->target_vars.lookup (tt, name, var)) + if (auto l = s->target_vars.lookup (*tt, *name, var)) return l; } if (auto r = s->vars.find (var)) return result (r, &s->vars); + + switch (var.visibility) + { + case variable_visibility::scope: + s = nullptr; + break; + case variable_visibility::project: + s = s->root () ? nullptr : s->parent_scope (); + break; + case variable_visibility::normal: + s = s->parent_scope (); + break; + } } return result (); -- cgit v1.1