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-path.cxx | 83 +++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 40 deletions(-) (limited to 'libbuild2/functions-path.cxx') diff --git a/libbuild2/functions-path.cxx b/libbuild2/functions-path.cxx index 2d5fad4..fdf712c 100644 --- a/libbuild2/functions-path.cxx +++ b/libbuild2/functions-path.cxx @@ -144,9 +144,9 @@ namespace build2 // string // - f["string"] = [](path p) {return move (p).string ();}; + f["string"] += [](path p) {return move (p).string ();}; - f["string"] = [](paths v) + f["string"] += [](paths v) { strings r; for (auto& p: v) @@ -154,7 +154,7 @@ namespace build2 return r; }; - f["string"] = [](dir_paths v) + f["string"] += [](dir_paths v) { strings r; for (auto& p: v) @@ -164,9 +164,9 @@ namespace build2 // representation // - f["representation"] = [](path p) {return move (p).representation ();}; + f["representation"] += [](path p) {return move (p).representation ();}; - f["representation"] = [](paths v) + f["representation"] += [](paths v) { strings r; for (auto& p: v) @@ -174,7 +174,7 @@ namespace build2 return r; }; - f["representation"] = [](dir_paths v) + f["representation"] += [](dir_paths v) { strings r; for (auto& p: v) @@ -186,24 +186,24 @@ namespace build2 // // @@ TODO: add ability to specify alternative separator. // - f["canonicalize"] = [](path p) {p.canonicalize (); return p;}; - f["canonicalize"] = [](dir_path p) {p.canonicalize (); return p;}; + f["canonicalize"] += [](path p) {p.canonicalize (); return p;}; + f["canonicalize"] += [](dir_path p) {p.canonicalize (); return p;}; - f["canonicalize"] = [](paths v) + f["canonicalize"] += [](paths v) { for (auto& p: v) p.canonicalize (); return v; }; - f["canonicalize"] = [](dir_paths v) + f["canonicalize"] += [](dir_paths v) { for (auto& p: v) p.canonicalize (); return v; }; - f[".canonicalize"] = [](names ns) + f[".canonicalize"] += [](names ns) { // For each path decide based on the presence of a trailing slash // whether it is a directory. Return as untyped list of (potentially @@ -221,19 +221,22 @@ namespace build2 // normalize // - f["normalize"] = [](path p, optional a) + // @@ TODO: normalize(true) is not pure, redo as a separate actualize() + // function. + // + f["normalize"] += [](path p, optional a) { p.normalize (a && convert (move (*a))); return p; }; - f["normalize"] = [](dir_path p, optional a) + f["normalize"] += [](dir_path p, optional a) { p.normalize (a && convert (move (*a))); return p; }; - f["normalize"] = [](paths v, optional a) + f["normalize"] += [](paths v, optional a) { bool act (a && convert (move (*a))); @@ -242,7 +245,7 @@ namespace build2 return v; }; - f["normalize"] = [](dir_paths v, optional a) + f["normalize"] += [](dir_paths v, optional a) { bool act (a && convert (move (*a))); @@ -251,7 +254,7 @@ namespace build2 return v; }; - f[".normalize"] = [](names ns, optional a) + f[".normalize"] += [](names ns, optional a) { bool act (a && convert (move (*a))); @@ -271,9 +274,9 @@ namespace build2 // directory // - f["directory"] = &path::directory; + f["directory"] += &path::directory; - f["directory"] = [](paths v) + f["directory"] += [](paths v) { dir_paths r; for (const path& p: v) @@ -281,14 +284,14 @@ namespace build2 return r; }; - f["directory"] = [](dir_paths v) + f["directory"] += [](dir_paths v) { for (dir_path& p: v) p = p.directory (); return v; }; - f[".directory"] = [](names ns) + f[".directory"] += [](names ns) { // For each path decide based on the presence of a trailing slash // whether it is a directory. Return as list of directory names. @@ -305,23 +308,23 @@ namespace build2 // base // - f["base"] = &path::base; + f["base"] += &path::base; - f["base"] = [](paths v) + f["base"] += [](paths v) { for (path& p: v) p = p.base (); return v; }; - f["base"] = [](dir_paths v) + f["base"] += [](dir_paths v) { for (dir_path& p: v) p = p.base (); return v; }; - f[".base"] = [](names ns) + f[".base"] += [](names ns) { // For each path decide based on the presence of a trailing slash // whether it is a directory. Return as untyped list of (potentially @@ -339,28 +342,28 @@ namespace build2 // leaf // - f["leaf"] = &path::leaf; + f["leaf"] += &path::leaf; - f["leaf"] = [](path p, dir_path d) + f["leaf"] += [](path p, dir_path d) { return leaf (p, move (d)); }; - f["leaf"] = [](paths v, optional d) + f["leaf"] += [](paths v, optional d) { for (path& p: v) p = leaf (p, d); return v; }; - f["leaf"] = [](dir_paths v, optional d) + f["leaf"] += [](dir_paths v, optional d) { for (dir_path& p: v) p = leaf (p, d); return v; }; - f[".leaf"] = [](names ns, optional d) + f[".leaf"] += [](names ns, optional d) { // For each path decide based on the presence of a trailing slash // whether it is a directory. Return as untyped list of (potentially @@ -378,9 +381,9 @@ namespace build2 // extension // - f["extension"] = &extension; + f["extension"] += &extension; - f[".extension"] = [](names ns) + f[".extension"] += [](names ns) { return extension (convert (move (ns))); }; @@ -415,19 +418,19 @@ namespace build2 // // Name matching. // - f[".match"] = [](string name, string pattern) + f[".match"] += [](string name, string pattern) { return path_match (name, pattern); }; // Path matching. // - f["match"] = [](path ent, path pat, optional start) + f["match"] += [](path ent, path pat, optional start) { return path_match (ent, pat, start); }; - f["match"] = [](path ent, names pat, optional start) + f["match"] += [](path ent, names pat, optional start) { return path_match (ent, convert (move (pat)), @@ -436,7 +439,7 @@ namespace build2 : optional ()); }; - f["match"] = [](names ent, path pat, optional start) + f["match"] += [](names ent, path pat, optional start) { return path_match (convert (move (ent)), pat, @@ -448,7 +451,7 @@ namespace build2 // The semantics depends on the presence of the start directory or the // first two argument syntactic representation. // - f[".match"] = [](names ent, names pat, optional start) + f[".match"] += [](names ent, names pat, optional start) { auto path_arg = [] (const names& a) -> bool { @@ -472,15 +475,15 @@ namespace build2 // function_family b (m, "builtin", &path_thunk); - b[".concat"] = &concat_path_string; - b[".concat"] = &concat_dir_path_string; + b[".concat"] += &concat_path_string; + b[".concat"] += &concat_dir_path_string; - b[".concat"] = [](path l, names ur) + b[".concat"] += [](path l, names ur) { return concat_path_string (move (l), convert (move (ur))); }; - b[".concat"] = [](dir_path l, names ur) + b[".concat"] += [](dir_path l, names ur) { return concat_dir_path_string (move (l), convert (move (ur))); }; -- cgit v1.1