aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-06-26 16:36:53 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-06-26 16:36:53 +0200
commit61617d7bb990f04970c6357d8e9a9095174d8fc4 (patch)
treec73f266c027d09dd1d0cd4d4233e8fc70ce27447
parent4d1c02b736f4c1e827b11085cdc83ce4b46c03d1 (diff)
Minor module interface cleanups
-rw-r--r--build2/cli/module.cxx17
-rw-r--r--build2/cxx/module.cxx12
-rw-r--r--build2/file.cxx2
-rw-r--r--build2/module6
-rw-r--r--build2/module.cxx6
-rw-r--r--build2/parser.cxx2
-rw-r--r--build2/variable7
-rw-r--r--build2/variable.ixx8
8 files changed, 33 insertions, 27 deletions
diff --git a/build2/cli/module.cxx b/build2/cli/module.cxx
index 44b36a1..478c8a8 100644
--- a/build2/cli/module.cxx
+++ b/build2/cli/module.cxx
@@ -36,18 +36,13 @@ namespace build2
tracer trace ("cli::init");
l5 ([&]{trace << "for " << base.out_path ();});
- // Make sure the cxx module has been loaded since we need its
- // targets types (?xx{}). Note that we don't try to load it
- // ourselves because of the non-trivial variable merging
- // semantics. So it is better to let the user load cxx
- // explicitly.
+ // Make sure the cxx module has been loaded since we need its targets
+ // types (?xx{}). Note that we don't try to load it ourselves because of
+ // the non-trivial variable merging semantics. So it is better to let
+ // the user load cxx explicitly.
//
- {
- auto l (base["cxx.loaded"]);
-
- if (!l || !cast<bool> (l))
- fail (loc) << "cxx module must be loaded before cli";
- }
+ if (!cast_false<bool> (base["cxx.loaded"]))
+ fail (loc) << "cxx module must be loaded before cli";
// Enter module variables.
//
diff --git a/build2/cxx/module.cxx b/build2/cxx/module.cxx
index b4ce142..c03763f 100644
--- a/build2/cxx/module.cxx
+++ b/build2/cxx/module.cxx
@@ -40,15 +40,11 @@ namespace build2
tracer trace ("cxx::init");
l5 ([&]{trace << "for " << b.out_path ();});
- // Initialize the bin module. Only do this if it hasn't already
- // been loaded so that we don't overwrite user's bin.* settings.
+ // Initialize the bin module. Only do this if it hasn't already been
+ // loaded so that we don't overwrite user's bin.* settings.
//
- {
- auto l (b["bin.loaded"]);
-
- if (!l || !cast<bool> (l))
- load_module (false, "bin", r, b, loc);
- }
+ if (!cast_false<bool> (b["bin.loaded"]))
+ load_module ("bin", r, b, loc);
// Enter module variables.
//
diff --git a/build2/file.cxx b/build2/file.cxx
index f5ce91c..8b6291a 100644
--- a/build2/file.cxx
+++ b/build2/file.cxx
@@ -781,7 +781,7 @@ namespace build2
if (s.boot)
{
- load_module (false, n, root, root, s.loc);
+ load_module (n, root, root, s.loc);
assert (!s.boot);
}
}
diff --git a/build2/module b/build2/module
index 25574d1..dcfe5d0 100644
--- a/build2/module
+++ b/build2/module
@@ -76,11 +76,11 @@ namespace build2
// (false can only be returned if optional).
//
bool
- load_module (bool optional,
- const string& name,
+ load_module (const string& name,
scope& root,
scope& base,
- const location&);
+ const location&,
+ bool optional = false);
// Builtin modules.
//
diff --git a/build2/module.cxx b/build2/module.cxx
index cfab057..1334689 100644
--- a/build2/module.cxx
+++ b/build2/module.cxx
@@ -50,11 +50,11 @@ namespace build2
}
bool
- load_module (bool opt,
- const string& name,
+ load_module (const string& name,
scope& rs,
scope& bs,
- const location& loc)
+ const location& loc,
+ bool opt)
{
// First see if this modules has already been loaded for this project.
//
diff --git a/build2/parser.cxx b/build2/parser.cxx
index 20cb75f..1edc7ba 100644
--- a/build2/parser.cxx
+++ b/build2/parser.cxx
@@ -1102,7 +1102,7 @@ namespace build2
if (boot_)
boot_module (n, *root_, l);
else
- load_module (optional, n, *root_, *scope_, l);
+ load_module (n, *root_, *scope_, l, optional);
}
}
diff --git a/build2/variable b/build2/variable
index a5f2ea5..c506a3e 100644
--- a/build2/variable
+++ b/build2/variable
@@ -252,6 +252,13 @@ namespace build2
template <typename T> const T* cast_null (const value&);
template <typename T> const T* cast_null (const lookup&);
+ // As above but returns false if the value is NULL (or not defined, in case
+ // of lookup). Note that the template argument is only for documentation and
+ // should be bool (or semantically compatible).
+ //
+ template <typename T> T cast_false (const value& v);
+ template <typename T> T cast_false (const lookup& l);
+
// Assign value type to the value. In the second version the variable is
// optional and is only used for diagnostics.
//
diff --git a/build2/variable.ixx b/build2/variable.ixx
index e01e3d6..da86c39 100644
--- a/build2/variable.ixx
+++ b/build2/variable.ixx
@@ -158,6 +158,14 @@ namespace build2
}
template <typename T>
+ inline T
+ cast_false (const value& v) {return v && cast<T> (v);}
+
+ template <typename T>
+ inline T
+ cast_false (const lookup& l) {return l && cast<T> (l);}
+
+ template <typename T>
inline void
typify (value& v, const variable& var)
{