From bd32ea47fd8f720b54f81a769dc007d1fdb4e5c1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 23 Aug 2016 09:05:54 +0200 Subject: Reverse empty simple values as an empty names sequence rather than empty name This way we get: config.import.foo = Rather than: config.import.foo = {} --- build2/variable | 2 ++ build2/variable.cxx | 27 ++++++++++++++++----------- build2/variable.txx | 16 +++++++++++++++- 3 files changed, 33 insertions(+), 12 deletions(-) (limited to 'build2') diff --git a/build2/variable b/build2/variable index 1248bd3..fb44bb4 100644 --- a/build2/variable +++ b/build2/variable @@ -476,6 +476,7 @@ namespace build2 static void append (value&, bool); // OR. static name reverse (bool x) {return name (x ? "true" : "false", false);} static int compare (bool, bool); + static bool empty (bool) {return false;} static const char* const type_name; static const build2::value_type value_type; @@ -491,6 +492,7 @@ namespace build2 static void append (value&, uint64_t); // ADD. static name reverse (uint64_t x) {return name (to_string (x), false);} static int compare (uint64_t, uint64_t); + static bool empty (bool) {return false;} static const char* const type_name; static const build2::value_type value_type; diff --git a/build2/variable.cxx b/build2/variable.cxx index 7a13618..0134683 100644 --- a/build2/variable.cxx +++ b/build2/variable.cxx @@ -643,7 +643,8 @@ namespace build2 static names_view name_reverse (const value& v, names&) { - return names_view (&v.as (), 1); + const name& n (v.as ()); + return n.empty () ? names_view (nullptr, 0) : names_view (&n, 1); } const char* const value_traits::type_name = "name"; @@ -726,19 +727,23 @@ namespace build2 static names_view process_path_reverse (const value& v, names& s) { - auto& pp (v.as ()); - s.reserve (pp.effect.empty () ? 1 : 2); + const process_path& x (v.as ()); - s.push_back (name (pp.recall.directory (), - string (), - pp.recall.leaf ().string ())); - - if (!pp.effect.empty ()) + if (!x.empty ()) { - s.back ().pair = '@'; - s.push_back (name (pp.effect.directory (), + s.reserve (x.effect.empty () ? 1 : 2); + + s.push_back (name (x.recall.directory (), string (), - pp.effect.leaf ().string ())); + x.recall.leaf ().string ())); + + if (!x.effect.empty ()) + { + s.back ().pair = '@'; + s.push_back (name (x.effect.directory (), + string (), + x.effect.leaf ().string ())); + } } return s; diff --git a/build2/variable.txx b/build2/variable.txx index f1335b4..95e4f0a 100644 --- a/build2/variable.txx +++ b/build2/variable.txx @@ -148,7 +148,21 @@ namespace build2 names_view simple_reverse (const value& v, names& s) { - s.emplace_back (value_traits::reverse (v.as ())); + const T& x (v.as ()); + + // Represent an empty simple value as empty name sequence rather than + // a single empty name. This way, for example, during serialization we + // end up with a much saner looking: + // + // config.import.foo = + // + // Rather than: + // + // config.import.foo = {} + // + if (!value_traits::empty (x)) + s.emplace_back (value_traits::reverse (x)); + return s; } -- cgit v1.1