Author: kclark
Date: Mon Jan  5 15:10:17 2009
New Revision: 731763

URL: http://svn.apache.org/viewvc?rev=731763&view=rev
Log:
THRIFT-157. rb: Quote strings and qualify class names properly

Author: Dave Engberg

Modified:
    incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc
    incubator/thrift/trunk/lib/rb/spec/gen-rb/NonblockingService.rb
    incubator/thrift/trunk/lib/rb/spec/gen-rb/ThriftSpec_types.rb

Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc?rev=731763&r1=731762&r2=731763&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc 
(original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_rb_generator.cc Mon Jan  
5 15:10:17 2009
@@ -147,6 +147,7 @@
   std::string render_includes();
   std::string declare_field(t_field* tfield);
   std::string type_name(t_type* ttype);
+  std::string full_type_name(t_type* ttype);
   std::string function_signature(t_function* tfunction, std::string prefix="");
   std::string argument_list(t_struct* tstruct);
   std::string type_to_enum(t_type* ttype);
@@ -328,7 +329,7 @@
     t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
     switch (tbase) {
     case t_base_type::TYPE_STRING:
-      out << "'" << value->get_string() << "'";
+      out << "%q\"" << value->get_string() << '"';
       break;
     case t_base_type::TYPE_BOOL:
       out << (value->get_integer() > 0 ? "true" : "false");
@@ -559,7 +560,7 @@
 
   if (!field_type->is_base_type()) {
     if (field_type->is_struct() || field_type->is_xception()) {
-      out << ", :class => " << type_name(((t_struct*)field_type));
+      out << ", :class => " << full_type_name((t_struct*)field_type);
     } else if (field_type->is_list()) {
       out << ", :element => ";
       generate_field_data(out, ((t_list*)field_type)->get_elem_type());
@@ -905,7 +906,7 @@
     indent_down();
     for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
       f_service_ <<
-        indent() << "rescue " << (*x_iter)->get_type()->get_name() << " => " 
<< (*x_iter)->get_name() << endl;
+        indent() << "rescue " << full_type_name((*x_iter)->get_type()) << " => 
" << (*x_iter)->get_name() << endl;
       if (!tfunction->is_async()) {
         indent_up();
         f_service_ <<
@@ -978,6 +979,16 @@
   return prefix + name;
 }
 
+string t_rb_generator::full_type_name(t_type* ttype) {
+  string prefix = "";
+  vector<std::string> modules = ruby_modules(ttype->get_program());
+  for (vector<std::string>::iterator m_iter = modules.begin();
+       m_iter != modules.end(); ++m_iter) {
+    prefix += *m_iter + "::";
+  }
+  return prefix + type_name(ttype);
+}
+
 /**
  * Converts the parse type to a Ruby tyoe
  */

Modified: incubator/thrift/trunk/lib/rb/spec/gen-rb/NonblockingService.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/gen-rb/NonblockingService.rb?rev=731763&r1=731762&r2=731763&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/gen-rb/NonblockingService.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/gen-rb/NonblockingService.rb Mon Jan  5 
15:10:17 2009
@@ -132,7 +132,7 @@
 
           Thrift::Struct.field_accessor self, :success
           FIELDS = {
-            SUCCESS => {:type => Thrift::Types::STRUCT, :name => 'success', 
:class => Hello}
+            SUCCESS => {:type => Thrift::Types::STRUCT, :name => 'success', 
:class => SpecNamespace::Hello}
           }
           def validate
           end

Modified: incubator/thrift/trunk/lib/rb/spec/gen-rb/ThriftSpec_types.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/gen-rb/ThriftSpec_types.rb?rev=731763&r1=731762&r2=731763&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/gen-rb/ThriftSpec_types.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/gen-rb/ThriftSpec_types.rb Mon Jan  5 
15:10:17 2009
@@ -13,7 +13,7 @@
 
       Thrift::Struct.field_accessor self, :greeting
       FIELDS = {
-        GREETING => {:type => Thrift::Types::STRING, :name => 'greeting', 
:default => 'hello world'}
+        GREETING => {:type => Thrift::Types::STRING, :name => 'greeting', 
:default => %q"hello world"}
       }
       def validate
       end
@@ -33,10 +33,10 @@
       Thrift::Struct.field_accessor self, :simple, :words, :hello, :ints, 
:complex, :shorts, :opt_string
       FIELDS = {
         SIMPLE => {:type => Thrift::Types::I32, :name => 'simple', :default => 
53},
-        WORDS => {:type => Thrift::Types::STRING, :name => 'words', :default 
=> 'words'},
+        WORDS => {:type => Thrift::Types::STRING, :name => 'words', :default 
=> %q"words"},
         HELLO => {:type => Thrift::Types::STRUCT, :name => 'hello', :default 
=> Hello.new({
-          'greeting' => 'hello, world!',
-        }), :class => Hello},
+          %q"greeting" => %q"hello, world!",
+        }), :class => SpecNamespace::Hello},
         INTS => {:type => Thrift::Types::LIST, :name => 'ints', :default => [
           1,
           2,
@@ -94,7 +94,7 @@
         MAPS => {:type => Thrift::Types::LIST, :name => 'maps', :element => 
{:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I16}, :value => 
{:type => Thrift::Types::I16}}},
         LISTS => {:type => Thrift::Types::LIST, :name => 'lists', :element => 
{:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I16}}},
         SETS => {:type => Thrift::Types::LIST, :name => 'sets', :element => 
{:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I16}}},
-        HELLOS => {:type => Thrift::Types::LIST, :name => 'hellos', :element 
=> {:type => Thrift::Types::STRUCT, :class => Hello}}
+        HELLOS => {:type => Thrift::Types::LIST, :name => 'hellos', :element 
=> {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}}
       }
       def validate
       end


Reply via email to