aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build2/bin/module.cxx10
-rw-r--r--build2/context.cxx30
-rw-r--r--build2/cxx/module.cxx32
-rw-r--r--build2/scope9
-rw-r--r--build2/target9
-rw-r--r--build2/variable23
6 files changed, 64 insertions, 49 deletions
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<string> ("bin.ar.signature") = move (bi.ar_signature);
+ r.assign<string> ("bin.ar.checksum") = move (bi.ar_checksum);
if (!ranlib.empty ())
{
- r.assign ("bin.ranlib.signature", string_type) =
+ r.assign<string> ("bin.ranlib.signature") =
move (bi.ranlib_signature);
-
- r.assign ("bin.ranlib.checksum", string_type) =
- move (bi.ranlib_checksum);
+ r.assign<string> ("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<dir_path> ("build.work") = work;
+ gs.assign<dir_path> ("build.home") = home;
// @@ Backwards-compatibility hack.
//
- gs.assign ("__build2_greater_than_0_2_0_hack__", bool_type) = true;
+ gs.assign<bool> ("__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<string> ("build.version") = to_string (BUILD2_VERSION);
+ gs.assign<string> ("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<string> ("build.version.release") = comp (1);
+ gs.assign<string> ("build.version.patch") = comp (100);
+ gs.assign<string> ("build.version.minor") = comp (10000);
+ gs.assign<string> ("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<string> ("build.host") = move (canon);
+ gs.assign<string> ("build.host.cpu") = move (t.cpu);
+ gs.assign<string> ("build.host.vendor") = move (t.vendor);
+ gs.assign<string> ("build.host.system") = move (t.system);
+ gs.assign<string> ("build.host.version") = move (t.version);
+ gs.assign<string> ("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<string> ("cxx.id") = ci.id.string ();
+ r.assign<string> ("cxx.id.type") = move (ci.id.type);
+ r.assign<string> ("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<string> ("cxx.version") = ci.version.string ();
+ r.assign<string> ("cxx.version.major") = move (ci.version.major);
+ r.assign<string> ("cxx.version.minor") = move (ci.version.minor);
+ r.assign<string> ("cxx.version.patch") = move (ci.version.patch);
+ r.assign<string> ("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<string> ("cxx.signature") = move (ci.signature);
+ r.assign<string> ("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<string> ("cxx.target") = move (canon);
+ r.assign<string> ("cxx.target.cpu") = move (t.cpu);
+ r.assign<string> ("cxx.target.vendor") = move (t.vendor);
+ r.assign<string> ("cxx.target.system") = move (t.system);
+ r.assign<string> ("cxx.target.version") = move (t.version);
+ r.assign<string> ("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 <typename T>
+ value&
+ assign (const string& name) {return vars.assign<T> (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 <typename T>
+ value&
+ assign (const string& name) {return vars.assign<T> (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 <typename T>
+ 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 <typename T> struct value_traits;
- // Assign value type to the value.
+ // Value cast.
//
- template <typename T>
- void assign (value&, const variable&);
- void assign (value&, const value_type*, const variable&);
-
template <typename T> typename value_traits<T>::type as (value&);
template <typename T> typename value_traits<T>::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<reference_wrapper<value>, bool>
assign (const variable& var)
@@ -781,6 +783,13 @@ namespace build2
return assign (var_pool.find (name, type));
}
+ template <typename T>
+ pair<reference_wrapper<value>, bool>
+ assign (const string& name)
+ {
+ return assign (var_pool.find (name, &value_traits<T>::value_type));
+ }
+
pair<const_iterator, const_iterator>
find_namespace (const string& ns) const
{