From 20677fb264e743b8e5423af31a7d8dc06cf509f6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 16 Mar 2016 15:27:12 +0200 Subject: Cleanup typed variable assignment --- build2/bin/module.cxx | 10 ++++------ build2/context.cxx | 30 +++++++++++++++--------------- build2/cxx/module.cxx | 32 ++++++++++++++++---------------- build2/scope | 9 +++++---- build2/target | 9 ++++++++- build2/variable | 23 ++++++++++++++++------- 6 files changed, 64 insertions(+), 49 deletions(-) (limited to 'build2') diff --git a/build2/bin/module.cxx b/build2/bin/module.cxx index 2b89eeb..eb4d771 100644 --- a/build2/bin/module.cxx +++ b/build2/bin/module.cxx @@ -194,16 +194,14 @@ namespace build2 } } - r.assign ("bin.ar.signature", string_type) = move (bi.ar_signature); - r.assign ("bin.ar.checksum", string_type) = move (bi.ar_checksum); + r.assign ("bin.ar.signature") = move (bi.ar_signature); + r.assign ("bin.ar.checksum") = move (bi.ar_checksum); if (!ranlib.empty ()) { - r.assign ("bin.ranlib.signature", string_type) = + r.assign ("bin.ranlib.signature") = move (bi.ranlib_signature); - - r.assign ("bin.ranlib.checksum", string_type) = - move (bi.ranlib_checksum); + r.assign ("bin.ranlib.checksum") = move (bi.ranlib_checksum); } } diff --git a/build2/context.cxx b/build2/context.cxx index 746592d..49edc1c 100644 --- a/build2/context.cxx +++ b/build2/context.cxx @@ -87,20 +87,20 @@ namespace build2 scope& gs (*global_scope); - gs.assign ("build.work", dir_path_type) = work; - gs.assign ("build.home", dir_path_type) = home; + gs.assign ("build.work") = work; + gs.assign ("build.home") = home; // @@ Backwards-compatibility hack. // - gs.assign ("__build2_greater_than_0_2_0_hack__", bool_type) = true; + gs.assign ("__build2_greater_than_0_2_0_hack__") = true; // Enter the version. // // @@ VAR types // { - gs.assign ("build.version", string_type) = to_string (BUILD2_VERSION); - gs.assign ("build.version.string", string_type) = BUILD2_VERSION_STR; + gs.assign ("build.version") = to_string (BUILD2_VERSION); + gs.assign ("build.version.string") = BUILD2_VERSION_STR; // AABBCCDD // @@ -109,10 +109,10 @@ namespace build2 return to_string ((BUILD2_VERSION / d)% 100); }; - gs.assign ("build.version.release", string_type) = comp (1); - gs.assign ("build.version.patch", string_type) = comp (100); - gs.assign ("build.version.minor", string_type) = comp (10000); - gs.assign ("build.version.major", string_type) = comp (1000000); + gs.assign ("build.version.release") = comp (1); + gs.assign ("build.version.patch") = comp (100); + gs.assign ("build.version.minor") = comp (10000); + gs.assign ("build.version.major") = comp (1000000); } // Enter the host information. Rather than jumping through hoops like @@ -145,12 +145,12 @@ namespace build2 // Enter as build.host.{cpu,vendor,system,version,class}. // - gs.assign ("build.host", string_type) = move (canon); - gs.assign ("build.host.cpu", string_type) = move (t.cpu); - gs.assign ("build.host.vendor", string_type) = move (t.vendor); - gs.assign ("build.host.system", string_type) = move (t.system); - gs.assign ("build.host.version", string_type) = move (t.version); - gs.assign ("build.host.class", string_type) = move (t.class_); + gs.assign ("build.host") = move (canon); + gs.assign ("build.host.cpu") = move (t.cpu); + gs.assign ("build.host.vendor") = move (t.vendor); + gs.assign ("build.host.system") = move (t.system); + gs.assign ("build.host.version") = move (t.version); + gs.assign ("build.host.class") = move (t.class_); } catch (const invalid_argument& e) { diff --git a/build2/cxx/module.cxx b/build2/cxx/module.cxx index 32f811a..9baccae 100644 --- a/build2/cxx/module.cxx +++ b/build2/cxx/module.cxx @@ -197,18 +197,18 @@ namespace build2 << " target " << ci.target; } - r.assign ("cxx.id", string_type) = ci.id.string (); - r.assign ("cxx.id.type", string_type) = move (ci.id.type); - r.assign ("cxx.id.variant", string_type) = move (ci.id.variant); + r.assign ("cxx.id") = ci.id.string (); + r.assign ("cxx.id.type") = move (ci.id.type); + r.assign ("cxx.id.variant") = move (ci.id.variant); - r.assign ("cxx.version", string_type) = ci.version.string (); - r.assign ("cxx.version.major", string_type) = move (ci.version.major); - r.assign ("cxx.version.minor", string_type) = move (ci.version.minor); - r.assign ("cxx.version.patch", string_type) = move (ci.version.patch); - r.assign ("cxx.version.build", string_type) = move (ci.version.build); + r.assign ("cxx.version") = ci.version.string (); + r.assign ("cxx.version.major") = move (ci.version.major); + r.assign ("cxx.version.minor") = move (ci.version.minor); + r.assign ("cxx.version.patch") = move (ci.version.patch); + r.assign ("cxx.version.build") = move (ci.version.build); - r.assign ("cxx.signature", string_type) = move (ci.signature); - r.assign ("cxx.checksum", string_type) = move (ci.checksum); + r.assign ("cxx.signature") = move (ci.signature); + r.assign ("cxx.checksum") = move (ci.checksum); // Split/canonicalize the target. // @@ -233,12 +233,12 @@ namespace build2 // Enter as cxx.target.{cpu,vendor,system,version,class}. // - r.assign ("cxx.target", string_type) = move (canon); - r.assign ("cxx.target.cpu", string_type) = move (t.cpu); - r.assign ("cxx.target.vendor", string_type) = move (t.vendor); - r.assign ("cxx.target.system", string_type) = move (t.system); - r.assign ("cxx.target.version", string_type) = move (t.version); - r.assign ("cxx.target.class", string_type) = move (t.class_); + r.assign ("cxx.target") = move (canon); + r.assign ("cxx.target.cpu") = move (t.cpu); + r.assign ("cxx.target.vendor") = move (t.vendor); + r.assign ("cxx.target.system") = move (t.system); + r.assign ("cxx.target.version") = move (t.version); + r.assign ("cxx.target.class") = move (t.class_); } catch (const invalid_argument& e) { diff --git a/build2/scope b/build2/scope index 158f967..e92361d 100644 --- a/build2/scope +++ b/build2/scope @@ -146,6 +146,10 @@ namespace build2 return vars.assign (name, type).first.get (); } + template + value& + assign (const string& name) {return vars.assign (name).first.get ();} + // Return a value suitable for appending. If the variable does not // exist in this scope's map, then outer scopes are searched for // the same variable. If found then a new variable with the found @@ -156,10 +160,7 @@ namespace build2 append (const variable&); value& - append (const string& name) - { - return append (var_pool.find (name)); - } + append (const string& name) {return append (var_pool.find (name));} // Target type/pattern-specific variables. // diff --git a/build2/target b/build2/target index b5e7ee9..cdf6037 100644 --- a/build2/target +++ b/build2/target @@ -292,7 +292,14 @@ namespace build2 assign (const variable& var) {return vars.assign (var).first;} value& - assign (const string& name) {return vars.assign (name).first;} + assign (const string& name, const build2::value_type* type = nullptr) + { + return vars.assign (name, type).first; + } + + template + value& + assign (const string& name) {return vars.assign (name).first.get ();} // Return a value suitable for appending. See class scope for // details. diff --git a/build2/variable b/build2/variable index 0c945c7..1a52566 100644 --- a/build2/variable +++ b/build2/variable @@ -161,6 +161,12 @@ namespace build2 inline bool operator!= (const value& x, const value& y) {return !(x == y);} + // Assign value type to the value. This triggers the assign callback. + // + template + void assign (value&, const variable&); + void assign (value&, const value_type*, const variable&); + // lookup // // A variable can be undefined, NULL, or contain a (potentially @@ -203,12 +209,8 @@ namespace build2 // template struct value_traits; - // Assign value type to the value. + // Value cast. // - template - void assign (value&, const variable&); - void assign (value&, const value_type*, const variable&); - template typename value_traits::type as (value&); template typename value_traits::const_type as (const value&); @@ -758,8 +760,8 @@ namespace build2 return operator[] (var_pool.find (name)); } - // The second member in the pair indicates whether the new - // value (which will be NULL) was assigned. + // The second member in the pair indicates whether the new value (which + // will be NULL) was assigned. // pair, bool> assign (const variable& var) @@ -781,6 +783,13 @@ namespace build2 return assign (var_pool.find (name, type)); } + template + pair, bool> + assign (const string& name) + { + return assign (var_pool.find (name, &value_traits::value_type)); + } + pair find_namespace (const string& ns) const { -- cgit v1.1