From: Roland McGrath Date: Thu, 2 Jul 2009 05:25:13 +0000 (-0700) Subject: Rejigger dwarf_data constructors. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0bce6cec0568c7aa36c8e5998cb2fd709f3ee1de;p=thirdparty%2Felfutils.git Rejigger dwarf_data constructors. --- diff --git a/libdw/c++/data-values.hh b/libdw/c++/data-values.hh index ec1e5455f..55860f5c5 100644 --- a/libdw/c++/data-values.hh +++ b/libdw/c++/data-values.hh @@ -54,9 +54,9 @@ namespace elfutils { - template + template dwarf::value_space - dwarf_data::attr_value::what_space () const + dwarf_data::attr_value::what_space () const { if (typeid (*_m_value) == typeid (typename v::value_flag)) return dwarf::VS_flag; diff --git a/libdw/c++/dwarf_data b/libdw/c++/dwarf_data index 56e61ed25..423028f2c 100644 --- a/libdw/c++/dwarf_data +++ b/libdw/c++/dwarf_data @@ -651,7 +651,7 @@ namespace elfutils public: struct nothing {}; - template + template struct value { class value_dispatch @@ -660,17 +660,17 @@ namespace elfutils virtual ~value_dispatch () {} }; - template + template static inline value_dispatch * - make (flavor *&result, const input &x, const constructor_arg_type &arg) + make (flavor *&result, const input &x, const arg_type &arg) { return result = new flavor (x, arg); } struct value_string : public value_dispatch, public std::string { - template - inline value_string (const string &s, const constructor_arg_type &arg) + template + inline value_string (const string &s, const arg_type &arg) : std::string (s) {} @@ -685,8 +685,8 @@ namespace elfutils struct value_identifier : public value_string { - template - inline value_identifier (const id &s, const constructor_arg_type &arg) + template + inline value_identifier (const id &s, const arg_type &arg) : value_string (s, arg) {} }; @@ -694,29 +694,32 @@ namespace elfutils struct value_reference : public value_dispatch { typename impl::debug_info_entry::children_type::iterator ref; + + template inline value_reference (const typename impl::debug_info_entry::children_type::iterator &i, - const constructor_arg_type &arg) + const arg_type &arg) : ref (i) {} - template // XXX dummy - value_reference (const iter &i, const constructor_arg_type &arg) + template // XXX dummy + inline value_reference (const iter &i, const arg_type &arg) : ref () {} }; struct value_unit_reference : public value_dispatch { typename impl::compile_units::iterator ref; + + template inline value_unit_reference (const typename impl::compile_units::iterator &i, - const constructor_arg_type &arg) + const arg_type &arg) : ref (i) {} - template // XXX dummy - value_unit_reference (const iter &i, - const constructor_arg_type &arg) + template // XXX dummy + inline value_unit_reference (const iter &i, const arg_type &arg) : ref () {} }; @@ -724,7 +727,9 @@ namespace elfutils struct value_flag : public value_dispatch { bool flag; - inline value_flag (bool t, const constructor_arg_type &arg) + + template + inline value_flag (bool t, const arg_type &arg) : flag (t) {} }; @@ -733,25 +738,25 @@ namespace elfutils { // XXX dwfl, reloc ::Dwarf_Addr addr; - inline value_address (::Dwarf_Addr a, const constructor_arg_type &arg) - : addr (a) + + template + inline value_address (::Dwarf_Addr x, const arg_type &arg) + : addr (x) {} }; struct value_rangelistptr : public value_dispatch, public range_list { - template - inline value_rangelistptr (const list &other, - const constructor_arg_type &arg) + template + inline value_rangelistptr (const list &other, const arg_type &arg) : range_list (other) {} }; struct value_lineptr : public value_dispatch, public impl::line_info_table { - template - inline value_lineptr (const table &other, - const constructor_arg_type &arg) + template + inline value_lineptr (const table &other, const arg_type &arg) : impl::line_info_table (other) {} }; @@ -763,7 +768,9 @@ namespace elfutils ::Dwarf_Word word; ::Dwarf_Sword sword; }; - inline value_constant (::Dwarf_Word x, const constructor_arg_type &arg) + + template + inline value_constant (::Dwarf_Word x, const arg_type &arg) : word (x) {} }; @@ -771,34 +778,34 @@ namespace elfutils struct value_constant_block : public value_dispatch, public std::vector { - template - inline value_constant_block (const block &b, - const constructor_arg_type &arg) + template + inline value_constant_block (const block &b, const arg_type &arg) : std::vector (b.begin (), b.end ()) {} }; struct value_dwarf_constant : public value_dispatch, public dwarf_enum { - template - inline value_dwarf_constant (const constant &other, - const constructor_arg_type &arg) - : dwarf_enum (other) {} + template + inline value_dwarf_constant (const constant &other, const arg_type &arg) + : dwarf_enum (other) + {} }; struct value_source_file : public value_dispatch, public source_file { - template - inline value_source_file (const file &other, - const constructor_arg_type &arg) - : source_file (other) {} + template + inline value_source_file (const file &other, const arg_type &arg) + : source_file (other) + {} }; struct value_source_line : public value_dispatch { unsigned int n; - inline value_source_line (unsigned int m, - const constructor_arg_type &arg) + + template + inline value_source_line (unsigned int m, const arg_type &arg) : n (m) {} }; @@ -808,27 +815,21 @@ namespace elfutils struct value_location : public value_dispatch, public location_attr { - template - inline value_location (const loc &other, - const constructor_arg_type &arg) + template + inline value_location (const loc &other, const arg_type &arg) : location_attr (other) {} }; }; - template - > + template > class attr_value { private: typename vw::value_dispatch *_m_value; - template - inline void init (const value &other, - const constructor_arg_type &arg - = constructor_arg_type ()) + template + inline void init (const value &other, const arg_type &arg) { switch (other.what_space ()) { @@ -885,13 +886,16 @@ namespace elfutils } public: - attr_value (const attr_value &other) : _m_value (NULL) + /* + attr_value (const attr_value &other) + : _m_value (NULL) { init (other); } + */ - template - attr_value (const value &other, const constructor_arg_type &arg) + template + attr_value (const value &other, const arg_type &arg) : _m_value (NULL) { init (other, arg); @@ -1082,110 +1086,24 @@ namespace elfutils } }; - template - struct constructor_arg_adapter - { - template - struct make_any - : public std::binary_function - { - inline typename output::value_type - operator () (const typename input::value_type &x, - const constructor_arg_type &c) const - { - 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, - const constructor_arg_type &c) const - { - 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 > - struct argify - : public std::unary_function - { - typedef typename input::const_iterator inny; - typedef typename output::iterator outty; - typedef typename input::value_type inlet; - typedef typename output::value_type outlet; - - /* Wrapper worker passed to wrapped_input_iterator. - This object holds the collector pointer. */ - struct maker - : public std::unary_function - { - constructor_arg_type _m_arg; - explicit inline maker (const constructor_arg_type &c) : _m_arg (c) {} - - inline outlet operator () (const inlet &x) const - { - return make_outlet () (x, _m_arg); - } - } _m_maker; - - explicit inline argify (const constructor_arg_type &c) - : _m_maker (c) - {} - - typedef subr::wrapped_input_iterator wrapped; - - inline wrapped operator () (const inny &i) - { - return wrapped (i, _m_maker); - } - }; - - template - static inline argify< - input, typename dwarf_output::debug_info_entry::attributes_type, - make_attribute - > attr (const input &, const constructor_arg_type &c) - { - return argify< - input, typename dwarf_output::debug_info_entry::attributes_type, - make_attribute< - input, typename dwarf_output::debug_info_entry::attributes_type> - > (c); - }; - }; - - template > + template > class attributes_type - : public std::map > + : public std::map > { friend class impl::debug_info_entry; private: - typedef std::map > base_type; - typedef constructor_arg_adapter argify; + typedef std::map > base_type; protected: inline attributes_type () {} public: // XXX should be protected - template - inline attributes_type (const input &other, const arg &c) - : base_type (argify::attr (other, c) (other.begin ()), - argify::attr (other, c) (other.end ())) + template + inline attributes_type (const input &other, const arg_type &c) + : base_type (subr::argify2nd + (other.begin (), c), + subr::argify2nd + (other.end (), c)) {} public: @@ -1212,8 +1130,8 @@ namespace elfutils return elfutils::to_string (*this); // Use that. } - template - inline std::string dwarf_data::attr_value::to_string () const + template + inline std::string dwarf_data::attr_value::to_string () const { return elfutils::to_string (*this); // Use that. } diff --git a/libdw/c++/dwarf_edit b/libdw/c++/dwarf_edit index 0d67a3e17..239fb3f76 100644 --- a/libdw/c++/dwarf_edit +++ b/libdw/c++/dwarf_edit @@ -52,6 +52,7 @@ #include "dwarf" #include "dwarf_data" +#include "dwarf_tracker" /* Read the comments for elfutils::dwarf first. @@ -109,9 +110,12 @@ namespace elfutils private: children_type () {} - template - children_type (const childrens &other) - : std::list (other.begin (), other.end ()) {} + template + children_type (const input &other, tracker *t) + : std::list + (subr::argify (other.begin (), t), + subr::argify (other.end (), t)) + {} public: typedef debug_info_entry value_type; @@ -126,9 +130,9 @@ namespace elfutils inline attributes_type () {} - template - inline attributes_type (const attrs &other) - : base_type (other, dwarf_data::nothing ()) + template + inline attributes_type (const attrs &other, tracker *t) + : base_type (other, t) {} }; @@ -146,11 +150,11 @@ namespace elfutils /* 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) + template + debug_info_entry (const die_type &die, tracker *t) : _m_tag (die.tag ()), - _m_attributes (die.attributes ()), - _m_children (die.children ()) + _m_attributes (die.attributes (), t), + _m_children (die.children (), t) {} inline int tag () const @@ -215,8 +219,9 @@ namespace elfutils // XXX should be private public: - template - compile_unit (const die_type &die) : debug_info_entry (die) + template + inline compile_unit (const die_type &die, tracker *t) + : debug_info_entry (die, t) { if (die.tag () != ::DW_TAG_compile_unit) throw std::invalid_argument ("not a compile_unit entry"); @@ -236,12 +241,17 @@ namespace elfutils typedef std::list _base; // Default constructor: an empty container, no CUs. - inline compile_units () {} + inline compile_units () + {} // Constructor copying CUs from input container. - template - compile_units(const input &units) - : _base (units.begin (), units.end ()) {} + template + inline compile_units (const input &units, tracker *t) + : _base (subr::argify + (units.begin (), t), + subr::argify + (units.end (), t)) + {} public: typedef compile_unit value_type; @@ -285,8 +295,10 @@ namespace elfutils inline dwarf_edit () {} // Constructor copying CUs from an input file (dwarf or dwarf_edit). - template - dwarf_edit (const input &dw) : _m_units (dw.compile_units ()) {} + template + dwarf_edit (const input &dw, tracker *t) + : _m_units (dw.compile_units (), t) + {} template inline bool operator== (const file &other) const diff --git a/libdw/c++/dwarf_output b/libdw/c++/dwarf_output index 65bff72f7..255afa27c 100644 --- a/libdw/c++/dwarf_output +++ b/libdw/c++/dwarf_output @@ -291,19 +291,20 @@ namespace elfutils static inline const std::string & collect_string (dwarf_output_collector *, const input &); - template - static inline const range_list & - collect (dwarf_output_collector *, const typename input::range_list &); - /* 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). */ - typedef dwarf_data::constructor_arg_adapter - collectify; + template + static inline typename subr::argifier::wrapped + collectify (const typename input::const_iterator &in, + dwarf_output_collector *c) + { + return subr::argifier (c) (in); + } struct value_wrapper - : public dwarf_data::value + : public dwarf_data::value { struct value_string : public value_dispatch { @@ -331,9 +332,7 @@ namespace elfutils public: - typedef dwarf_data::attr_value attr_value; + typedef dwarf_data::attr_value attr_value; class compile_units; @@ -350,8 +349,8 @@ namespace elfutils template inline children_type (const input &other, dwarf_output_collector *c) : std::list - (collectify::argify (c) (other.begin ()), - collectify::argify (c) (other.end ())) + (collectify (other.begin (), c), + collectify (other.end (), c)) {} public: @@ -478,8 +477,8 @@ namespace elfutils // Constructor copying CUs from input container. template compile_units (const input &units, dwarf_output_collector *c) - : _base (collectify::argify (c) (units.begin ()), - collectify::argify (c) (units.end ())) + : _base (collectify (units.begin (), c), + collectify (units.end (), c)) { } @@ -563,14 +562,6 @@ namespace elfutils return c->_m_strings.add (s); } - template - inline const dwarf_output::range_list & - dwarf_output::collect (dwarf_output_collector *c, - const typename input::range_list &rl) - { - return c->_m_ranges.add (rl); - } - }; #endif // diff --git a/libdw/c++/subr.hh b/libdw/c++/subr.hh index 4a90e50ce..7a799eeb8 100644 --- a/libdw/c++/subr.hh +++ b/libdw/c++/subr.hh @@ -603,6 +603,98 @@ namespace elfutils return (*_m_wrapper) (_base::operator* ()); } }; + + /* 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 + struct argifier + : public std::unary_function + { + typedef typename input::const_iterator inny; + typedef typename output::iterator outty; + typedef typename input::value_type inlet; + typedef typename output::value_type outlet; + + /* Wrapper worker passed to wrapped_input_iterator. + This object holds the collector pointer. */ + struct maker + : public std::unary_function + { + arg_type _m_arg; + explicit inline maker (const arg_type &c) : _m_arg (c) {} + + inline outlet operator () (const inlet &x) const + { + return outlet (x, _m_arg); + } + } _m_maker; + + explicit inline argifier (const arg_type &c) + : _m_maker (c) + {} + + typedef subr::wrapped_input_iterator wrapped; + + inline wrapped operator () (const inny &i) + { + return wrapped (i, _m_maker); + } + }; + + template + static inline typename argifier::wrapped + argify (const typename input::const_iterator &in, const arg_type &arg) + { + return argifier (arg) (in); + } + + template + struct argifier2nd + : public std::unary_function + { + typedef typename input::const_iterator inny; + typedef typename output::iterator outty; + typedef typename input::value_type inlet; + typedef typename output::value_type outlet; + + /* Wrapper worker passed to wrapped_input_iterator. + This object holds the collector pointer. */ + struct maker + : public std::unary_function + { + arg_type _m_arg; + explicit inline maker (const arg_type &c) : _m_arg (c) {} + + inline outlet operator () (const inlet &x) const + { + return std::make_pair (x.first, + typename outlet::second_type (x.second, + _m_arg)); + } + } _m_maker; + + explicit inline argifier2nd (const arg_type &c) + : _m_maker (c) + {} + + typedef subr::wrapped_input_iterator wrapped; + + inline wrapped operator () (const inny &i) + { + return wrapped (i, _m_maker); + } + }; + + template + static inline typename argifier2nd::wrapped + argify2nd (const typename input::const_iterator &in, const arg_type &arg) + { + return argifier2nd (arg) (in); + } + }; }; diff --git a/src/dwarfcmp.cc b/src/dwarfcmp.cc index e29d2d8c1..677a5beba 100644 --- a/src/dwarfcmp.cc +++ b/src/dwarfcmp.cc @@ -325,8 +325,10 @@ main (int argc, char *argv[]) if (test_writer) { - dwarf_edit edit1 (file1); - dwarf_edit edit2 (file2); + dwarf_ref_tracker t1; + dwarf_ref_tracker t2; + dwarf_edit edit1 (file1, &t1); + dwarf_edit edit2 (file2, &t2); test_classes (file1, file2, edit1, edit2, same); {