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
This commit is contained in:
Mark Slee 2007-01-19 19:14:36 +00:00
parent 1ea90526b0
commit b6200d82f6
8 changed files with 30 additions and 3 deletions

View File

@ -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;
}

View File

@ -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 << "]),";

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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; }

View File

@ -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; }

View File

@ -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");