From 4168cda2363f3d796d0b9922852e249aac3131ba Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 4 Dec 2020 08:39:35 +0200 Subject: Mark Buildfile functions as pure or impure --- libbuild2/functions-builtin.cxx | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'libbuild2/functions-builtin.cxx') diff --git a/libbuild2/functions-builtin.cxx b/libbuild2/functions-builtin.cxx index 97cc449..4689ac2 100644 --- a/libbuild2/functions-builtin.cxx +++ b/libbuild2/functions-builtin.cxx @@ -19,7 +19,9 @@ namespace build2 // Note that we may want to extend the scope argument to a more general // notion of "lookup context" (scope, target, prerequisite). // - f["defined"] = [](const scope* s, names name) + // Note that this function is not pure. + // + f.insert ("defined", false) += [](const scope* s, names name) { if (s == nullptr) fail << "defined() called out of scope" << endf; @@ -29,7 +31,9 @@ namespace build2 // Return variable visibility if it has been entered and NULL otherwise. // - f["visibility"] = [](const scope* s, names name) + // Note that this function is not pure. + // + f.insert ("visibility", false) += [](const scope* s, names name) { if (s == nullptr) fail << "visibility() called out of scope" << endf; @@ -42,25 +46,25 @@ namespace build2 : 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 ();}; + 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 ();}; - f["identity"] = [](value* v) {return move (*v);}; + f["identity"] += [](value* v) {return move (*v);}; // string // - f["string"] = [](bool b) {return b ? "true" : "false";}; - f["string"] = [](int64_t i) {return to_string (i);}; - f["string"] = [](uint64_t i) {return to_string (i);}; - f["string"] = [](name n) {return to_string (n);}; + f["string"] += [](bool b) {return b ? "true" : "false";}; + f["string"] += [](int64_t i) {return to_string (i);}; + f["string"] += [](uint64_t i) {return to_string (i);}; + f["string"] += [](name n) {return to_string (n);}; // Quote a value returning its string representation. If escape is true, // then also escape (with a backslash) the quote characters being added // (this is useful if the result will be re-parsed, for example as a // Testscript command line). // - f["quote"] = [](value* v, optional escape) + f["quote"] += [](value* v, optional escape) { if (v->null) return string (); @@ -81,7 +85,9 @@ namespace build2 // Return NULL if the environment variable is not set, untyped value // otherwise. // - f["getenv"] = [](names name) + // Note that this function is not pure. + // + f.insert ("getenv", false) += [](names name) { optional v (getenv (convert (move (name)))); -- cgit v1.1