Thrift supports HEX notation for int consts and proper python/php sets
Reviewed By: yishan-tbr
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664883 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 afadf06..cb2573c 100644
--- a/compiler/cpp/src/generate/t_php_generator.cc
+++ b/compiler/cpp/src/generate/t_php_generator.cc
@@ -219,6 +219,9 @@
for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
f_consts_ << indent();
print_const_value(etype, *v_iter);
+ if (type->is_set()) {
+ f_consts_ << " => true";
+ }
f_consts_ << "," << endl;
}
indent_down();
@@ -1337,7 +1340,7 @@
generate_deserialize_field(out, &felem);
indent(out) <<
- "$" << prefix << " []= $" << elem << ";" << endl;
+ "$" << prefix << "[$" << elem << "] = true;" << endl;
}
void t_php_generator::generate_deserialize_list_element(ofstream &out,
@@ -1555,7 +1558,7 @@
} else if (ttype->is_set()) {
string iter = tmp("iter");
indent(out) <<
- "foreach ($" << prefix << " as $" << iter << ")" << endl;
+ "foreach ($" << prefix << " as $" << iter << " => $true)" << endl;
scope_up(out);
generate_serialize_set_element(out, (t_set*)ttype, iter);
scope_down(out);
diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc
index bb375cc..bc38296 100644
--- a/compiler/cpp/src/generate/t_py_generator.cc
+++ b/compiler/cpp/src/generate/t_py_generator.cc
@@ -210,6 +210,9 @@
} else {
etype = ((t_set*)type)->get_elem_type();
}
+ if (type->is_set()) {
+ f_consts_ << "set(";
+ }
f_consts_ << "[" << endl;
indent_up();
const vector<t_const_value*>& val = value->get_list();
@@ -221,6 +224,9 @@
}
indent_down();
indent(f_consts_) << "]";
+ if (type->is_set()) {
+ f_consts_ << ")";
+ }
}
}
@@ -1109,7 +1115,7 @@
indent() << "(" << ktype << ", " << vtype << ", " << size << " ) = iprot.readMapBegin() " << endl;
} else if (ttype->is_set()) {
out <<
- indent() << prefix << " = []" << endl <<
+ indent() << prefix << " = set()" << endl <<
indent() << "(" << etype << ", " << size << ") = iprot.readSetBegin()" << endl;
} else if (ttype->is_list()) {
out <<
@@ -1175,7 +1181,7 @@
generate_deserialize_field(out, &felem);
indent(out) <<
- prefix << ".append(" << elem << ")" << endl;
+ prefix << ".add(" << elem << ")" << endl;
}
/**
diff --git a/compiler/cpp/src/thrift.l b/compiler/cpp/src/thrift.l
index 0c113cb..a353786 100644
--- a/compiler/cpp/src/thrift.l
+++ b/compiler/cpp/src/thrift.l
@@ -28,6 +28,7 @@
*/
intconstant ([+-]?[0-9]+)
+hexconstant ("0x"[0-9A-Fa-f]+)
dubconstant ([+-]?[0-9]*(\.[0-9]+)?([eE][+-]?[0-9]+)?)
identifier ([a-zA-Z_][\.a-zA-Z_0-9]*)
whitespace ([ \t\r\n]*)
@@ -80,6 +81,12 @@
return tok_int_constant;
}
+{hexconstant} {
+ sscanf(yytext+2, "%x", &yylval.iconst);
+ printf("%d\n", yylval.iconst);
+ return tok_int_constant;
+}
+
{dubconstant} {
yylval.dconst = atof(yytext);
return tok_dub_constant;