]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarf_output working again like dwarf_edit
authorRoland McGrath <roland@redhat.com>
Mon, 6 Jul 2009 08:42:29 +0000 (01:42 -0700)
committerRoland McGrath <roland@redhat.com>
Mon, 6 Jul 2009 08:42:29 +0000 (01:42 -0700)
libdw/c++/dwarf_output
src/dwarfcmp.cc

index 3ec3c4a2d7015d525e423766b9b4287dddb67fca..efd29859d1f8499bee4e257de531f3f0dacec1f4 100644 (file)
@@ -51,6 +51,7 @@
 #define _ELFUTILS_DWARF_OUTPUT 1
 
 #include "dwarf_edit"
+#include "dwarf_ref_maker"
 #include <functional>
 
 /* Read the comments for elfutils::dwarf first.
@@ -286,6 +287,7 @@ namespace elfutils
     class debug_info_entry;
 
   protected:
+    template<typename input> class copier; // Below.
 
     template<typename input>
     static inline const std::string &
@@ -310,8 +312,8 @@ namespace elfutils
       {
        const std::string &_m_str;
 
-       template<typename string>
-       inline value_string (const string &s, dwarf_output_collector &c)
+       template<typename string, typename input>
+       inline value_string (const string &s, dwarf_output::copier<input> &c)
          : _m_str (collect_string (c, s))
        {}
 
@@ -534,6 +536,13 @@ namespace elfutils
       return _m_units;
     }
 
+  private:
+    // Bind default copy-constructor and prevent it.
+    inline dwarf_output (const dwarf_output &)
+    {
+      throw std::logic_error ("copying dwarf_output requires a collector");
+    }
+
   public:
     // Constructor for an empty file, can add to its compile_units ().
     inline dwarf_output () {}
@@ -541,9 +550,8 @@ namespace elfutils
     // Constructor copying CUs from an input file (can be any of dwarf,
     // dwarf_edit, or dwarf_output).
     template<typename input>
-    inline dwarf_output (const input &dw, dwarf_output_collector &c)
-      : _m_units (dw.compile_units (), c)
-    {}
+    inline dwarf_output (const input &, dwarf_output_collector &,
+                        copier<input> = copier<input> ());
 
     template<typename file>
     inline bool operator== (const file &other) const
@@ -577,15 +585,40 @@ namespace elfutils
 
   public:
 
-    template<typename die1, typename die2> // XXX
-    inline void equivalence (const die1 &, const die2 &)
-    {}
+  };
+
+  template<class input>
+  class dwarf_output::copier
+    : public dwarf_ref_maker<dwarf_output, input> // XXX temporary
+  {
+    friend class dwarf_output;
+  private:
+    dwarf_output_collector *_m_collector;
 
-    template<typename die1, typename die2> // XXX
-    inline void refer (die1 *, const die2 &)
+    inline copier ()
+      : _m_collector (NULL)
     {}
+
+    copier &operator () (dwarf_output_collector &c)
+    {
+      _m_collector = &c;
+      return *this;
+    }
+
+    inline operator dwarf_output_collector & ()
+    {
+      return *_m_collector;
+    }
   };
 
+  // Copy construction instantiates a copier derived from the collector.
+  template<typename input>
+  inline dwarf_output::dwarf_output (const input &dw,
+                                    dwarf_output_collector &c,
+                                    copier<input> maker)
+    : _m_units (dw.compile_units (), maker (c))
+  {}
+
   template<typename input>
   inline const std::string &
   dwarf_output::collect_string (dwarf_output_collector &c, const input &s)
index 60f57ed3b0c307e996720baa41f86cda754fbc0c..7f9468a9d4d4e609cfa8032eeb572effbe024f48 100644 (file)
@@ -330,7 +330,6 @@ main (int argc, char *argv[])
          dwarf_edit edit2 (file2);
          test_classes (file1, file2, edit1, edit2, same);
 
-         /*
          {
            dwarf_output_collector c1;
            dwarf_output_collector c2;
@@ -347,7 +346,6 @@ main (int argc, char *argv[])
            test_classes (file1, file2, out1, out2, same);
            test_classes (edit1, edit2, out1, out2, same);
          }
-         */
        }
 
       result = !same;