aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-04-08 16:09:31 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-04-08 16:09:31 +0200
commit5af9070fda0dba591264ed675920efcfd62e81bc (patch)
tree8331fc83572c4bcd93a06adfcb489877b9816153
parent22a280a1f3f92c2e01ef192a4dda65e7ae957188 (diff)
Distinguish between undefined and null variables
-rw-r--r--build/config/operation.cxx8
-rw-r--r--build/cxx/module.cxx60
-rw-r--r--build/variable10
3 files changed, 51 insertions, 27 deletions
diff --git a/build/config/operation.cxx b/build/config/operation.cxx
index b85a5c7..ef83e47 100644
--- a/build/config/operation.cxx
+++ b/build/config/operation.cxx
@@ -99,13 +99,13 @@ namespace build
//
if (auto gval = (*global_scope)[var])
{
- if (!pval || !pval->compare (gval.as<const value&> ()))
+ if (pval == nullptr || !pval->compare (gval.as<const value&> ()))
warn << "variable " << var.name << " configured value "
<< "differs from command line value" <<
info << "reconfigure the project to use command line value";
}
- if (pval)
+ if (pval != nullptr)
{
//@@ TODO: assuming list
//
@@ -116,8 +116,8 @@ namespace build
}
else
{
- ofs << var.name << " =" << endl; // @@ TODO: [undefined]
- //text << var.name << " = [undefined]";
+ ofs << var.name << " = #[null]" << endl; // @@ TODO: [null]
+ //text << var.name << " = [null]";
}
}
}
diff --git a/build/cxx/module.cxx b/build/cxx/module.cxx
index 2bfdc41..e29d311 100644
--- a/build/cxx/module.cxx
+++ b/build/cxx/module.cxx
@@ -104,41 +104,57 @@ namespace build
//
// These are optional so all we need to do is "import" them
// into the root scope if they were specified on the command
- // line and set them to empty if unspecified (the last part
+ // line and set them to NULL if unspecified (the last part
// is important to distinguish between the "configured as
- // undefined" and "not configured" cases).
+ // unspecified" and "not configured" cases).
//
- if (auto val = root["config.cxx.poptions"])
{
- if (val.scope == global_scope)
- root.variables["config.cxx.poptions"] = val;
+ auto v (root["config.cxx.poptions"]);
+
+ if (v.defined ())
+ {
+ if (v.scope == global_scope)
+ root.variables["config.cxx.poptions"] = v;
+ }
+ else
+ root.variables["config.cxx.poptions"]; // Set to NULL.
}
- else
- root.variables["config.cxx.poptions"]; // Undefined.
- if (auto val = root["config.cxx.coptions"])
{
- if (val.scope == global_scope)
- root.variables["config.cxx.coptions"] = val;
+ auto v (root["config.cxx.coptions"]);
+
+ if (v.defined ())
+ {
+ if (v.scope == global_scope)
+ root.variables["config.cxx.coptions"] = v;
+ }
+ else
+ root.variables["config.cxx.coptions"]; // Set to NULL.
}
- else
- root.variables["config.cxx.coptions"]; // Undefined.
- if (auto val = root["config.cxx.loptions"])
{
- if (val.scope == global_scope)
- root.variables["config.cxx.loptions"] = val;
+ auto v (root["config.cxx.loptions"]);
+
+ if (v.defined ())
+ {
+ if (v.scope == global_scope)
+ root.variables["config.cxx.loptions"] = v;
+ }
+ else
+ root.variables["config.cxx.loptions"]; // Set to NULL.
}
- else
- root.variables["config.cxx.loptions"]; // Undefined.
- if (auto val = root["config.cxx.libs"])
{
- if (val.scope == global_scope)
- root.variables["config.cxx.libs"] = val;
+ auto v (root["config.cxx.libs"]);
+
+ if (v.defined ())
+ {
+ if (v.scope == global_scope)
+ root.variables["config.cxx.libs"] = v;
+ }
+ else
+ root.variables["config.cxx.libs"]; // Set to NULL.
}
- else
- root.variables["config.cxx.libs"]; // Undefined.
}
}
}
diff --git a/build/variable b/build/variable
index fc0ba2b..67ec33c 100644
--- a/build/variable
+++ b/build/variable
@@ -90,11 +90,19 @@ namespace build
// value_proxy
//
+ // A variable can be undefined, null, or contain some actual value.
+ //
struct value_proxy
{
typedef build::scope scope_type;
- explicit operator bool () const {return p != nullptr && *p != nullptr;}
+ bool
+ defined () const {return p != nullptr;}
+
+ bool
+ null () const {return *p == nullptr;}
+
+ explicit operator bool () const {return defined () && !null ();}
explicit operator value_ptr& () const {return *p;}
scope_type* scope;