You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2010/10/05 18:39:30 UTC

svn commit: r1004703 - in /incubator/thrift/trunk/compiler/cpp/src: generate/t_generator.h parse/parse.cc parse/t_scope.h parse/t_type.h

Author: dreiss
Date: Tue Oct  5 16:39:29 2010
New Revision: 1004703

URL: http://svn.apache.org/viewvc?rev=1004703&view=rev
Log:
THRIFT-868. Make const values work properly with typdefs

Just requires calling get_true_type in the right spot.  Because "the
right spot" is under src/parse, get_true_type had to be moed from
t_generator to t_type.

Modified:
    incubator/thrift/trunk/compiler/cpp/src/generate/t_generator.h
    incubator/thrift/trunk/compiler/cpp/src/parse/parse.cc
    incubator/thrift/trunk/compiler/cpp/src/parse/t_scope.h
    incubator/thrift/trunk/compiler/cpp/src/parse/t_type.h

Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_generator.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_generator.h?rev=1004703&r1=1004702&r2=1004703&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_generator.h (original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_generator.h Tue Oct  5 16:39:29 2010
@@ -237,10 +237,7 @@ class t_generator {
    * 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;
+    return type->get_true_type();
   }
 
  protected:

Modified: incubator/thrift/trunk/compiler/cpp/src/parse/parse.cc
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/parse/parse.cc?rev=1004703&r1=1004702&r2=1004703&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/parse/parse.cc (original)
+++ incubator/thrift/trunk/compiler/cpp/src/parse/parse.cc Tue Oct  5 16:39:29 2010
@@ -1,4 +1,5 @@
 #include "t_type.h"
+#include "t_typedef.h"
 
 #include "md5.h"
 
@@ -9,3 +10,11 @@ void t_type::generate_fingerprint() {
   md5_append(&ctx, (md5_byte_t*)(material.data()), (int)material.size());
   md5_finish(&ctx, (md5_byte_t*)fingerprint_);
 }
+
+t_type* t_type::get_true_type() {
+  t_type* type = this;
+  while (type->is_typedef()) {
+    type = ((t_typedef*)type)->get_type();
+  }
+  return type;
+}

Modified: incubator/thrift/trunk/compiler/cpp/src/parse/t_scope.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/parse/t_scope.h?rev=1004703&r1=1004702&r2=1004703&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/parse/t_scope.h (original)
+++ incubator/thrift/trunk/compiler/cpp/src/parse/t_scope.h Tue Oct  5 16:39:29 2010
@@ -115,8 +115,11 @@ class t_scope {
           throw "No enum value or constant found named \"" + const_val->get_identifier() + "\"!";
         }
 
-        if (constant->get_type()->is_base_type()) {
-          switch (((t_base_type*)constant->get_type())->get_base()) {
+        // Resolve typedefs to the underlying type
+        t_type* const_type = constant->get_type()->get_true_type();
+
+        if (const_type->is_base_type()) {
+          switch (((t_base_type*)const_type)->get_base()) {
             case t_base_type::TYPE_I16:
             case t_base_type::TYPE_I32:
             case t_base_type::TYPE_I64:
@@ -133,7 +136,7 @@ class t_scope {
             case t_base_type::TYPE_VOID:
               throw "Constants cannot be of type VOID";
           }
-        } else if (constant->get_type()->is_map()) {
+        } else if (const_type->is_map()) {
           const std::map<t_const_value*, t_const_value*>& map = constant->get_value()->get_map();
           std::map<t_const_value*, t_const_value*>::const_iterator v_iter;
 
@@ -141,7 +144,7 @@ class t_scope {
           for (v_iter = map.begin(); v_iter != map.end(); ++v_iter) {
             const_val->add_map(v_iter->first, v_iter->second);
           }
-        } else if (constant->get_type()->is_list()) {
+        } else if (const_type->is_list()) {
           const std::vector<t_const_value*>& val = constant->get_value()->get_list();
           std::vector<t_const_value*>::const_iterator v_iter;
 

Modified: incubator/thrift/trunk/compiler/cpp/src/parse/t_type.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/parse/t_type.h?rev=1004703&r1=1004702&r2=1004703&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/parse/t_type.h (original)
+++ incubator/thrift/trunk/compiler/cpp/src/parse/t_type.h Tue Oct  5 16:39:29 2010
@@ -66,6 +66,7 @@ class t_type : public t_doc {
     return program_;
   }
 
+  t_type* get_true_type();
 
   // Return a string that uniquely identifies this type
   // from any other thrift type in the world, as far as