From: Mark Slee Date: Fri, 19 Jan 2007 19:14:36 +0000 (+0000) Subject: Add comma-separated list of type "slist" to thrift X-Git-Tag: 0.2.0~1541 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=b6200d82f6611c5c3ca962f8de48ea840fe35de1;p=common%2Fthrift.git Add comma-separated list of type "slist" to thrift Summary: Useful for API arguments Reviewed By: tbr-dave git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664931 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc index 1f775756..092244e0 100644 --- a/compiler/cpp/src/generate/t_php_generator.cc +++ b/compiler/cpp/src/generate/t_php_generator.cc @@ -836,7 +836,8 @@ void t_php_generator::generate_service_rest(t_service* tservice) { } f_service_ << indent() << "$" << (*a_iter)->get_name() << " = $request['" << (*a_iter)->get_name() << "'];" << endl; - if (atype->is_list()) { + if (atype->is_string() && + ((t_base_type*)atype)->is_string_list()) { f_service_ << indent() << "$" << (*a_iter)->get_name() << " = explode(',', $" << (*a_iter)->get_name() << ");" << endl; } diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc index c6e81e3f..a8e07267 100644 --- a/compiler/cpp/src/generate/t_py_generator.cc +++ b/compiler/cpp/src/generate/t_py_generator.cc @@ -811,7 +811,7 @@ void t_py_generator::generate_service_remote(t_service* tservice) { " sys.exit(1)" << endl << " pp.pprint(client." << (*f_iter)->get_name() << "("; for (int i = 0; i < num_args; ++i) { - if (args[i]->get_type() == g_type_string) { + if (args[i]->get_type()->is_string()) { f_remote << "args[" << i << "],"; } else { f_remote << "eval(args[" << i << "]),"; diff --git a/compiler/cpp/src/globals.h b/compiler/cpp/src/globals.h index 51502c75..dd1067f2 100644 --- a/compiler/cpp/src/globals.h +++ b/compiler/cpp/src/globals.h @@ -47,6 +47,7 @@ extern t_program* g_program; extern t_type* g_type_void; extern t_type* g_type_string; +extern t_type* g_type_slist; extern t_type* g_type_bool; extern t_type* g_type_byte; extern t_type* g_type_i16; diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc index 065c95f6..2fbf913b 100644 --- a/compiler/cpp/src/main.cc +++ b/compiler/cpp/src/main.cc @@ -41,6 +41,7 @@ t_program* g_program; t_type* g_type_void; t_type* g_type_string; +t_type* g_type_slist; t_type* g_type_bool; t_type* g_type_byte; t_type* g_type_i16; @@ -621,6 +622,8 @@ int main(int argc, char** argv) { // Initialize global types g_type_void = new t_base_type("void", t_base_type::TYPE_VOID); g_type_string = new t_base_type("string", t_base_type::TYPE_STRING); + g_type_slist = new t_base_type("string", t_base_type::TYPE_STRING); + ((t_base_type*)g_type_slist)->set_string_list(true); g_type_bool = new t_base_type("bool", t_base_type::TYPE_BOOL); g_type_byte = new t_base_type("byte", t_base_type::TYPE_BYTE); g_type_i16 = new t_base_type("i16", t_base_type::TYPE_I16); diff --git a/compiler/cpp/src/parse/t_base_type.h b/compiler/cpp/src/parse/t_base_type.h index 837caa5e..b0d41d60 100644 --- a/compiler/cpp/src/parse/t_base_type.h +++ b/compiler/cpp/src/parse/t_base_type.h @@ -27,7 +27,8 @@ class t_base_type : public t_type { t_base_type(std::string name, t_base base) : t_type(name), - base_(base) {} + base_(base), + string_list_(false) {} t_base get_base() const { return base_; @@ -37,12 +38,25 @@ class t_base_type : public t_type { return base_ == TYPE_VOID; } + bool is_string() const { + return base_ == TYPE_STRING; + } + + void set_string_list(bool val) { + string_list_ = val; + } + + bool is_string_list() const { + return base_ == TYPE_STRING && string_list_; + } + bool is_base_type() const { return true; } private: t_base base_; + bool string_list_; }; #endif diff --git a/compiler/cpp/src/parse/t_type.h b/compiler/cpp/src/parse/t_type.h index 9589f02b..da062b52 100644 --- a/compiler/cpp/src/parse/t_type.h +++ b/compiler/cpp/src/parse/t_type.h @@ -28,6 +28,7 @@ class t_type { virtual bool is_void() const { return false; } virtual bool is_base_type() const { return false; } + virtual bool is_string() const { return false; } virtual bool is_typedef() const { return false; } virtual bool is_enum() const { return false; } virtual bool is_struct() const { return false; } diff --git a/compiler/cpp/src/thrift.l b/compiler/cpp/src/thrift.l index 4f2d542a..b7008c69 100644 --- a/compiler/cpp/src/thrift.l +++ b/compiler/cpp/src/thrift.l @@ -70,6 +70,7 @@ sliteral ("'"[^']*"'") "i64" { return tok_i64; } "double" { return tok_double; } "string" { return tok_string; } +"slist" { return tok_slist; } "map" { return tok_map; } "list" { return tok_list; } "set" { return tok_set; } diff --git a/compiler/cpp/src/thrift.y b/compiler/cpp/src/thrift.y index cfb3e44f..fe56dad9 100644 --- a/compiler/cpp/src/thrift.y +++ b/compiler/cpp/src/thrift.y @@ -75,6 +75,7 @@ int y_field_val = -1; %token tok_bool %token tok_byte %token tok_string +%token tok_slist %token tok_i16 %token tok_i32 %token tok_i64 @@ -637,6 +638,11 @@ BaseType: pdebug("BaseType -> tok_string"); $$ = g_type_string; } +| tok_slist + { + pdebug("BaseType -> tok_slist"); + $$ = g_type_slist; + } | tok_bool { pdebug("BaseType -> tok_bool");