summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorJens Geyer <jensg@apache.org>2022-06-29 00:00:00 +0200
committerJens Geyer <jensg@apache.org>2022-09-05 22:04:20 +0200
commit62445c1d2e8bcca1056abb4559518f1c8d995992 (patch)
treebea3319b780bf3b918997ba5317eae0151e2395b /compiler
parent6a797b9843f47b455740afc146ac490de95d74c2 (diff)
downloadthrift-62445c1d2e8bcca1056abb4559518f1c8d995992.tar.gz
THRIFT-5591 Add uuid type to IDL and implement reference code (+ improved self-tests)
Client: compiler general, netstd, Delphi Patch: Jens Geyer
Diffstat (limited to 'compiler')
-rw-r--r--compiler/cpp/src/thrift/common.cc4
-rw-r--r--compiler/cpp/src/thrift/common.h1
-rw-r--r--compiler/cpp/src/thrift/generate/t_c_glib_generator.cc2
-rw-r--r--compiler/cpp/src/thrift/generate/t_cpp_generator.cc28
-rw-r--r--compiler/cpp/src/thrift/generate/t_d_generator.cc10
-rw-r--r--compiler/cpp/src/thrift/generate/t_dart_generator.cc6
-rw-r--r--compiler/cpp/src/thrift/generate/t_delphi_generator.cc20
-rw-r--r--compiler/cpp/src/thrift/generate/t_erl_generator.cc4
-rw-r--r--compiler/cpp/src/thrift/generate/t_go_generator.cc10
-rw-r--r--compiler/cpp/src/thrift/generate/t_haxe_generator.cc4
-rw-r--r--compiler/cpp/src/thrift/generate/t_java_generator.cc8
-rw-r--r--compiler/cpp/src/thrift/generate/t_javame_generator.cc4
-rw-r--r--compiler/cpp/src/thrift/generate/t_js_generator.cc5
-rw-r--r--compiler/cpp/src/thrift/generate/t_kotlin_generator.cc2
-rw-r--r--compiler/cpp/src/thrift/generate/t_lua_generator.cc2
-rw-r--r--compiler/cpp/src/thrift/generate/t_markdown_generator.cc2
-rw-r--r--compiler/cpp/src/thrift/generate/t_netstd_generator.cc18
-rw-r--r--compiler/cpp/src/thrift/generate/t_ocaml_generator.cc4
-rw-r--r--compiler/cpp/src/thrift/generate/t_perl_generator.cc6
-rw-r--r--compiler/cpp/src/thrift/generate/t_php_generator.cc10
-rw-r--r--compiler/cpp/src/thrift/generate/t_py_generator.cc2
-rw-r--r--compiler/cpp/src/thrift/generate/t_rb_generator.cc2
-rw-r--r--compiler/cpp/src/thrift/generate/t_rs_generator.cc10
-rw-r--r--compiler/cpp/src/thrift/generate/t_st_generator.cc2
-rw-r--r--compiler/cpp/src/thrift/generate/t_swift_generator.cc8
-rw-r--r--compiler/cpp/src/thrift/main.cc6
-rw-r--r--compiler/cpp/src/thrift/parse/t_base_type.h6
-rw-r--r--compiler/cpp/src/thrift/parse/t_const_value.h39
-rw-r--r--compiler/cpp/src/thrift/parse/t_scope.h3
-rw-r--r--compiler/cpp/src/thrift/parse/t_type.h1
-rw-r--r--compiler/cpp/src/thrift/thriftl.ll1
-rw-r--r--compiler/cpp/src/thrift/thrifty.yy6
32 files changed, 209 insertions, 27 deletions
diff --git a/compiler/cpp/src/thrift/common.cc b/compiler/cpp/src/thrift/common.cc
index 6dcd85500..3a28407a4 100644
--- a/compiler/cpp/src/thrift/common.cc
+++ b/compiler/cpp/src/thrift/common.cc
@@ -23,6 +23,7 @@
t_type* g_type_void;
t_type* g_type_string;
t_type* g_type_binary;
+t_type* g_type_uuid;
t_type* g_type_bool;
t_type* g_type_i8;
t_type* g_type_i16;
@@ -35,6 +36,7 @@ void initGlobals() {
g_type_string = new t_base_type("string", t_base_type::TYPE_STRING);
g_type_binary = new t_base_type("string", t_base_type::TYPE_STRING);
((t_base_type*)g_type_binary)->set_binary(true);
+ g_type_uuid = new t_base_type("string", t_base_type::TYPE_UUID);
g_type_bool = new t_base_type("bool", t_base_type::TYPE_BOOL);
g_type_i8 = new t_base_type("i8", t_base_type::TYPE_I8);
g_type_i16 = new t_base_type("i16", t_base_type::TYPE_I16);
@@ -46,6 +48,8 @@ void initGlobals() {
void clearGlobals() {
delete g_type_void;
delete g_type_string;
+ delete g_type_binary;
+ delete g_type_uuid;
delete g_type_bool;
delete g_type_i8;
delete g_type_i16;
diff --git a/compiler/cpp/src/thrift/common.h b/compiler/cpp/src/thrift/common.h
index 06392cda7..059421df1 100644
--- a/compiler/cpp/src/thrift/common.h
+++ b/compiler/cpp/src/thrift/common.h
@@ -29,6 +29,7 @@
extern t_type* g_type_void;
extern t_type* g_type_string;
extern t_type* g_type_binary;
+extern t_type* g_type_uuid;
extern t_type* g_type_bool;
extern t_type* g_type_i8;
extern t_type* g_type_i16;
diff --git a/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc b/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc
index 8cb82c180..4ce9c5fdc 100644
--- a/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc
@@ -723,6 +723,8 @@ string t_c_glib_generator::type_to_enum(t_type* type) {
return "T_I64";
case t_base_type::TYPE_DOUBLE:
return "T_DOUBLE";
+ default:
+ break;
}
} else if (type->is_enum()) {
return "T_I32";
diff --git a/compiler/cpp/src/thrift/generate/t_cpp_generator.cc b/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
index d9898b7c5..0420e62e7 100644
--- a/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
@@ -689,7 +689,7 @@ void t_cpp_generator::generate_enum_to_string_helper_function(std::ostream& out,
out << tenum->get_name() << "::type&";
}
out << " val) " ;
- scope_up(out);
+ scope_up(out);
out << indent() << "std::map<int, const char*>::const_iterator it = _"
<< tenum->get_name() << "_VALUES_TO_NAMES.find(val);" << endl;
@@ -1221,7 +1221,7 @@ void t_cpp_generator::generate_struct_declaration(ostream& out,
// Declare all fields
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- generate_java_doc(out, *m_iter);
+ generate_java_doc(out, *m_iter);
indent(out) << declare_field(*m_iter,
false,
(pointers && !(*m_iter)->get_type()->is_xception()),
@@ -2475,11 +2475,11 @@ void t_cpp_generator::generate_service_client(t_service* tservice, string style)
indent_up();
if (style != "Cob") {
f_header_ << indent() << service_name_ << style << "Client" << short_suffix << "(" << prot_ptr
- << " prot";
- if (style == "Concurrent") {
- f_header_ << ", std::shared_ptr< ::apache::thrift::async::TConcurrentClientSyncInfo> sync";
- }
- f_header_ << ") ";
+ << " prot";
+ if (style == "Concurrent") {
+ f_header_ << ", std::shared_ptr< ::apache::thrift::async::TConcurrentClientSyncInfo> sync";
+ }
+ f_header_ << ") ";
if (extends.empty()) {
if (style == "Concurrent") {
@@ -2498,12 +2498,12 @@ void t_cpp_generator::generate_service_client(t_service* tservice, string style)
}
f_header_ << indent() << service_name_ << style << "Client" << short_suffix << "(" << prot_ptr
- << " iprot, " << prot_ptr << " oprot";
- if (style == "Concurrent") {
- f_header_ << ", std::shared_ptr< ::apache::thrift::async::TConcurrentClientSyncInfo> sync";
- }
- f_header_ << ") ";
-
+ << " iprot, " << prot_ptr << " oprot";
+ if (style == "Concurrent") {
+ f_header_ << ", std::shared_ptr< ::apache::thrift::async::TConcurrentClientSyncInfo> sync";
+ }
+ f_header_ << ") ";
+
if (extends.empty()) {
if (style == "Concurrent") {
f_header_ << ": sync_(sync)" << endl;
@@ -4660,6 +4660,8 @@ string t_cpp_generator::type_to_enum(t_type* type) {
return "::apache::thrift::protocol::T_I64";
case t_base_type::TYPE_DOUBLE:
return "::apache::thrift::protocol::T_DOUBLE";
+ default:
+ break;
}
} else if (type->is_enum()) {
return "::apache::thrift::protocol::T_I32";
diff --git a/compiler/cpp/src/thrift/generate/t_d_generator.cc b/compiler/cpp/src/thrift/generate/t_d_generator.cc
index afae5b53d..f9e485642 100644
--- a/compiler/cpp/src/thrift/generate/t_d_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_d_generator.cc
@@ -74,9 +74,9 @@ protected:
// D reserved words are suffixed with an underscore
static string suffix_if_reserved(const string& name) {
- const bool isIn = std::binary_search(std::begin(d_reserved_words), std::end(d_reserved_words), name);
- string ret = isIn ? name + "_" : name;
- return ret;
+ const bool isIn = std::binary_search(std::begin(d_reserved_words), std::end(d_reserved_words), name);
+ string ret = isIn ? name + "_" : name;
+ return ret;
}
void init_generator() override {
@@ -403,8 +403,8 @@ private:
out << indent() << "// Your implementation goes here." << endl << indent() << "writeln(\""
<< suffix_if_reserved((*f_iter)->get_name()) << " called\");" << endl;
- t_type* rt = (*f_iter)->get_returntype();
- if (!rt->is_void()) {
+ t_type* rt = (*f_iter)->get_returntype();
+ if (!rt->is_void()) {
indent(out) << "return typeof(return).init;" << endl;
}
diff --git a/compiler/cpp/src/thrift/generate/t_dart_generator.cc b/compiler/cpp/src/thrift/generate/t_dart_generator.cc
index 65d0f535f..61cd98167 100644
--- a/compiler/cpp/src/thrift/generate/t_dart_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_dart_generator.cc
@@ -2216,6 +2216,8 @@ string t_dart_generator::declare_field(t_field* tfield, bool init) {
case t_base_type::TYPE_DOUBLE:
result += " = 0.0";
break;
+ default:
+ throw "compiler error: unhandled type";
}
} else if (ttype->is_enum()) {
@@ -2297,6 +2299,8 @@ string t_dart_generator::type_to_enum(t_type* type) {
return "TType.I64";
case t_base_type::TYPE_DOUBLE:
return "TType.DOUBLE";
+ default:
+ break;
}
} else if (type->is_enum()) {
return "TType.I32";
@@ -2351,6 +2355,8 @@ std::string t_dart_generator::init_value(t_field* field) {
case t_base_type::TYPE_STRING:
result = "";
break;
+ default:
+ throw "compiler error: unhandled type";
}
return result;
diff --git a/compiler/cpp/src/thrift/generate/t_delphi_generator.cc b/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
index 2d0af119f..f35ffcb99 100644
--- a/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
@@ -1024,6 +1024,7 @@ void t_delphi_generator::init_known_types_list() {
// known base types
types_known[type_name(g_type_string)] = 1;
types_known[type_name(g_type_binary)] = 1;
+ types_known[type_name(g_type_uuid)] = 1;
types_known[type_name(g_type_bool)] = 1;
types_known[type_name(g_type_i8)] = 1;
types_known[type_name(g_type_i16)] = 1;
@@ -1398,6 +1399,9 @@ string t_delphi_generator::render_const_value(ostream& vars,
case t_base_type::TYPE_STRING:
render << "'" << get_escaped_string(value) << "'";
break;
+ case t_base_type::TYPE_UUID:
+ render << "['{" << value->get_uuid() << "}']";
+ break;
case t_base_type::TYPE_BOOL:
render << ((value->get_integer() > 0) ? "True" : "False");
break;
@@ -2709,6 +2713,9 @@ void t_delphi_generator::generate_deserialize_field(ostream& out,
out << "ReadString();";
}
break;
+ case t_base_type::TYPE_UUID:
+ out << "ReadUuid();";
+ break;
case t_base_type::TYPE_BOOL:
out << "ReadBool();";
break;
@@ -2910,6 +2917,9 @@ void t_delphi_generator::generate_serialize_field(ostream& out,
}
out << name << ");";
break;
+ case t_base_type::TYPE_UUID:
+ out << "WriteUuid(" << name << ");";
+ break;
case t_base_type::TYPE_BOOL:
out << "WriteBool(" << name << ");";
break;
@@ -3195,6 +3205,7 @@ string t_delphi_generator::input_arg_prefix(t_type* ttype) {
// these should be const'ed for optimal performamce
case t_base_type::TYPE_STRING: // refcounted pointer
+ case t_base_type::TYPE_UUID: // refcounted pointer
case t_base_type::TYPE_I64: // larger than 32 bit
case t_base_type::TYPE_DOUBLE: // larger than 32 bit
return "const ";
@@ -3247,6 +3258,8 @@ string t_delphi_generator::base_type_name(t_base_type* tbase) {
} else {
return com_types_ ? "System.WideString" : "System.string";
}
+ case t_base_type::TYPE_UUID:
+ return "System.TGuid";
case t_base_type::TYPE_BOOL:
return "System.Boolean";
case t_base_type::TYPE_I8:
@@ -3413,6 +3426,8 @@ string t_delphi_generator::type_to_enum(t_type* type) {
throw "NO T_VOID CONSTRUCT";
case t_base_type::TYPE_STRING:
return "TType.String_";
+ case t_base_type::TYPE_UUID:
+ return "TType.Uuid";
case t_base_type::TYPE_BOOL:
return "TType.Bool_";
case t_base_type::TYPE_I8:
@@ -3461,6 +3476,8 @@ string t_delphi_generator::empty_value(t_type* type) {
} else {
return "''";
}
+ case t_base_type::TYPE_UUID:
+ return "System.TGuid.Empty";
case t_base_type::TYPE_BOOL:
return "False";
case t_base_type::TYPE_I8:
@@ -4065,6 +4082,9 @@ void t_delphi_generator::generate_delphi_struct_tostring_impl(ostream& out,
<< type_name(ttype, false, true, false, false)
<< ">.ToString( System.Ord( Self."
<< prop_name((*f_iter), is_exception) << ")));" << endl;
+ } else if (ttype->is_uuid()) {
+ indent_impl(out) << tmp_sb << ".Append( GUIDToString(Self." << prop_name((*f_iter), is_exception) << "));"
+ << endl;
} else {
indent_impl(out) << tmp_sb << ".Append( Self." << prop_name((*f_iter), is_exception) << ");"
<< endl;
diff --git a/compiler/cpp/src/thrift/generate/t_erl_generator.cc b/compiler/cpp/src/thrift/generate/t_erl_generator.cc
index c06ea437d..1f4fd506d 100644
--- a/compiler/cpp/src/thrift/generate/t_erl_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_erl_generator.cc
@@ -1168,6 +1168,8 @@ string t_erl_generator::type_to_enum(t_type* type) {
return "?tType_I64";
case t_base_type::TYPE_DOUBLE:
return "?tType_DOUBLE";
+ default:
+ break;
}
} else if (type->is_enum()) {
return "?tType_I32";
@@ -1211,6 +1213,8 @@ std::string t_erl_generator::render_type_term(t_type* type,
return "i64";
case t_base_type::TYPE_DOUBLE:
return "double";
+ default:
+ break;
}
} else if (type->is_enum()) {
return "i32";
diff --git a/compiler/cpp/src/thrift/generate/t_go_generator.cc b/compiler/cpp/src/thrift/generate/t_go_generator.cc
index f4b94a455..90f34c8ca 100644
--- a/compiler/cpp/src/thrift/generate/t_go_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_go_generator.cc
@@ -368,6 +368,8 @@ bool t_go_generator::omit_initialization(t_field* tfield) {
} else {
return value->get_double() == 0.;
}
+ default:
+ throw "compiler error: unhandled type";
}
}
return false;
@@ -420,6 +422,8 @@ bool t_go_generator::is_pointer_field(t_field* tfield, bool in_container_value)
case t_base_type::TYPE_I64:
case t_base_type::TYPE_DOUBLE:
return !has_default;
+ default:
+ break;
}
} else if (type->is_enum()) {
return !has_default;
@@ -4057,6 +4061,9 @@ string t_go_generator::type_to_enum(t_type* type) {
case t_base_type::TYPE_DOUBLE:
return "thrift.DOUBLE";
+
+ default:
+ break;
}
} else if (type->is_enum()) {
return "thrift.I32";
@@ -4144,6 +4151,9 @@ string t_go_generator::type_to_go_type_with_opt(t_type* type,
case t_base_type::TYPE_DOUBLE:
return maybe_pointer + "float64";
+
+ default:
+ break;
}
} else if (type->is_enum()) {
return maybe_pointer + publicize(type_name(type));
diff --git a/compiler/cpp/src/thrift/generate/t_haxe_generator.cc b/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
index 757f207f0..fdd21f2a3 100644
--- a/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
@@ -2698,6 +2698,8 @@ string t_haxe_generator::declare_field(t_field* tfield, bool init) {
case t_base_type::TYPE_DOUBLE:
result += " = (double)0";
break;
+ default:
+ throw "unhandled type";
}
} else if (ttype->is_enum()) {
@@ -2805,6 +2807,8 @@ string t_haxe_generator::type_to_enum(t_type* type) {
return "TType.I64";
case t_base_type::TYPE_DOUBLE:
return "TType.DOUBLE";
+ default:
+ break;
}
} else if (type->is_enum()) {
return "TType.I32";
diff --git a/compiler/cpp/src/thrift/generate/t_java_generator.cc b/compiler/cpp/src/thrift/generate/t_java_generator.cc
index 7dfd10f52..743d150fe 100644
--- a/compiler/cpp/src/thrift/generate/t_java_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_java_generator.cc
@@ -1833,6 +1833,8 @@ void t_java_generator::generate_java_struct_parcelable(ostream& out, t_struct* t
break;
case t_base_type::TYPE_VOID:
break;
+ default:
+ throw "compiler error: unhandled type";
}
}
}
@@ -1931,6 +1933,8 @@ void t_java_generator::generate_java_struct_parcelable(ostream& out, t_struct* t
break;
case t_base_type::TYPE_VOID:
break;
+ default:
+ throw "compiler error: unhandled type";
}
}
}
@@ -4666,6 +4670,8 @@ string t_java_generator::declare_field(t_field* tfield, bool init, bool comment)
case t_base_type::TYPE_DOUBLE:
result += " = (double)0";
break;
+ default:
+ throw "compiler error: unhandled type";
}
} else if (ttype->is_enum()) {
result += " = null";
@@ -4843,6 +4849,8 @@ string t_java_generator::type_to_enum(t_type* type) {
return "org.apache.thrift.protocol.TType.I64";
case t_base_type::TYPE_DOUBLE:
return "org.apache.thrift.protocol.TType.DOUBLE";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return "org.apache.thrift.protocol.TType.I32";
diff --git a/compiler/cpp/src/thrift/generate/t_javame_generator.cc b/compiler/cpp/src/thrift/generate/t_javame_generator.cc
index b37a43bd0..4da086965 100644
--- a/compiler/cpp/src/thrift/generate/t_javame_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_javame_generator.cc
@@ -2869,6 +2869,8 @@ string t_javame_generator::declare_field(t_field* tfield, bool init) {
case t_base_type::TYPE_DOUBLE:
result += " = (double)0";
break;
+ default:
+ throw "compiler error: unhandled type";
}
} else if (ttype->is_enum()) {
@@ -2951,6 +2953,8 @@ string t_javame_generator::type_to_enum(t_type* type) {
return "TType.I64";
case t_base_type::TYPE_DOUBLE:
return "TType.DOUBLE";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return "TType.I32";
diff --git a/compiler/cpp/src/thrift/generate/t_js_generator.cc b/compiler/cpp/src/thrift/generate/t_js_generator.cc
index 5fcac1659..03a307f82 100644
--- a/compiler/cpp/src/thrift/generate/t_js_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_js_generator.cc
@@ -2697,6 +2697,8 @@ string t_js_generator::type_to_enum(t_type* type) {
return "Thrift.Type.I64";
case t_base_type::TYPE_DOUBLE:
return "Thrift.Type.DOUBLE";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return "Thrift.Type.I32";
@@ -2745,6 +2747,9 @@ string t_js_generator::ts_get_type(t_type* type) {
break;
case t_base_type::TYPE_VOID:
ts_type = "void";
+ break;
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum() || type->is_struct() || type->is_xception()) {
std::string type_name;
diff --git a/compiler/cpp/src/thrift/generate/t_kotlin_generator.cc b/compiler/cpp/src/thrift/generate/t_kotlin_generator.cc
index 3a2afe6d5..3a3543e63 100644
--- a/compiler/cpp/src/thrift/generate/t_kotlin_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_kotlin_generator.cc
@@ -1892,6 +1892,8 @@ string t_kotlin_generator::type_to_enum(t_type* type) {
return "org.apache.thrift.protocol.TType.I64";
case t_base_type::TYPE_DOUBLE:
return "org.apache.thrift.protocol.TType.DOUBLE";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return "org.apache.thrift.protocol.TType.I32";
diff --git a/compiler/cpp/src/thrift/generate/t_lua_generator.cc b/compiler/cpp/src/thrift/generate/t_lua_generator.cc
index de3b89011..a4b4a37d3 100644
--- a/compiler/cpp/src/thrift/generate/t_lua_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_lua_generator.cc
@@ -1146,6 +1146,8 @@ string t_lua_generator::type_to_enum(t_type* type) {
return "TType.I64";
case t_base_type::TYPE_DOUBLE:
return "TType.DOUBLE";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return "TType.I32";
diff --git a/compiler/cpp/src/thrift/generate/t_markdown_generator.cc b/compiler/cpp/src/thrift/generate/t_markdown_generator.cc
index 17e90f759..0f6aa2227 100644
--- a/compiler/cpp/src/thrift/generate/t_markdown_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_markdown_generator.cc
@@ -199,7 +199,7 @@ void t_markdown_generator::generate_program_toc_row(t_program* tprog) {
string fn_name = (*fn_iter)->get_name();
filling.emplace_back();
fill = &filling.back();
- (*fill)[1] = " [ &bull; " + fn_name + "]("
+ (*fill)[1] = " [ &bull; " + fn_name + "]("
+ make_file_link(fname)
+ "#function-" + str_to_id(name + fn_name) + ")";
}
diff --git a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
index ad9e57965..547457130 100644
--- a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
@@ -636,6 +636,9 @@ string t_netstd_generator::render_const_value(ostream& out, string name, t_type*
render << '"' << get_escaped_string(value) << '"';
}
break;
+ case t_base_type::TYPE_UUID:
+ render << "new System.Guid(\"" << get_escaped_string(value) << "\")";
+ break;
case t_base_type::TYPE_BOOL:
render << ((value->get_integer() > 0) ? "true" : "false");
break;
@@ -2703,6 +2706,9 @@ void t_netstd_generator::generate_deserialize_field(ostream& out, t_field* tfiel
out << "ReadStringAsync(" << CANCELLATION_TOKEN_NAME << ");";
}
break;
+ case t_base_type::TYPE_UUID:
+ out << "ReadUuidAsync(" << CANCELLATION_TOKEN_NAME << ");";
+ break;
case t_base_type::TYPE_BOOL:
out << "ReadBoolAsync(" << CANCELLATION_TOKEN_NAME << ");";
break;
@@ -2906,6 +2912,9 @@ void t_netstd_generator::generate_serialize_field(ostream& out, t_field* tfield,
}
out << name << ", " << CANCELLATION_TOKEN_NAME << ");";
break;
+ case t_base_type::TYPE_UUID:
+ out << "WriteUuidAsync(" << nullable_name << ", " << CANCELLATION_TOKEN_NAME << ");";
+ break;
case t_base_type::TYPE_BOOL:
out << "WriteBoolAsync(" << nullable_name << ", " << CANCELLATION_TOKEN_NAME << ");";
break;
@@ -3453,7 +3462,7 @@ string t_netstd_generator::type_name(t_type* ttype, bool with_namespace)
if (ttype->is_set())
{
t_set* tset = static_cast<t_set*>(ttype);
- return "HashSet<" + type_name(tset->get_elem_type()) + ">";
+ return "HashSet<" + type_name(tset->get_elem_type()) + ">";
}
if (ttype->is_list())
@@ -3492,6 +3501,8 @@ string t_netstd_generator::base_type_name(t_base_type* tbase)
} else {
return "string";
}
+ case t_base_type::TYPE_UUID:
+ return "global::System.Guid";
case t_base_type::TYPE_BOOL:
return "bool";
case t_base_type::TYPE_I8:
@@ -3614,6 +3625,9 @@ string t_netstd_generator::initialize_field(t_field* tfield)
return " = null";
}
break;
+ case t_base_type::TYPE_UUID:
+ return " = System.Guid.Empty";
+ break;
case t_base_type::TYPE_BOOL:
return " = false";
break;
@@ -3725,6 +3739,8 @@ string t_netstd_generator::type_to_enum(t_type* type)
throw "NO T_VOID CONSTRUCT";
case t_base_type::TYPE_STRING:
return "TType.String";
+ case t_base_type::TYPE_UUID:
+ return "TType.Uuid";
case t_base_type::TYPE_BOOL:
return "TType.Bool";
case t_base_type::TYPE_I8:
diff --git a/compiler/cpp/src/thrift/generate/t_ocaml_generator.cc b/compiler/cpp/src/thrift/generate/t_ocaml_generator.cc
index 0a961467e..300b5ac71 100644
--- a/compiler/cpp/src/thrift/generate/t_ocaml_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_ocaml_generator.cc
@@ -1698,6 +1698,8 @@ string t_ocaml_generator::type_to_enum(t_type* type) {
return "Protocol.T_I64";
case t_base_type::TYPE_DOUBLE:
return "Protocol.T_DOUBLE";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return "Protocol.T_I32";
@@ -1739,6 +1741,8 @@ string t_ocaml_generator::render_ocaml_type(t_type* type) {
return "Int64.t";
case t_base_type::TYPE_DOUBLE:
return "float";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return capitalize(((t_enum*)type)->get_name()) + ".t";
diff --git a/compiler/cpp/src/thrift/generate/t_perl_generator.cc b/compiler/cpp/src/thrift/generate/t_perl_generator.cc
index 68bd57f0f..72de69887 100644
--- a/compiler/cpp/src/thrift/generate/t_perl_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_perl_generator.cc
@@ -1003,12 +1003,12 @@ void t_perl_generator::generate_service_rest(t_service* tservice) {
f_service_ << indent() << "my $" << (*a_iter)->get_name() << " = (" << req << ") ? " << req
<< " : undef;" << endl;
/* slist no longer supported
- if (atype->is_string() && ((t_base_type*)atype)->is_string_list()) {
+ if (atype->is_string() && ((t_base_type*)atype)->is_string_list()) {
f_service_ << indent() << "my @" << (*a_iter)->get_name() << " = split(/,/, $"
<< (*a_iter)->get_name() << ");" << endl << indent() << "$"
<< (*a_iter)->get_name() << " = \\@" << (*a_iter)->get_name() << endl;
}
- */
+ */
}
f_service_ << indent() << "return $self->{impl}->" << (*f_iter)->get_name() << "("
<< argument_list((*f_iter)->get_arglist()) << ");" << endl;
@@ -1666,6 +1666,8 @@ string t_perl_generator::type_to_enum(t_type* type) {
return "Thrift::TType::I64";
case t_base_type::TYPE_DOUBLE:
return "Thrift::TType::DOUBLE";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return "Thrift::TType::I32";
diff --git a/compiler/cpp/src/thrift/generate/t_php_generator.cc b/compiler/cpp/src/thrift/generate/t_php_generator.cc
index 39968a658..c6e60c82a 100644
--- a/compiler/cpp/src/thrift/generate/t_php_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_php_generator.cc
@@ -62,7 +62,7 @@ public:
validate_ = false;
json_serializable_ = false;
getters_setters_ = false;
-
+
nsglobal_ = ""; // by default global namespace is empty
classmap_ = false;
for (iter = parsed_options.begin(); iter != parsed_options.end(); ++iter) {
@@ -874,8 +874,8 @@ void t_php_generator::generate_reflection_getters(ostringstream& out,
* Generates a setter for the generated private fields
*/
void t_php_generator::generate_reflection_setters(ostringstream& out,
- string field_name,
- string cap_name) {
+ string field_name,
+ string cap_name) {
out << indent() << "public function set" << cap_name << "(" << "$" << field_name << ")" << endl
<< indent() << "{" << endl;
@@ -2798,6 +2798,8 @@ string t_php_generator::type_to_enum(t_type* type) {
return "TType::I64";
case t_base_type::TYPE_DOUBLE:
return "TType::DOUBLE";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return "TType::I32";
@@ -2839,6 +2841,8 @@ string t_php_generator::type_to_phpdoc(t_type* type) {
return "int";
case t_base_type::TYPE_DOUBLE:
return "double";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return "int";
diff --git a/compiler/cpp/src/thrift/generate/t_py_generator.cc b/compiler/cpp/src/thrift/generate/t_py_generator.cc
index 7f3cae546..33437fd00 100644
--- a/compiler/cpp/src/thrift/generate/t_py_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_py_generator.cc
@@ -2767,6 +2767,8 @@ string t_py_generator::type_to_enum(t_type* type) {
return "TType.I64";
case t_base_type::TYPE_DOUBLE:
return "TType.DOUBLE";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return "TType.I32";
diff --git a/compiler/cpp/src/thrift/generate/t_rb_generator.cc b/compiler/cpp/src/thrift/generate/t_rb_generator.cc
index 116ccaaa7..2ec578771 100644
--- a/compiler/cpp/src/thrift/generate/t_rb_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_rb_generator.cc
@@ -1171,6 +1171,8 @@ string t_rb_generator::type_to_enum(t_type* type) {
return "::Thrift::Types::I64";
case t_base_type::TYPE_DOUBLE:
return "::Thrift::Types::DOUBLE";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return "::Thrift::Types::I32";
diff --git a/compiler/cpp/src/thrift/generate/t_rs_generator.cc b/compiler/cpp/src/thrift/generate/t_rs_generator.cc
index 6ce402739..5946e1d9a 100644
--- a/compiler/cpp/src/thrift/generate/t_rs_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_rs_generator.cc
@@ -1551,6 +1551,8 @@ void t_rs_generator::render_type_sync_write(const string &type_var, bool type_va
case t_base_type::TYPE_DOUBLE:
f_gen_ << indent() << "o_prot.write_double(" + type_var + ".into())?;" << endl;
return;
+ default:
+ throw "compiler error: unhandled type";
}
} else if (ttype->is_typedef()) {
t_typedef* ttypedef = (t_typedef*) ttype;
@@ -1926,6 +1928,8 @@ void t_rs_generator::render_type_sync_read(const string &type_var, t_type *ttype
case t_base_type::TYPE_DOUBLE:
f_gen_ << indent() << "let " << type_var << " = OrderedFloat::from(i_prot.read_double()?);" << endl;
return;
+ default:
+ throw "compiler error: unhandled type";
}
} else if (ttype->is_typedef()) {
// FIXME: not a fan of separate `is_boxed` parameter
@@ -3025,6 +3029,8 @@ string t_rs_generator::to_rust_type(t_type* ttype) {
return "i64";
case t_base_type::TYPE_DOUBLE:
return "OrderedFloat<f64>";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (ttype->is_typedef()) {
t_typedef* ttypedef = (t_typedef*)ttype;
@@ -3085,6 +3091,8 @@ string t_rs_generator::to_rust_field_type_enum(t_type* ttype) {
return "TType::I64";
case t_base_type::TYPE_DOUBLE:
return "TType::Double";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (ttype->is_enum()) {
return "TType::I32";
@@ -3123,6 +3131,8 @@ string t_rs_generator::opt_in_req_out_value(t_type* ttype) {
return "Some(0)";
case t_base_type::TYPE_DOUBLE:
return "Some(OrderedFloat::from(0.0))";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (ttype->is_enum() || ttype->is_struct() || ttype->is_xception()) {
diff --git a/compiler/cpp/src/thrift/generate/t_st_generator.cc b/compiler/cpp/src/thrift/generate/t_st_generator.cc
index 109adc705..5edb85281 100644
--- a/compiler/cpp/src/thrift/generate/t_st_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_st_generator.cc
@@ -1037,6 +1037,8 @@ string t_st_generator::type_to_enum(t_type* type) {
return "TType i64";
case t_base_type::TYPE_DOUBLE:
return "TType double";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return "TType i32";
diff --git a/compiler/cpp/src/thrift/generate/t_swift_generator.cc b/compiler/cpp/src/thrift/generate/t_swift_generator.cc
index d8eb73310..834e31dc8 100644
--- a/compiler/cpp/src/thrift/generate/t_swift_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_swift_generator.cc
@@ -51,7 +51,7 @@ public:
const string& option_string)
: t_oop_generator(program) {
update_keywords();
-
+
(void)option_string;
map<string, string>::const_iterator iter;
@@ -292,7 +292,7 @@ private:
protected:
std::set<std::string> lang_keywords() const override {
- return {};
+ return {};
}
};
@@ -3136,6 +3136,8 @@ string t_swift_generator::type_to_enum(t_type* type, bool qualified) {
return result + "i64";
case t_base_type::TYPE_DOUBLE:
return result + "double";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return result + "i32";
@@ -3168,6 +3170,8 @@ string t_swift_generator::type_to_enum(t_type* type, bool qualified) {
return result + "I64";
case t_base_type::TYPE_DOUBLE:
return result + "DOUBLE";
+ default:
+ throw "compiler error: unhandled type";
}
} else if (type->is_enum()) {
return result + "I32";
diff --git a/compiler/cpp/src/thrift/main.cc b/compiler/cpp/src/thrift/main.cc
index c5aa65f32..a07f4295a 100644
--- a/compiler/cpp/src/thrift/main.cc
+++ b/compiler/cpp/src/thrift/main.cc
@@ -738,6 +738,12 @@ void validate_const_rec(std::string name, t_type* type, t_const_value* value) {
throw "type error: const \"" + name + "\" was declared as string";
}
break;
+ case t_base_type::TYPE_UUID:
+ if (value->get_type() != t_const_value::CV_STRING) {
+ throw "type error: const \"" + name + "\" was declared as uuid";
+ }
+ value->get_uuid(); // validates constant
+ break;
case t_base_type::TYPE_BOOL:
if (value->get_type() != t_const_value::CV_INTEGER) {
throw "type error: const \"" + name + "\" was declared as bool";
diff --git a/compiler/cpp/src/thrift/parse/t_base_type.h b/compiler/cpp/src/thrift/parse/t_base_type.h
index 5676f0492..4e5228d54 100644
--- a/compiler/cpp/src/thrift/parse/t_base_type.h
+++ b/compiler/cpp/src/thrift/parse/t_base_type.h
@@ -36,6 +36,7 @@ public:
enum t_base {
TYPE_VOID,
TYPE_STRING,
+ TYPE_UUID,
TYPE_BOOL,
TYPE_I8,
TYPE_I16,
@@ -55,6 +56,8 @@ public:
bool is_bool() const override { return base_ == TYPE_BOOL; }
+ bool is_uuid() const override { return base_ == TYPE_UUID; }
+
void set_binary(bool val) { binary_ = val; }
bool is_binary() const override { return binary_ && (base_ == TYPE_STRING); }
@@ -69,6 +72,9 @@ public:
case TYPE_STRING:
return "string";
break;
+ case TYPE_UUID:
+ return "uuid";
+ break;
case TYPE_BOOL:
return "bool";
break;
diff --git a/compiler/cpp/src/thrift/parse/t_const_value.h b/compiler/cpp/src/thrift/parse/t_const_value.h
index 5b8156f1a..452a90c5b 100644
--- a/compiler/cpp/src/thrift/parse/t_const_value.h
+++ b/compiler/cpp/src/thrift/parse/t_const_value.h
@@ -85,6 +85,17 @@ public:
}
}
+ void set_uuid(std::string val) {
+ validate_uuid(val);
+ valType_ = CV_STRING;
+ stringVal_ = val;
+ }
+
+ std::string get_uuid() const {
+ validate_uuid(stringVal_);
+ return stringVal_;
+ }
+
void set_double(double val) {
valType_ = CV_DOUBLE;
doubleVal_ = val;
@@ -199,6 +210,34 @@ private:
t_enum* enum_;
t_const_value_type valType_;
+
+ void validate_uuid(std::string uuid) const {
+ bool valid = (uuid.length() == 36);
+ const std::string HEXCHARS = std::string("0123456789ABCDEFabcdef");
+
+ // canonical format "01234567-9012-4567-9012-456789012345" expected
+ for( size_t i = 0; valid && (i < uuid.length()); ++i) {
+ switch(i) {
+ case 8:
+ case 13:
+ case 18:
+ case 23:
+ if(uuid[i] != '-') {
+ valid = false;
+ }
+ break;
+ default:
+ if(HEXCHARS.find(uuid[i]) == std::string::npos) {
+ valid = false;
+ }
+ break;
+ }
+ }
+
+ if( ! valid) {
+ throw "invalid uuid " + uuid;
+ }
+ }
};
#endif
diff --git a/compiler/cpp/src/thrift/parse/t_scope.h b/compiler/cpp/src/thrift/parse/t_scope.h
index 17a360f08..71ab4f389 100644
--- a/compiler/cpp/src/thrift/parse/t_scope.h
+++ b/compiler/cpp/src/thrift/parse/t_scope.h
@@ -166,6 +166,9 @@ public:
case t_base_type::TYPE_STRING:
const_val->set_string(constant->get_value()->get_string());
break;
+ case t_base_type::TYPE_UUID:
+ const_val->set_uuid(constant->get_value()->get_uuid());
+ break;
case t_base_type::TYPE_DOUBLE:
const_val->set_double(constant->get_value()->get_double());
break;
diff --git a/compiler/cpp/src/thrift/parse/t_type.h b/compiler/cpp/src/thrift/parse/t_type.h
index 63f99ed87..8dbeb9efc 100644
--- a/compiler/cpp/src/thrift/parse/t_type.h
+++ b/compiler/cpp/src/thrift/parse/t_type.h
@@ -47,6 +47,7 @@ public:
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_uuid() const { return false; }
virtual bool is_binary() const { return false; }
virtual bool is_bool() const { return false; }
virtual bool is_typedef() const { return false; }
diff --git a/compiler/cpp/src/thrift/thriftl.ll b/compiler/cpp/src/thrift/thriftl.ll
index 810a983e0..d60e84645 100644
--- a/compiler/cpp/src/thrift/thriftl.ll
+++ b/compiler/cpp/src/thrift/thriftl.ll
@@ -239,6 +239,7 @@ literal_begin (['\"])
"double" { return tok_double; }
"string" { return tok_string; }
"binary" { return tok_binary; }
+"uuid" { return tok_uuid; }
"slist" {
error_no_longer_supported("slist","string");
}
diff --git a/compiler/cpp/src/thrift/thrifty.yy b/compiler/cpp/src/thrift/thrifty.yy
index a062a0e40..40c2a9373 100644
--- a/compiler/cpp/src/thrift/thrifty.yy
+++ b/compiler/cpp/src/thrift/thrifty.yy
@@ -134,6 +134,7 @@ const int struct_is_union = 1;
%token tok_bool
%token tok_string
%token tok_binary
+%token tok_uuid
%token tok_i8
%token tok_i16
%token tok_i32
@@ -1002,6 +1003,11 @@ SimpleBaseType:
pdebug("BaseType -> tok_binary");
$$ = g_type_binary;
}
+| tok_uuid
+ {
+ pdebug("BaseType -> tok_uuid");
+ $$ = g_type_uuid;
+ }
| tok_bool
{
pdebug("BaseType -> tok_bool");