diff options
Diffstat (limited to 'libbuild2/target-type.hxx')
-rw-r--r-- | libbuild2/target-type.hxx | 79 |
1 files changed, 69 insertions, 10 deletions
diff --git a/libbuild2/target-type.hxx b/libbuild2/target-type.hxx index 5798766..a0fc5a2 100644 --- a/libbuild2/target-type.hxx +++ b/libbuild2/target-type.hxx @@ -89,11 +89,34 @@ namespace build2 const location&, bool reverse); - void (*print) (ostream&, const target_key&); + // See to_stream(ostream,target_key) for details. + // + bool (*print) (ostream&, const target_key&, bool name_only); const target* (*search) (const target&, const prerequisite_key&); - bool see_through; // A group with the default "see through" semantics. + // Target type flags. + // + // Note that the member_hint flag should only be used on groups with + // link-up during load (see lib{}, for example). In particular, if the + // group link-up only happens during match, then the hint would be looked + // up before the group is known. + // + // Note: consider exposing as an attribute in define if adding a new flag. + // + enum class flag: uint64_t + { + none = 0, + group = 0x01, // A (non-adhoc) group. + see_through = group | 0x02, // A group with "see through" semantics. + member_hint = group | 0x04, // Untyped rule hint applies to members. + dyn_members = group | 0x08 // A group with dynamic members. + }; + + flag flags; + + bool + see_through () const; template <typename T> bool @@ -102,14 +125,15 @@ namespace build2 bool is_a (const target_type& tt) const { - return this == &tt || (base != nullptr && is_a_base (tt)); + for (const target_type* b (this); b != nullptr; b = b->base) + if (b == &tt) + return true; + + return false; } bool is_a (const char*) const; // Defined in target.cxx - - bool - is_a_base (const target_type&) const; // Defined in target.cxx }; inline bool @@ -124,6 +148,32 @@ namespace build2 inline ostream& operator<< (ostream& os, const target_type& tt) {return os << tt.name;} + inline target_type::flag + operator&= (target_type::flag& x, target_type::flag y) + { + return x = static_cast<target_type::flag> ( + static_cast<uint64_t> (x) & static_cast<uint64_t> (y)); + } + + inline target_type::flag + operator|= (target_type::flag& x, target_type::flag y) + { + return x = static_cast<target_type::flag> ( + static_cast<uint64_t> (x) | static_cast<uint64_t> (y)); + } + + inline target_type::flag + operator& (target_type::flag x, target_type::flag y) {return x &= y;} + + inline target_type::flag + operator| (target_type::flag x, target_type::flag y) {return x |= y;} + + inline bool target_type:: + see_through () const + { + return (flags & flag::see_through) == flag::see_through; + } + // Target type map. // class target_type_map @@ -189,7 +239,7 @@ namespace build2 file_map_.emplace (n, tt); } - private: + public: struct target_type_ref { // Like reference_wrapper except it sometimes deletes the target type. @@ -201,7 +251,7 @@ namespace build2 target_type_ref (unique_ptr<target_type>&& p) : p_ (p.release ()), d_ (true) {} - target_type_ref (target_type_ref&& r) + target_type_ref (target_type_ref&& r) noexcept : p_ (r.p_), d_ (r.d_) {r.p_ = nullptr;} ~target_type_ref () {if (p_ != nullptr && d_) delete p_;} @@ -214,8 +264,17 @@ namespace build2 bool d_; }; - map<string, target_type_ref> type_map_; - map<string, reference_wrapper<const target_type>> file_map_; + using type_map = map<string, target_type_ref>; + using file_map = map<string, reference_wrapper<const target_type>>; + + 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_; }; } |