summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Clark <kclark@apache.org>2009-01-05 23:10:17 +0000
committerKevin Clark <kclark@apache.org>2009-01-05 23:10:17 +0000
commit41baeaba96302e480265542340532842bc5ab0c9 (patch)
treeb8daa0f137876c6e8cb543f43654a3f06feef4ae
parentbcb4cf83e56ecbe5167d8c6ae79248c35020afe4 (diff)
downloadthrift-41baeaba96302e480265542340532842bc5ab0c9.tar.gz
THRIFT-157. rb: Quote strings and qualify class names properly
Author: Dave Engberg git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@731763 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--compiler/cpp/src/generate/t_rb_generator.cc17
-rw-r--r--lib/rb/spec/gen-rb/NonblockingService.rb2
-rw-r--r--lib/rb/spec/gen-rb/ThriftSpec_types.rb10
3 files changed, 20 insertions, 9 deletions
diff --git a/compiler/cpp/src/generate/t_rb_generator.cc b/compiler/cpp/src/generate/t_rb_generator.cc
index 4d90b1086..b2fc5bc7d 100644
--- a/compiler/cpp/src/generate/t_rb_generator.cc
+++ b/compiler/cpp/src/generate/t_rb_generator.cc
@@ -147,6 +147,7 @@ class t_rb_generator : public t_oop_generator {
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 @@ string t_rb_generator::render_const_value(t_type* type, t_const_value* value) {
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 @@ void t_rb_generator::generate_field_data(std::ofstream& out, t_type* field_type,
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 @@ void t_rb_generator::generate_process_function(t_service* tservice,
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 @@ string t_rb_generator::type_name(t_type* ttype) {
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
*/
diff --git a/lib/rb/spec/gen-rb/NonblockingService.rb b/lib/rb/spec/gen-rb/NonblockingService.rb
index a88680582..8044d8e5b 100644
--- a/lib/rb/spec/gen-rb/NonblockingService.rb
+++ b/lib/rb/spec/gen-rb/NonblockingService.rb
@@ -132,7 +132,7 @@ require File.dirname(__FILE__) + '/ThriftSpec_types'
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
diff --git a/lib/rb/spec/gen-rb/ThriftSpec_types.rb b/lib/rb/spec/gen-rb/ThriftSpec_types.rb
index 613c8de8e..a28c92142 100644
--- a/lib/rb/spec/gen-rb/ThriftSpec_types.rb
+++ b/lib/rb/spec/gen-rb/ThriftSpec_types.rb
@@ -13,7 +13,7 @@ module SpecNamespace
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 @@ module SpecNamespace
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 @@ module SpecNamespace
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