From: Dodji Seketeli Date: Tue, 1 Nov 2016 10:37:41 +0000 (+0100) Subject: Factorize out string representation of array_type_def::subrange_type X-Git-Tag: libabigail-1.0.rc6~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ff0b07e711b608b1255d84db213caa05ddec4ad5;p=platform%2Fupstream%2Flibabigail.git Factorize out string representation of array_type_def::subrange_type 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 --- diff --git a/include/abg-ir.h b/include/abg-ir.h index fd32029c..7f8c100c 100644 --- a/include/abg-ir.h +++ b/include/abg-ir.h @@ -1891,6 +1891,12 @@ public: const location& get_location() const; + + string + as_string() const; + + static string + vector_as_string(const vector&); }; array_type_def(const type_base_sptr type, diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 45768af3..4be3fef6 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -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& v) +{ + string r; + for (vector::const_iterator i = v.begin(); + i != v.end(); + ++i) + r += (*i)->as_string(); + + return r; +} + // 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::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; }