]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Add comments to locus.hh, simple_locus helpers now in namespace
authorPetr Machata <pmachata@redhat.com>
Tue, 19 Apr 2011 11:29:03 +0000 (13:29 +0200)
committerPetr Machata <pmachata@redhat.com>
Tue, 19 Apr 2011 11:29:03 +0000 (13:29 +0200)
dwarflint/check_debug_abbrev.cc
dwarflint/check_debug_abbrev.hh
dwarflint/check_debug_aranges.cc
dwarflint/check_debug_aranges.hh
dwarflint/check_debug_line.cc
dwarflint/die_locus.cc
dwarflint/die_locus.hh
dwarflint/locus.cc
dwarflint/locus.hh

index 0b827e717bdd3bc35d4fd51385caa30cadfaa2dd..849e50533f20259cefc70943cca0e16ea520f601 100644 (file)
 #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)
index 3e39fa976b5edf9216137b2e8276f1da4b224dd9..9565f885454ced2ed4057343104f23e2e7e8b1c5 100644 (file)
 #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<sec_abbrev,
-                   abbrev_locus_n::name,
+                   locus_simple_fmt::abbr_offset_n,
                    locus_simple_fmt::hex> abbrev_locus;
 
 class abbrev_attrib_locus
index b43f9bd746dce1d384e4884f08ed2892c092beb7..cc2ce8c8f03013bf087cc1d9475c208e28b4dd90 100644 (file)
 #include "misc.hh"
 #include "pri.hh"
 
+char const *
+locus_simple_fmt::cudie_n ()
+{
+  return "CU DIE";
+}
+
 std::string
 arange_locus::format (bool brief) const
 {
index 5254d846123fc92d668028a176fa36b251904a19..9840245c925da05a3cdf1a22ee9f4d68f880cdd9 100644 (file)
 #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<sec_info,
-                      cudie_locus_n::name,
+                      locus_simple_fmt::cudie_n,
                       locus_simple_fmt::dec>
 {
+  typedef fixed_locus<sec_info,
+                     locus_simple_fmt::cudie_n,
+                     locus_simple_fmt::dec> _super_t;
 public:
   template <class T>
   cudie_locus (T const &die)
-    : fixed_locus<sec_info, cudie_locus_n::name,
-                 locus_simple_fmt::dec> (die.offset ())
+    : _super_t (die.offset ())
   {}
 
   cudie_locus (Dwarf_Off offset)
-    : fixed_locus<sec_info, cudie_locus_n::name,
-                 locus_simple_fmt::dec> (offset)
+    : _super_t (offset)
   {}
 };
 
index 2f896f675decfe34d0339d36e6b7a7ca9b35d12f..57238bc4b90c4bed15a63a3eb522fc1bd0a8824d 100644 (file)
@@ -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<sec_line,
-                     line_table_locus_n::name,
+  typedef fixed_locus<sec_line, table_n,
                      locus_simple_fmt::dec> line_table_locus;
 }
 
index 46458dee5b2539426ff1ac67ee74d95134571090..e27d0e2e6bdba34edbc7e49e700d409b9f57e416 100644 (file)
 #include "die_locus.hh"
 #include "pri.hh"
 
+char const *
+locus_simple_fmt::cu_n ()
+{
+  return "CU";
+}
+
 std::string
 die_locus::format (bool brief) const
 {
index 180423be85c5aa05670a690bcfaef585e91b0d30..9363bc8d713985703c2962b96a1386e65456fec8 100644 (file)
 #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<sec_info,
-                   cu_locus_n::name,
+                   locus_simple_fmt::cu_n,
                    locus_simple_fmt::dec> cu_locus;
 
 class die_locus
index 8109e3c6126a91c2479a140d82ab9b713d8ff2f0..19efd1a61e57203b55f166888f70366a33036c55 100644 (file)
 #include "section_id.hh"
 #include <sstream>
 
+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)
index b3d82f9cda69f4d7ab644e2871529772b3f5e1e1..3a61b9a83a868fea8dce9067b4bb7d9013f9edcf 100644 (file)
 #include <iostream>
 #include <cassert>
 
+/// 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<X>
 template <class T>
 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<char const *(*N) (),
         void (*F) (std::ostream &, uint64_t)>
 class simple_locus
   : public clonable_locus<simple_locus<N, F> >
+  , 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<section_id S,
         char const *(*N) (),
         void (*F) (std::ostream &, uint64_t)>
@@ -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<locus_simple_fmt::offset,
+/// Straightforward locus for cases where either offset is not
+/// necessary at all, or if it is present, it's simply shown as
+/// "offset: 0xf00".
+typedef simple_locus<locus_simple_fmt::offset_n,
                     locus_simple_fmt::hex> section_locus;
 
 inline std::ostream &