Factorize out string representation of array_type_def::subrange_type
authorDodji Seketeli <dodji@redhat.com>
Tue, 1 Nov 2016 10:37:41 +0000 (11:37 +0100)
committerDodji Seketeli <dodji@redhat.com>
Thu, 3 Nov 2016 14:13:38 +0000 (15:13 +0100)
As we are going to need to print names of array types from DIEs
directly, we'll need to represent names of subranges.

This patch factorizes the string representation of the
array_type_def::subrange_type type.

* src/abg-ir.cc (array_type_def::subrange_type::{as_string,
vector_as_string}): Define methods.
(array_type_def::get_subrange_representation): Use the new
vector_as_string method.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
include/abg-ir.h
src/abg-ir.cc

index fd32029c1e0166874ce804f8a548a797fdc410ba..7f8c100ce5d45098e2b7d2ab905c3df40f13bdca 100644 (file)
@@ -1891,6 +1891,12 @@ public:
 
     const location&
     get_location() const;
+
+    string
+    as_string() const;
+
+    static string
+    vector_as_string(const vector<subrange_sptr>&);
   };
 
   array_type_def(const type_base_sptr type,
index 45768af314b692a11095e19f68663a8b4843f529..4be3fef6be1971e8043f4a0fdf1bde52009cee7b 100644 (file)
@@ -9268,6 +9268,33 @@ const location&
 array_type_def::subrange_type::get_location() const
 {return priv_->location_;}
 
+/// Return a string representation of the sub range.
+///
+/// @return the string representation of the sub range.
+string
+array_type_def::subrange_type::as_string() const
+{
+  string r;
+  std::ostringstream o;
+  o << "["  << get_length() << "]";
+  return o.str();
+}
+
+/// Return a string representation of a vector of subranges
+///
+/// @return the string representation of a vector of sub ranges.
+string
+array_type_def::subrange_type::vector_as_string(const vector<subrange_sptr>& v)
+{
+  string r;
+  for (vector<subrange_sptr>::const_iterator i = v.begin();
+       i != v.end();
+       ++i)
+    r += (*i)->as_string();
+
+  return r;
+}
+
 // </array_type_def::subrange_type>
 struct array_type_def::priv
 {
@@ -9307,16 +9334,7 @@ array_type_def::array_type_def(const type_base_sptr                      e_type,
 string
 array_type_def::get_subrange_representation() const
 {
-  string r;
-  for (std::vector<subrange_sptr >::const_iterator i = get_subranges().begin();
-       i != get_subranges().end(); ++i)
-    {
-      r += "[";
-      std::ostringstream o;
-      o << (*i)->get_length();
-      r += o.str();
-      r += "]";
-    }
+  string r = subrange_type::vector_as_string(get_subranges());
   return r;
 }