]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Add clonable_locus template for easier implementation of loci
authorPetr Machata <pmachata@redhat.com>
Mon, 18 Apr 2011 11:29:02 +0000 (13:29 +0200)
committerPetr Machata <pmachata@redhat.com>
Mon, 18 Apr 2011 11:29:02 +0000 (13:29 +0200)
dwarflint/check_debug_abbrev.cc
dwarflint/check_debug_abbrev.hh
dwarflint/check_debug_aranges.cc
dwarflint/check_debug_loc_range.cc
dwarflint/reloc.cc
dwarflint/where.h

index 3c18d619d657c22f047a63bf99e9129d611d86f9..5e03116085ec3f3efdd66188eaa2931b83168690 100644 (file)
@@ -62,12 +62,6 @@ abbrev_locus::format (bool brief) const
   return ss.str ();
 }
 
-locus *
-abbrev_locus::clone () const
-{
-  return new abbrev_locus (*this);
-}
-
 abbrev_attrib_locus::abbrev_attrib_locus (uint64_t abbr_offset,
                                          uint64_t attr_offset,
                                          int a_name)
@@ -114,12 +108,6 @@ abbrev_attrib_locus::format (bool brief) const
   return ss.str ();
 }
 
-locus *
-abbrev_attrib_locus::clone () const
-{
-  return new abbrev_attrib_locus (*this);
-}
-
 checkdescriptor const *
 check_debug_abbrev::descriptor ()
 {
index 82704a5a6a45c086ff717f9e18dc835bf697a693..2eece6985338bf1c13c2afdf7a7601b2960807ce 100644 (file)
@@ -32,7 +32,7 @@
 #include "dwarf_version_i.hh"
 
 class abbrev_locus
-  : public locus
+  : public clonable_locus<abbrev_locus>
 {
   uint64_t _m_abbr_offset;
 
@@ -42,11 +42,10 @@ public:
   abbrev_locus (abbrev_locus const &copy);
 
   std::string format (bool brief = false) const;
-  locus *clone () const;
 };
 
 class abbrev_attrib_locus
-  : public locus
+  : public clonable_locus<abbrev_attrib_locus>
 {
   uint64_t _m_abbr_offset;
   uint64_t _m_attr_offset;
@@ -64,7 +63,6 @@ public:
   void set_name (int name);
   std::string format (bool brief = false) const;
   std::string name () const;
-  locus *clone () const;
 };
 
 struct abbrev_attrib
index d3b5df904584c7ef92ca2f86518d7753a856863c..d775608bed6b8cde83f069db0b70901fc435bb9e 100644 (file)
@@ -270,7 +270,7 @@ check_aranges_structural (struct elf_file *file,
        wr_error (&where, ": unresolved reference to " PRI_CU ".\n", cu_offset);
 
       class cudie_locus
-       : public locus
+       : public clonable_locus<cudie_locus>
       {
        uint64_t _m_offset;
 
@@ -289,12 +289,6 @@ check_aranges_structural (struct elf_file *file,
            ss << "unknown CU";
          return ss.str ();
        }
-
-       locus *
-       clone () const
-       {
-         return new cudie_locus (*this);
-       }
       };
 
       cudie_locus cudie_loc (cu != NULL ? cu->cudie_offset : -1);
index 8362a3c63ce46cd80bdfd32b6dd5abd601f30e39..611f1aec1cd8388b36ecdd3ba665c056ac1a72cb 100644 (file)
@@ -832,7 +832,7 @@ namespace
 }
 
 class locexpr_locus
-  : public locus
+  : public clonable_locus<locexpr_locus>
 {
   uint64_t const _m_offset;
   locus const *const _m_context;
@@ -851,12 +851,6 @@ public:
     return ss.str ();
   }
 
-  locus *
-  clone () const
-  {
-    return new locexpr_locus (*this);
-  }
-
   virtual locus const *next () const
   {
     return _m_context;
index 0a96f4bee74600b8adf97e63320d3cd9d6ee7003..f89cd67114803d7b200c5e82c5c876854a9a5b19 100644 (file)
@@ -41,7 +41,7 @@
 namespace
 {
   class reloc_locus
-    : public locus
+    : public clonable_locus<reloc_locus>
   {
     locus const &_m_ref;
     size_t _m_index;
@@ -88,12 +88,6 @@ namespace
       ss << " of " << _m_ref.format ();
       return ss.str ();
     }
-
-    locus *
-    clone () const
-    {
-      return new reloc_locus (*this);
-    }
   };
 }
 
index 7d9dcc577280fd14b3c5c9bfeefd94139adcf7a4..fdb5be0de73b70bc83fe983d4b2c9454e8ecdf57 100644 (file)
@@ -48,8 +48,19 @@ public:
   virtual ~locus () {}
 };
 
-struct section_locus
+template <class T>
+class clonable_locus
   : public locus
+{
+public:
+  virtual locus *clone () const
+  {
+    return new T (*static_cast<T const*> (this));
+  }
+};
+
+struct section_locus
+  : public clonable_locus<section_locus>
 {
   section_id _m_sec;
   uint64_t _m_offset;
@@ -66,16 +77,10 @@ public:
   {}
 
   std::string format (bool brief = false) const;
-
-  locus *
-  clone () const
-  {
-    return new section_locus (*this);
-  }
 };
 
 struct where
-  : public locus
+  : public clonable_locus<where>
 {
   class formatter
   {
@@ -111,12 +116,6 @@ public:
     return _m_next;
   }
 
-  locus *
-  clone () const
-  {
-    return new where (*this);
-  }
-
   void
   set_next (locus const *nxt)
   {