From: Roland McGrath Date: Mon, 29 Jun 2009 07:43:09 +0000 (-0700) Subject: Pass collector in constructors down to attr_value level. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25c2399b1a202ffde40310608c3185ccd01b2f24;p=thirdparty%2Felfutils.git Pass collector in constructors down to attr_value level. --- diff --git a/libdw/c++/dwarf_output b/libdw/c++/dwarf_output index bd1b10ee3..882d5cfc7 100644 --- a/libdw/c++/dwarf_output +++ b/libdw/c++/dwarf_output @@ -51,6 +51,7 @@ #define _ELFUTILS_DWARF_OUTPUT 1 #include "dwarf_edit" +#include /* Read the comments for elfutils::dwarf first. @@ -280,17 +281,46 @@ namespace elfutils typedef dwarf_data::dwarf_enum dwarf_enum; typedef dwarf_data::range_list range_list; typedef dwarf_data::location_attr location_attr; - typedef dwarf_data::attr_value attr_value; protected: template static inline const range_list & collect (dwarf_output_collector *, const typename input::range_list &); + template + struct make_any + : public std::binary_function + { + inline typename output::value_type + operator () (const typename input::value_type &x, + dwarf_output_collector *c) + { + return typename output::value_type (x, c); + } + }; + + template + struct make_attribute + : public std::binary_function + { + inline typename output::value_type + operator () (const typename input::value_type &x, + dwarf_output_collector *c) + { + return std::make_pair + (x.first, typename output::value_type::second_type (x.second, c)); + } + }; + /* An iterator adapter for use in iterator-based constructors. collectify (iterator) yields an iterator on input where *i constructs output::value_type (input::value_type v, collector). */ - template + template > struct collectify : public std::unary_function @@ -310,7 +340,7 @@ namespace elfutils inline outlet operator () (const inlet &x) const { - return outlet (x, _m_collector); + return make_outlet () (x, _m_collector); } } _m_maker; @@ -325,7 +355,9 @@ namespace elfutils }; public: + class compile_units; + class attr_value; class debug_info_entry { @@ -337,9 +369,12 @@ namespace elfutils private: children_type () {} - template - children_type (const childrens &other) - : std::list (other.begin (), other.end ()) {} + template + inline children_type (const input &other, dwarf_output_collector *c) + : std::list + (collectify (c) (other.begin ()), + collectify (c) (other.end ())) + {} public: typedef debug_info_entry value_type; @@ -353,9 +388,15 @@ namespace elfutils attributes_type () {} - template - attributes_type (const attrs &other) - : std::map (other.begin (), other.end ()) {} + template + inline attributes_type (const input &other, dwarf_output_collector *c) + : base_type (collectify > (c) + (other.begin ()), + collectify > (c) + (other.end ())) + {} public: typedef base_type::key_type key_type; @@ -377,19 +418,11 @@ namespace elfutils children_type _m_children; public: - explicit debug_info_entry (int t) : _m_tag (t) - { - if (unlikely (t <= 0)) - throw std::invalid_argument ("invalid tag"); - } - - /* The template constructor lets us copy in from any class that has - compatibly iterable containers for attributes and children. */ template - debug_info_entry (const die_type &die) + debug_info_entry (const die_type &die, dwarf_output_collector *c) : _m_tag (die.tag ()), - _m_attributes (die.attributes ()), - _m_children (die.children ()) + _m_attributes (die.attributes (), c), + _m_children (die.children (), c) {} inline int tag () const @@ -449,14 +482,12 @@ namespace elfutils class compile_unit : public debug_info_entry { friend class compile_units; - private: - inline compile_unit () : debug_info_entry (::DW_TAG_compile_unit) {} // XXX should be private public: template compile_unit (const die_type &die, dwarf_output_collector *c) - : debug_info_entry (die) + : debug_info_entry (die, c) { if (die.tag () != ::DW_TAG_compile_unit) throw std::invalid_argument ("not a compile_unit entry"); @@ -506,6 +537,20 @@ namespace elfutils } }; + class attr_value : public dwarf_data::attr_value + { + private: + typedef dwarf_data::attr_value _base; + + public: + template + attr_value (const value &other, dwarf_output_collector *c) + : _base (other) + { + // XXX + } + }; + private: compile_units _m_units;