diff options
-rw-r--r-- | build2/bin/target | 14 | ||||
-rw-r--r-- | build2/cc/utility.cxx | 4 | ||||
-rw-r--r-- | build2/cli/rule.cxx | 2 | ||||
-rw-r--r-- | build2/cli/target | 39 | ||||
-rw-r--r-- | build2/cli/target.cxx | 9 | ||||
-rw-r--r-- | build2/target | 18 | ||||
-rw-r--r-- | build2/target.cxx | 2 | ||||
-rw-r--r-- | old-tests/cli/lib/libtest/test/buildfile | 4 | ||||
-rw-r--r-- | old-tests/cli/lib/test/buildfile | 2 | ||||
-rw-r--r-- | old-tests/cli/simple/buildfile | 2 |
10 files changed, 43 insertions, 53 deletions
diff --git a/build2/bin/target b/build2/bin/target index 85a84df..0108f09 100644 --- a/build2/bin/target +++ b/build2/bin/target @@ -51,9 +51,11 @@ namespace build2 public: using target::target; - obje* e {nullptr}; - obja* a {nullptr}; - objs* s {nullptr}; + // Group members. + // + const_ptr<obje> e = nullptr; + const_ptr<obja> a = nullptr; + const_ptr<objs> s = nullptr; public: static const target_type static_type; @@ -87,8 +89,10 @@ namespace build2 public: using target::target; - liba* a {nullptr}; - libs* s {nullptr}; + // Group members. + // + const_ptr<liba> a = nullptr; + const_ptr<libs> s = nullptr; virtual void reset (action_type) override; diff --git a/build2/cc/utility.cxx b/build2/cc/utility.cxx index 4ccdcaf..62febfa 100644 --- a/build2/cc/utility.cxx +++ b/build2/cc/utility.cxx @@ -62,10 +62,8 @@ namespace build2 } } - target* r (ls ? static_cast<target*> (l.s) : l.a); - + const target* r (ls ? static_cast<const target*> (l.s) : l.a); assert (r != nullptr); - return *r; } diff --git a/build2/cli/rule.cxx b/build2/cli/rule.cxx index 7928c5c..ba4963e 100644 --- a/build2/cli/rule.cxx +++ b/build2/cli/rule.cxx @@ -207,7 +207,7 @@ namespace build2 static void append_extension (cstrings& args, - path_target& t, + const path_target& t, const char* option, const char* default_extension) { diff --git a/build2/cli/target b/build2/cli/target index f4ab7e7..c10e4b8 100644 --- a/build2/cli/target +++ b/build2/cli/target @@ -26,37 +26,22 @@ namespace build2 virtual const target_type& dynamic_type () const {return static_type;} }; - class cli_cxx: public mtime_target + // Standard layout type compatible with target*[3]. + // + struct cli_cxx_members { - public: - union - { - // It is theoretically possible that the compiler will add - // padding between the members of this struct. This would - // mean that the optimal alignment for a pointer is greater - // than its size (and that an array of pointers is sub- - // optimally aligned). We will deal with such a beast of - // an architecture when we see it. - // - struct - { - cxx::hxx* h; - cxx::cxx* c; - cxx::ixx* i; - }; - target* m[3] /*= {nullptr, nullptr, nullptr}*/; // @@ GCC 4.8 - }; - - //using mtime_target::mtime_target; // @@ GCC 4.8 + const_ptr<cxx::hxx> h = nullptr; + const_ptr<cxx::cxx> c = nullptr; + const_ptr<cxx::ixx> i = nullptr; + }; - cli_cxx (dir_path d, dir_path o, string n) - : mtime_target (move (d), move (o), move (n)) - { - m[0] = m[1] = m[2] = nullptr; - } + class cli_cxx: public mtime_target, public cli_cxx_members + { + public: + using mtime_target::mtime_target; virtual group_view - group_members (action_type) const; + group_members (action_type); virtual timestamp load_mtime () const; diff --git a/build2/cli/target.cxx b/build2/cli/target.cxx index 48dc95b..200f6f0 100644 --- a/build2/cli/target.cxx +++ b/build2/cli/target.cxx @@ -32,10 +32,15 @@ namespace build2 // cli.cxx // group_view cli_cxx:: - group_members (action_type) const + group_members (action_type) { + static_assert (offsetof (cli_cxx_members, i) - + offsetof (cli_cxx_members, h) == sizeof (target*) * 2, + "member layout incompatible with array"); + return h != nullptr - ? group_view {m, (i != nullptr ? 3U : 2U)} + ? group_view {reinterpret_cast<target* const*> (&h), + (i != nullptr ? 3U : 2U)} : group_view {nullptr, 0}; } diff --git a/build2/target b/build2/target index 90aaeec..6cc492a 100644 --- a/build2/target +++ b/build2/target @@ -250,7 +250,7 @@ namespace build2 // resolve_group_members() from <build2/algorithm>. // virtual group_view - group_members (action_type) const; + group_members (action_type); // Note that the returned key "tracks" the target (except for the // extension). @@ -475,9 +475,11 @@ namespace build2 // // Currenly the data is not destroyed until the next match. // - static constexpr size_t data_size = sizeof (string) * 4; - std::aligned_storage<data_size>::type data_pad; - void (*data_dtor) (void*) = nullptr; + // Note that the recipe may modify (mutable) the data. + // + static constexpr size_t data_size = sizeof (string) * 4; + mutable std::aligned_storage<data_size>::type data_pad; + mutable void (*data_dtor) (void*) = nullptr; template <typename R, typename T = typename std::remove_cv< @@ -503,14 +505,10 @@ namespace build2 template <typename T> T& - data () {return *reinterpret_cast<T*> (&data_pad);} - - template <typename T> - const T& - data () const {return *reinterpret_cast<const T*> (&data_pad);} + data () const {return *reinterpret_cast<T*> (&data_pad);} void - clear_data () + clear_data () const { if (data_dtor != nullptr) { diff --git a/build2/target.cxx b/build2/target.cxx index ad448cb..b22dfce 100644 --- a/build2/target.cxx +++ b/build2/target.cxx @@ -139,7 +139,7 @@ namespace build2 } group_view target:: - group_members (action_type) const + group_members (action_type) { assert (false); // Not a group or doesn't expose its members. return group_view {nullptr, 0}; diff --git a/old-tests/cli/lib/libtest/test/buildfile b/old-tests/cli/lib/libtest/test/buildfile index 6b0d9bd..a7667e6 100644 --- a/old-tests/cli/lib/libtest/test/buildfile +++ b/old-tests/cli/lib/libtest/test/buildfile @@ -13,8 +13,8 @@ extra/: --cli-namespace test::extra::cli } -cxx.poptions += -I$out_root -I$src_root -lib{test}: cxx.export.poptions = -I$out_root -I$src_root +cxx.poptions += "-I$out_root" "-I$src_root" +lib{test}: cxx.export.poptions = "-I$out_root" "-I$src_root" cli.options += --include-prefix test --guard-prefix TEST \ --cli-namespace test::cli diff --git a/old-tests/cli/lib/test/buildfile b/old-tests/cli/lib/test/buildfile index d3e784d..1f3d65c 100644 --- a/old-tests/cli/lib/test/buildfile +++ b/old-tests/cli/lib/test/buildfile @@ -3,4 +3,4 @@ import libs += cli-lib-libtest%lib{test} exe{driver}: cxx{driver} cli.cxx{test} $libs cli.cxx{test}: cli{test} -cxx.poptions += -I$out_root +cxx.poptions += "-I$out_root" diff --git a/old-tests/cli/simple/buildfile b/old-tests/cli/simple/buildfile index 47e06d9..ddbf27c 100644 --- a/old-tests/cli/simple/buildfile +++ b/old-tests/cli/simple/buildfile @@ -4,7 +4,7 @@ hxx{*}: extension = cxx{*}: extension = cpp ixx{*}: extension = ipp -cxx.poptions += -I$out_root +cxx.poptions += "-I$out_root" using cli |