Thrift: Add a useful helper function (in compiler).
authorDavid Reiss <dreiss@apache.org>
Wed, 15 Aug 2007 00:55:41 +0000 (00:55 +0000)
committerDavid Reiss <dreiss@apache.org>
Wed, 15 Aug 2007 00:55:41 +0000 (00:55 +0000)
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

compiler/cpp/src/generate/t_cpp_generator.cc
compiler/cpp/src/generate/t_generator.h

index ec83c89..8af32e2 100644 (file)
@@ -387,10 +387,7 @@ void t_cpp_generator::generate_struct_definition(ofstream& out,
     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()) {
index 52ffb70..beea968 100644 (file)
@@ -118,6 +118,7 @@ class t_generator {
   std::ostream& indent(std::ostream &os) {
     return os << indent();
   }
+
   /**
    * Capitalization helpers
    */
@@ -130,6 +131,16 @@ class t_generator {
     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