From eb000f6aa31f48b36ad2fcd09d14559f43106ca2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 8 Nov 2021 08:16:29 +0200 Subject: Incorporate derived target types into generated header logic --- libbuild2/cc/compile-rule.cxx | 28 +++++++++++++++++++++++++--- libbuild2/target-type.hxx | 15 ++++++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) (limited to 'libbuild2') diff --git a/libbuild2/cc/compile-rule.cxx b/libbuild2/cc/compile-rule.cxx index 62391f3..6258ce8 100644 --- a/libbuild2/cc/compile-rule.cxx +++ b/libbuild2/cc/compile-rule.cxx @@ -1551,12 +1551,12 @@ namespace build2 // Reverse-lookup target type(s) from extension. // small_vector compile_rule:: - map_extension (const scope& s, const string& n, const string& e) const + map_extension (const scope& bs, const string& n, const string& e) const { // We will just have to try all of the possible ones, in the "most // likely to match" order. // - auto test = [&s, &n, &e] (const target_type& tt) -> bool + auto test = [&bs, &n, &e] (const target_type& tt) -> bool { // Call the extension derivation function. Here we know that it will // only use the target type and name from the target key so we can @@ -1566,7 +1566,7 @@ namespace build2 // This is like prerequisite search. // - optional de (tt.default_extension (tk, s, nullptr, true)); + optional de (tt.default_extension (tk, bs, nullptr, true)); return de && *de == e; }; @@ -1577,6 +1577,28 @@ namespace build2 if (test (**p)) r.push_back (*p); + // Next try target types derived from any of the C-source types. + // + const target_type_map& ttm (bs.root_scope ()->root_extra->target_types); + + for (auto i (ttm.type_begin ()), e (ttm.type_end ()); i != e; ++i) + { + const target_type& dt (i->second); + + for (const target_type* const* p (x_inc); *p != nullptr; ++p) + { + const target_type& bt (**p); + + if (dt.is_a (bt)) + { + if (dt != bt && test (dt)) + r.push_back (&dt); + + break; + } + } + } + return r; } diff --git a/libbuild2/target-type.hxx b/libbuild2/target-type.hxx index 5798766..0e24e3a 100644 --- a/libbuild2/target-type.hxx +++ b/libbuild2/target-type.hxx @@ -189,7 +189,7 @@ namespace build2 file_map_.emplace (n, tt); } - private: + public: struct target_type_ref { // Like reference_wrapper except it sometimes deletes the target type. @@ -214,8 +214,17 @@ namespace build2 bool d_; }; - map type_map_; - map> file_map_; + using type_map = map; + using file_map = map>; + + using type_iterator = type_map::const_iterator; + + type_iterator type_begin () const {return type_map_.begin ();} + type_iterator type_end () const {return type_map_.end ();} + + private: + type_map type_map_; + file_map file_map_; }; } -- cgit v1.1