From aeeedd32f8717d8c6a1886a5561a879059be87d0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 16 Nov 2016 10:53:39 +0200 Subject: Make names and vector different types, add typed value constructor --- build2/c/init.cxx | 8 ++++---- build2/cc/common.cxx | 2 +- build2/cc/init.cxx | 8 ++++---- build2/cc/pkgconfig.cxx | 2 +- build2/cxx/init.cxx | 8 ++++---- build2/name | 10 +++++++++- build2/parser.cxx | 2 +- build2/variable | 13 +++++++++++-- build2/variable.ixx | 23 ++++++++++++++--------- 9 files changed, 49 insertions(+), 27 deletions(-) (limited to 'build2') diff --git a/build2/c/init.cxx b/build2/c/init.cxx index 750c729..aaef186 100644 --- a/build2/c/init.cxx +++ b/build2/c/init.cxx @@ -147,10 +147,10 @@ namespace build2 v["cc.loptions"], v["cc.libs"], - v.insert ("c.export.poptions"), - v.insert ("c.export.coptions"), - v.insert ("c.export.loptions"), - v.insert ("c.export.libs"), + v.insert ("c.export.poptions"), + v.insert ("c.export.coptions"), + v.insert ("c.export.loptions"), + v.insert> ("c.export.libs"), v["cc.export.poptions"], v["cc.export.coptions"], diff --git a/build2/cc/common.cxx b/build2/cc/common.cxx index 911fbfa..14201d4 100644 --- a/build2/cc/common.cxx +++ b/build2/cc/common.cxx @@ -264,7 +264,7 @@ namespace build2 &find_sysd, &find_lo, &sys, &sys_simple, &bs, &lo, this] (const lookup& lu) { - const names* ns (cast_null (lu)); + const vector* ns (cast_null> (lu)); if (ns == nullptr || ns->empty ()) return; diff --git a/build2/cc/init.cxx b/build2/cc/init.cxx index b9dc4c1..036d622 100644 --- a/build2/cc/init.cxx +++ b/build2/cc/init.cxx @@ -49,10 +49,10 @@ namespace build2 v.insert ("cc.loptions"); v.insert ("cc.libs"); - v.insert ("cc.export.poptions"); - v.insert ("cc.export.coptions"); - v.insert ("cc.export.loptions"); - v.insert ("cc.export.libs"); + v.insert ("cc.export.poptions"); + v.insert ("cc.export.coptions"); + v.insert ("cc.export.loptions"); + v.insert> ("cc.export.libs"); // Hint variables (not overridable). // diff --git a/build2/cc/pkgconfig.cxx b/build2/cc/pkgconfig.cxx index 3a7bf82..580812c 100644 --- a/build2/cc/pkgconfig.cxx +++ b/build2/cc/pkgconfig.cxx @@ -260,7 +260,7 @@ namespace build2 const string& lstr, target& t) { strings lops; - names libs; + vector libs; // Normally we will have zero or more -L's followed by one or more // -l's, with the first one being the library itself. But sometimes diff --git a/build2/cxx/init.cxx b/build2/cxx/init.cxx index 59d4cc6..92c0253 100644 --- a/build2/cxx/init.cxx +++ b/build2/cxx/init.cxx @@ -147,10 +147,10 @@ namespace build2 v["cc.loptions"], v["cc.libs"], - v.insert ("cxx.export.poptions"), - v.insert ("cxx.export.coptions"), - v.insert ("cxx.export.loptions"), - v.insert ("cxx.export.libs"), + v.insert ("cxx.export.poptions"), + v.insert ("cxx.export.coptions"), + v.insert ("cxx.export.loptions"), + v.insert> ("cxx.export.libs"), v["cc.export.poptions"], v["cc.export.coptions"], diff --git a/build2/name b/build2/name index 12aa9dc..e079c9f 100644 --- a/build2/name +++ b/build2/name @@ -125,7 +125,15 @@ namespace build2 // Vector of names. // - using names = vector; + // We make it a separate type rather than an alias for vector in order + // to distinguish between untyped variable values (names) and typed ones + // (vector). + // + struct names: vector + { + using vector::vector; + }; + using names_view = vector_view; // The same semantics as to_stream(name). diff --git a/build2/parser.cxx b/build2/parser.cxx index bfbaa04..d095047 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -1497,7 +1497,7 @@ namespace build2 n == "strings" ? &value_traits::value_type : n == "paths" ? &value_traits::value_type : n == "dir_paths" ? &value_traits::value_type : - n == "names" ? &value_traits::value_type : + n == "names" ? &value_traits>::value_type : nullptr; } diff --git a/build2/variable b/build2/variable index 6bdc728..ab5586d 100644 --- a/build2/variable +++ b/build2/variable @@ -165,11 +165,18 @@ namespace build2 ~value () {*this = nullptr;} explicit - value (const value_type* t = nullptr): type (t), null (true), extra (0) {} + value (nullptr_t = nullptr): type (nullptr), null (true), extra (0) {} + + explicit + value (const value_type* t): type (t), null (true), extra (0) {} explicit value (names&&); // Create untyped value. + template + explicit + value (T); // Create value of value_traits::value_type type. + // Note: preserves type. // value& @@ -257,10 +264,12 @@ namespace build2 // Value cast. The first three expect the value to be not NULL. The cast // from lookup expects the value to aslo be defined. // + // Note that a cast to names expects the value to be untyped while a cast + // to vector -- typed. + // // Why are these non-members? The cast is easier on the eyes and is also // consistent with the cast operators. The other two are for symmetry. // - // template T& cast (value&); template T&& cast (value&&); template const T& cast (const value&); diff --git a/build2/variable.ixx b/build2/variable.ixx index 5c9118b..d054dd4 100644 --- a/build2/variable.ixx +++ b/build2/variable.ixx @@ -12,8 +12,9 @@ namespace build2 empty () const { assert (!null); - return type == nullptr ? as ().empty () : - type->empty == nullptr ? false : type->empty (*this); + return type == nullptr + ? as ().empty () + : type->empty == nullptr ? false : type->empty (*this); } inline value:: @@ -23,6 +24,15 @@ namespace build2 new (&data_) names (move (ns)); } + template + inline value:: + value (T v) + : type (&value_traits::value_type), null (true), extra (0) + { + value_traits::assign (*this, move (v)); + null = false; + } + inline value& value:: operator= (reference_wrapper v) { @@ -93,10 +103,7 @@ namespace build2 inline const names& cast (const value& v) { - // Note that it can still be a typed vector. - // - assert (v && - (v.type == nullptr || v.type == &value_traits::value_type)); + assert (v && v.type == nullptr); return v.as (); } @@ -104,8 +111,7 @@ namespace build2 inline names& cast (value& v) { - assert (v && - (v.type == nullptr || v.type == &value_traits::value_type)); + assert (v && v.type == nullptr); return v.as (); } @@ -230,7 +236,6 @@ namespace build2 v.as () = x; else new (&v.data_) bool (x); - } inline void value_traits:: -- cgit v1.1