From: Petr Machata Date: Tue, 19 Apr 2011 11:29:03 +0000 (+0200) Subject: dwarflint: Add comments to locus.hh, simple_locus helpers now in namespace X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3ff1c04ed82c2ced1ed7ad51666bbddc0bd70a8f;p=thirdparty%2Felfutils.git dwarflint: Add comments to locus.hh, simple_locus helpers now in namespace --- diff --git a/dwarflint/check_debug_abbrev.cc b/dwarflint/check_debug_abbrev.cc index 0b827e717..849e50533 100644 --- a/dwarflint/check_debug_abbrev.cc +++ b/dwarflint/check_debug_abbrev.cc @@ -43,6 +43,12 @@ #include "messages.hh" #include "misc.hh" +char const * +locus_simple_fmt::abbr_offset_n () +{ + return "abbr. offset"; +} + abbrev_attrib_locus::abbrev_attrib_locus (uint64_t abbr_offset, uint64_t attr_offset, int a_name) diff --git a/dwarflint/check_debug_abbrev.hh b/dwarflint/check_debug_abbrev.hh index 3e39fa976..9565f8854 100644 --- a/dwarflint/check_debug_abbrev.hh +++ b/dwarflint/check_debug_abbrev.hh @@ -31,12 +31,13 @@ #include "check_debug_info_i.hh" #include "dwarf_version_i.hh" -struct abbrev_locus_n { - static char const *name () { return "abbr. offset"; } -}; +namespace locus_simple_fmt +{ + char const *abbr_offset_n (); +} typedef fixed_locus abbrev_locus; class abbrev_attrib_locus diff --git a/dwarflint/check_debug_aranges.cc b/dwarflint/check_debug_aranges.cc index b43f9bd74..cc2ce8c8f 100644 --- a/dwarflint/check_debug_aranges.cc +++ b/dwarflint/check_debug_aranges.cc @@ -42,6 +42,12 @@ #include "misc.hh" #include "pri.hh" +char const * +locus_simple_fmt::cudie_n () +{ + return "CU DIE"; +} + std::string arange_locus::format (bool brief) const { diff --git a/dwarflint/check_debug_aranges.hh b/dwarflint/check_debug_aranges.hh index 5254d8461..9840245c9 100644 --- a/dwarflint/check_debug_aranges.hh +++ b/dwarflint/check_debug_aranges.hh @@ -31,25 +31,27 @@ #include "check_debug_info_i.hh" #include "cu_coverage_i.hh" -struct cudie_locus_n { - static char const *name () { return "CU DIE"; } +namespace locus_simple_fmt +{ + char const *cudie_n (); }; class cudie_locus : public fixed_locus { + typedef fixed_locus _super_t; public: template cudie_locus (T const &die) - : fixed_locus (die.offset ()) + : _super_t (die.offset ()) {} cudie_locus (Dwarf_Off offset) - : fixed_locus (offset) + : _super_t (offset) {} }; diff --git a/dwarflint/check_debug_line.cc b/dwarflint/check_debug_line.cc index 2f896f675..57238bc4b 100644 --- a/dwarflint/check_debug_line.cc +++ b/dwarflint/check_debug_line.cc @@ -149,12 +149,13 @@ namespace namespace { - struct line_table_locus_n { - static char const *name () { return "table"; } - }; + char const * + table_n () + { + return "table"; + } - typedef fixed_locus line_table_locus; } diff --git a/dwarflint/die_locus.cc b/dwarflint/die_locus.cc index 46458dee5..e27d0e2e6 100644 --- a/dwarflint/die_locus.cc +++ b/dwarflint/die_locus.cc @@ -30,6 +30,12 @@ #include "die_locus.hh" #include "pri.hh" +char const * +locus_simple_fmt::cu_n () +{ + return "CU"; +} + std::string die_locus::format (bool brief) const { diff --git a/dwarflint/die_locus.hh b/dwarflint/die_locus.hh index 180423be8..9363bc8d7 100644 --- a/dwarflint/die_locus.hh +++ b/dwarflint/die_locus.hh @@ -29,12 +29,13 @@ #include "locus.hh" #include "../libdw/c++/dwarf" -struct cu_locus_n { - static char const *name () { return "CU"; } +namespace locus_simple_fmt +{ + char const *cu_n (); }; typedef fixed_locus cu_locus; class die_locus diff --git a/dwarflint/locus.cc b/dwarflint/locus.cc index 8109e3c61..19efd1a61 100644 --- a/dwarflint/locus.cc +++ b/dwarflint/locus.cc @@ -27,12 +27,28 @@ #include "section_id.hh" #include +char const * +locus_simple_fmt::offset_n () +{ + return "offset"; +} + +void +locus_simple_fmt::hex (std::ostream &ss, uint64_t off) +{ + ss << "0x" << std::hex << off; +} + +void +locus_simple_fmt::dec (std::ostream &ss, uint64_t off) +{ + ss << std::dec << off; +} + std::string -format_simple_locus (char const *(*N) (), - void (*F) (std::ostream &, uint64_t), - bool brief, - section_id sec, - uint64_t off) +simple_locus_aux::format_simple_locus (char const *(*N) (), + void (*F) (std::ostream &, uint64_t), + bool brief, section_id sec, uint64_t off) { std::stringstream ss; if (!brief) diff --git a/dwarflint/locus.hh b/dwarflint/locus.hh index b3d82f9cd..3a61b9a83 100644 --- a/dwarflint/locus.hh +++ b/dwarflint/locus.hh @@ -34,6 +34,11 @@ #include #include +/// Instances of the locus subclasses are used as pointers into +/// debuginfo for documentation purposes (messages and errors). They +/// are usually tiny structures, and should be used as values, but we +/// need the abstract interface to be able to format them, and copy +/// them into ref_record. class locus { public: @@ -42,6 +47,9 @@ public: virtual ~locus () {} }; +/// This is to simplify creation of subclasses. Most locus subclasses +/// should in fact inherit from this using CRTP: +/// class X: public clonable_locus template class clonable_locus : public locus @@ -53,16 +61,26 @@ public: } }; -std::string format_simple_locus (char const *(*N) (), - void (*F) (std::ostream &, uint64_t), - bool brief, - section_id sec, - uint64_t off); +/// Helper class for simple_locus to reduce the template bloat. +class simple_locus_aux +{ +protected: + static std::string format_simple_locus (char const *(*N) (), + void (*F) (std::ostream &, uint64_t), + bool brief, section_id sec, + uint64_t off); +}; +/// Template for quick construction of straightforward locus +/// subclasses (one address, one way of formatting). N should be a +/// function that returns the name of the argument. +/// locus_simple_fmt::hex, locus_simple_fmt::dec would be candidate +/// parameters for argument F. template class simple_locus : public clonable_locus > + , private simple_locus_aux { section_id _m_sec; uint64_t _m_offset; @@ -73,12 +91,14 @@ public: , _m_offset (offset) {} - std::string format (bool brief = false) const + std::string + format (bool brief = false) const { return format_simple_locus (N, F, brief, _m_sec, _m_offset); } }; +/// Constructor of simple_locus that fixes the section_id argument. template @@ -91,17 +111,17 @@ public: {} }; -struct locus_simple_fmt { - static char const *offset () { return "offset"; } +namespace locus_simple_fmt +{ + char const *offset_n (); + void hex (std::ostream &ss, uint64_t off); + void dec (std::ostream &ss, uint64_t off); +} - static void hex (std::ostream &ss, uint64_t off) { - ss << "0x" << std::hex << off; - } - static void dec (std::ostream &ss, uint64_t off) { - ss << std::dec << off; - } -}; -typedef simple_locus section_locus; inline std::ostream &