aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/functions-builtin.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-03-18 07:19:41 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-03-18 07:19:41 +0200
commit65be7de7aca4bdac05e0acf68ec86a351e779839 (patch)
treec0fc17cf80c8b07ccf7e51936df0a818d3ced1a4 /libbuild2/functions-builtin.cxx
parentc0f6b9b835e8ede26e407d7431d0a44aeb41dc15 (diff)
Add $visibility(<variable>) function for querying variable visibility
Diffstat (limited to 'libbuild2/functions-builtin.cxx')
-rw-r--r--libbuild2/functions-builtin.cxx15
1 files changed, 15 insertions, 0 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 ();};