Thrift: Add a useful helper function (in compiler).

Summary:
Add a function to t_generator to traverse the typedef chain.

Reviewed By: mcslee

Test Plan:
Rebuilt thrift.
Re-thrifted ThriftTest.thrift.
Saw that the output was unchanged.

Revert Plan: ok

Notes:
Converting all of the generators to use this will happen later.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665203 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc
index ec83c89..8af32e2 100644
--- a/compiler/cpp/src/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/generate/t_cpp_generator.cc
@@ -387,10 +387,7 @@
     bool init_ctor = false;
 
     for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
-      t_type* t = (*m_iter)->get_type();
-      while (t->is_typedef()) {
-        t = ((t_typedef*)t)->get_type();
-      }
+      t_type* t = get_true_type((*m_iter)->get_type());
       if (t->is_base_type()) {
         string dval;
         if (t->is_enum()) {
diff --git a/compiler/cpp/src/generate/t_generator.h b/compiler/cpp/src/generate/t_generator.h
index 52ffb70..beea968 100644
--- a/compiler/cpp/src/generate/t_generator.h
+++ b/compiler/cpp/src/generate/t_generator.h
@@ -118,6 +118,7 @@
   std::ostream& indent(std::ostream &os) {
     return os << indent();
   }
+
   /**
    * Capitalization helpers
    */
@@ -130,6 +131,16 @@
     return in;
   }
 
+  /**
+   * Get the true type behind a series of typedefs.
+   */
+  static t_type* get_true_type(t_type* type) {
+    while (type->is_typedef()) {
+      type = ((t_typedef*)type)->get_type();
+    }
+    return type;
+  }
+
  protected:
   /**
    * The program being generated