aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbuild2/functions-builtin.cxx15
-rw-r--r--libbuild2/variable.cxx18
-rw-r--r--libbuild2/variable.hxx10
3 files changed, 32 insertions, 11 deletions
diff --git a/libbuild2/functions-builtin.cxx b/libbuild2/functions-builtin.cxx
index c4f0314..4e28741 100644
--- a/libbuild2/functions-builtin.cxx
+++ b/libbuild2/functions-builtin.cxx
@@ -27,6 +27,21 @@ namespace build2
return (*s)[convert<string> (move (name))].defined ();
};
+ // Return variable visibility if it exists and NULL otherwise.
+ //
+ f["visibility"] = [](const scope* s, names name)
+ {
+ if (s == nullptr)
+ fail << "visibility() called out of scope" << endf;
+
+ const variable* var (
+ s->ctx.var_pool.find (convert<string> (move (name))));
+
+ return (var != nullptr
+ ? optional<string> (to_string (var->visibility))
+ : nullopt);
+ };
+
f["type"] = [](value* v) {return v->type != nullptr ? v->type->name : "";};
f["null"] = [](value* v) {return v->null;};
f["empty"] = [](value* v) {return v->null || v->empty ();};
diff --git a/libbuild2/variable.cxx b/libbuild2/variable.cxx
index 0460344..7b55357 100644
--- a/libbuild2/variable.cxx
+++ b/libbuild2/variable.cxx
@@ -15,21 +15,21 @@ namespace build2
{
// variable_visibility
//
- ostream&
- operator<< (ostream& o, variable_visibility v)
+ string
+ to_string (variable_visibility v)
{
- const char* s (nullptr);
+ string r;
switch (v)
{
- case variable_visibility::normal: s = "normal"; break;
- case variable_visibility::project: s = "project"; break;
- case variable_visibility::scope: s = "scope"; break;
- case variable_visibility::target: s = "target"; break;
- case variable_visibility::prereq: s = "prerequisite"; break;
+ case variable_visibility::normal: r = "normal"; break;
+ case variable_visibility::project: r = "project"; break;
+ case variable_visibility::scope: r = "scope"; break;
+ case variable_visibility::target: r = "target"; break;
+ case variable_visibility::prereq: r = "prerequisite"; break;
}
- return o << s;
+ return r;
}
// value
diff --git a/libbuild2/variable.hxx b/libbuild2/variable.hxx
index 071cb5f..b293215 100644
--- a/libbuild2/variable.hxx
+++ b/libbuild2/variable.hxx
@@ -136,8 +136,14 @@ namespace build2
}
#endif
- LIBBUILD2_SYMEXPORT ostream&
- operator<< (ostream&, variable_visibility);
+ LIBBUILD2_SYMEXPORT string
+ to_string (variable_visibility);
+
+ inline ostream&
+ operator<< (ostream& o, variable_visibility v)
+ {
+ return o << to_string (v);
+ }
// variable
//