From fc27ec48c9d63879e4b0f049060e943233cb540d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 17 Oct 2016 15:43:47 +0200 Subject: Cleanup match_result mess --- build2/bin/rule | 8 ++++---- build2/bin/rule.cxx | 30 +++++++++++++++++++----------- 2 files changed, 23 insertions(+), 15 deletions(-) (limited to 'build2/bin') diff --git a/build2/bin/rule b/build2/bin/rule index 9bf1379..4072e4e 100644 --- a/build2/bin/rule +++ b/build2/bin/rule @@ -18,20 +18,20 @@ namespace build2 { public: virtual match_result - match (action, target&, const string& hint) const; + match (action, target&, const string& hint) const override; virtual recipe - apply (action, target&, const match_result&) const; + apply (action, target&) const override; }; class lib_rule: public rule { public: virtual match_result - match (action, target&, const string& hint) const; + match (action, target&, const string& hint) const override; virtual recipe - apply (action, target&, const match_result&) const; + apply (action, target&) const override; static target_state perform (action, target&); diff --git a/build2/bin/rule.cxx b/build2/bin/rule.cxx index 7710a53..3f16d71 100644 --- a/build2/bin/rule.cxx +++ b/build2/bin/rule.cxx @@ -25,17 +25,26 @@ namespace build2 fail << diag_doing (a, t) << " target group" << info << "explicitly select obje{}, obja{}, or objs{} member"; - return nullptr; + return false; } recipe obj_rule:: - apply (action, target&, const match_result&) const {return empty_recipe;} + apply (action, target&) const {return empty_recipe;} // lib // // The whole logic is pretty much as if we had our two group members as // our prerequisites. // + + struct match_data + { + const string& type; + }; + + static_assert (sizeof (match_data) <= target::data_size, + "insufficient space"); + match_result lib_rule:: match (action act, target& xt, const string&) const { @@ -79,7 +88,9 @@ namespace build2 match_only (act, *t.s); } - match_result mr (t, &type); + t.data (match_data {type}); // Save in the target's auxilary storage. + + match_result mr (true); // If there is an outer operation, indicate that we match // unconditionally so that we don't override ourselves. @@ -91,11 +102,12 @@ namespace build2 } recipe lib_rule:: - apply (action act, target& xt, const match_result& mr) const + apply (action act, target& xt) const { lib& t (static_cast (xt)); - const string& type (*static_cast (mr.cpvalue)); + const match_data& md (t.data ()); + const string& type (md.type); bool a (type == "static" || type == "both"); bool s (type == "shared" || type == "both"); @@ -116,12 +128,8 @@ namespace build2 { lib& t (static_cast (xt)); - //@@ Not cool we have to do this again. Looks like we need - // some kind of a cache vs resolved pointer, like in - // prerequisite vs prerequisite_target. - // - // - const string& type (cast (t["bin.lib"])); + const match_data& md (t.data ()); + const string& type (md.type); bool a (type == "static" || type == "both"); bool s (type == "shared" || type == "both"); -- cgit v1.1