From 218a739b33325c5dd6baa5cf6291dad849ad2441 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 14 Dec 2022 08:03:32 +0200 Subject: Handle NULL values in $string() and $concat() functions This is relied upon by the parser to provide conversion/concatenation semantics consistent with untyped values. Note that we handle NULL values only for types that have empty representation. --- libbuild2/functions-string.cxx | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'libbuild2/functions-string.cxx') diff --git a/libbuild2/functions-string.cxx b/libbuild2/functions-string.cxx index f5d7cb1..06fe89d 100644 --- a/libbuild2/functions-string.cxx +++ b/libbuild2/functions-string.cxx @@ -39,12 +39,13 @@ namespace build2 { function_family f (m, "string"); - f["string"] += [](string s) {return s;}; - - // @@ Shouldn't it concatenate elements into the single string? - // @@ Doesn't seem to be used so far. Can consider removing. + // Note that we must handle NULL values (relied upon by the parser + // to provide conversion semantics consistent with untyped values). // - // f["string"] += [](strings v) {return v;}; + f["string"] += [](string* s) + { + return s != nullptr ? move (*s) : string (); + }; // Compare ASCII strings ignoring case and returning the boolean value. // @@ -195,19 +196,26 @@ namespace build2 // function_family b (m, "builtin"); - b[".concat"] += [](string l, string r) {l += r; return l;}; + // Note that we must handle NULL values (relied upon by the parser to + // provide concatenation semantics consistent with untyped values). + // + b[".concat"] += [](string* l, string* r) + { + return l != nullptr + ? r != nullptr ? move (*l += *r) : move (*l) + : r != nullptr ? move (*r) : string (); + }; - b[".concat"] += [](string l, names ur) + b[".concat"] += [](string* l, names* ur) { - l += convert (move (ur)); - return l; + string r (ur != nullptr ? convert (move (*ur)) : string ()); + return l != nullptr ? move (*l += r) : move (r); }; - b[".concat"] += [](names ul, string r) + b[".concat"] += [](names* ul, string* r) { - string l (convert (move (ul))); - l += r; - return l; + string l (ul != nullptr ? convert (move (*ul)) : string ()); + return r != nullptr ? move (l += *r) : move (l); }; } } -- cgit v1.1