From 9da5febf1d9af9f5cb62d5d35fc87136e6e4cd60 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 11 Apr 2016 09:20:49 +0200 Subject: Add basic support for variable value inheritance Currently, only abs_dir_path inherits from dir_path. --- build2/variable.ixx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'build2/variable.ixx') diff --git a/build2/variable.ixx b/build2/variable.ixx index e52a150..9b29608 100644 --- a/build2/variable.ixx +++ b/build2/variable.ixx @@ -81,17 +81,27 @@ namespace build2 inline const T& cast (const value& v) { - assert (!v.null () && v.type == &value_traits::value_type); + assert (!v.null ()); + + // Find base if any. + // + const value_type* b (v.type); + for (; b != nullptr && b != &value_traits::value_type; b = b->base) ; + assert (b != nullptr); + return *static_cast (v.type->cast == nullptr ? static_cast (&v.data_) - : v.type->cast (v)); + : v.type->cast (v, b)); } template inline T& cast (value& v) { - return const_cast (cast (static_cast (v))); + assert (!v.null () && v.type == &value_traits::value_type); + return *static_cast (v.type->cast == nullptr + ? static_cast (&v.data_) + : const_cast (v.type->cast (v, v.type))); } template -- cgit v1.1