Upgrading vendor folder dependencies.
This commit is contained in:
parent
4a0cbcd770
commit
acbe9ad9e5
229 changed files with 10735 additions and 4528 deletions
2
vendor/git.apache.org/thrift.git/compiler/cpp/CMakeLists.txt
generated
vendored
2
vendor/git.apache.org/thrift.git/compiler/cpp/CMakeLists.txt
generated
vendored
|
@ -113,7 +113,7 @@ THRIFT_ADD_COMPILER(xml "Enable compiler for XML" ON)
|
|||
# we also add the current binary directory for generated files
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR} src)
|
||||
|
||||
if(NOT ${WITH_PLUGIN})
|
||||
if(NOT DEFINED WITH_PLUGIN OR NOT ${WITH_PLUGIN})
|
||||
list(APPEND thrift-compiler_SOURCES ${compiler_core})
|
||||
endif()
|
||||
|
||||
|
|
78
vendor/git.apache.org/thrift.git/compiler/cpp/src/thrift/generate/t_csharp_generator.cc
generated
vendored
78
vendor/git.apache.org/thrift.git/compiler/cpp/src/thrift/generate/t_csharp_generator.cc
generated
vendored
|
@ -1690,6 +1690,7 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
|
|||
|
||||
if (!async_) {
|
||||
indent(f_service_) << "#if SILVERLIGHT" << endl;
|
||||
indent(f_service_) << endl;
|
||||
}
|
||||
// Begin_
|
||||
indent(f_service_) << "public " << function_signature_async_begin(*f_iter, "Begin_") << endl;
|
||||
|
@ -1766,51 +1767,52 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
|
|||
indent(f_service_) << "#endif" << endl << endl;
|
||||
}
|
||||
|
||||
// "Normal" Synchronous invoke
|
||||
generate_csharp_doc(f_service_, *f_iter);
|
||||
indent(f_service_) << "public " << function_signature(*f_iter) << endl;
|
||||
scope_up(f_service_);
|
||||
|
||||
// silverlight invoke
|
||||
if (!async_) {
|
||||
indent(f_service_) << "#if !SILVERLIGHT" << endl;
|
||||
indent(f_service_) << "send_" << funname << "(";
|
||||
indent(f_service_) << "#if SILVERLIGHT" << endl;
|
||||
|
||||
first = true;
|
||||
indent(f_service_) << "var asyncResult = Begin_" << funname << "(null, null";
|
||||
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
f_service_ << ", ";
|
||||
}
|
||||
f_service_ << normalize_name((*fld_iter)->get_name());
|
||||
f_service_ << ", " << normalize_name((*fld_iter)->get_name());
|
||||
}
|
||||
f_service_ << ");" << endl;
|
||||
|
||||
|
||||
if (!(*f_iter)->is_oneway()) {
|
||||
f_service_ << indent();
|
||||
if (!(*f_iter)->get_returntype()->is_void()) {
|
||||
f_service_ << "return ";
|
||||
}
|
||||
f_service_ << "recv_" << funname << "();" << endl;
|
||||
f_service_ << "End_" << funname << "(asyncResult);" << endl;
|
||||
}
|
||||
f_service_ << endl;
|
||||
|
||||
indent(f_service_) << "#else" << endl;
|
||||
}
|
||||
|
||||
// Silverlight synchronous invoke
|
||||
indent(f_service_) << "var asyncResult = Begin_" << funname << "(null, null";
|
||||
// synchronous invoke
|
||||
indent(f_service_) << "send_" << funname << "(";
|
||||
|
||||
first = true;
|
||||
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
|
||||
f_service_ << ", " << normalize_name((*fld_iter)->get_name());
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
f_service_ << ", ";
|
||||
}
|
||||
f_service_ << normalize_name((*fld_iter)->get_name());
|
||||
}
|
||||
f_service_ << ");" << endl;
|
||||
|
||||
|
||||
if (!(*f_iter)->is_oneway()) {
|
||||
f_service_ << indent();
|
||||
if (!(*f_iter)->get_returntype()->is_void()) {
|
||||
f_service_ << "return ";
|
||||
}
|
||||
f_service_ << "End_" << funname << "(asyncResult);" << endl;
|
||||
f_service_ << "recv_" << funname << "();" << endl;
|
||||
}
|
||||
f_service_ << endl;
|
||||
|
||||
|
@ -1829,12 +1831,8 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
|
|||
if (!async_) {
|
||||
indent(f_service_) << "#if SILVERLIGHT" << endl;
|
||||
}
|
||||
|
||||
indent(f_service_) << "public " << function_signature_async_begin(&send_function) << endl;
|
||||
if (!async_) {
|
||||
indent(f_service_) << "#else" << endl;
|
||||
indent(f_service_) << "public " << function_signature(&send_function) << endl;
|
||||
indent(f_service_) << "#endif" << endl;
|
||||
}
|
||||
scope_up(f_service_);
|
||||
|
||||
f_service_ << indent() << "oprot_.WriteMessageBegin(new TMessage(\"" << funname << "\", "
|
||||
|
@ -1849,20 +1847,40 @@ void t_csharp_generator::generate_service_client(t_service* tservice) {
|
|||
|
||||
f_service_ << indent() << "args.Write(oprot_);" << endl << indent()
|
||||
<< "oprot_.WriteMessageEnd();" << endl;
|
||||
;
|
||||
indent(f_service_) << "return oprot_.Transport.BeginFlush(callback, state);" << endl;
|
||||
|
||||
scope_down(f_service_);
|
||||
f_service_ << endl;
|
||||
|
||||
if (!async_) {
|
||||
indent(f_service_) << "#if SILVERLIGHT" << endl;
|
||||
}
|
||||
indent(f_service_) << "return oprot_.Transport.BeginFlush(callback, state);" << endl;
|
||||
if (!async_) {
|
||||
indent(f_service_) << "#else" << endl;
|
||||
indent(f_service_) << "oprot_.Transport.Flush();" << endl;
|
||||
f_service_ << endl;
|
||||
}
|
||||
|
||||
indent(f_service_) << "public " << function_signature(&send_function) << endl;
|
||||
scope_up(f_service_);
|
||||
|
||||
f_service_ << indent() << "oprot_.WriteMessageBegin(new TMessage(\"" << funname << "\", "
|
||||
<< ((*f_iter)->is_oneway() ? "TMessageType.Oneway" : "TMessageType.Call")
|
||||
<< ", seqid_));" << endl << indent() << argsname << " args = new " << argsname
|
||||
<< "();" << endl;
|
||||
|
||||
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
|
||||
f_service_ << indent() << "args." << prop_name(*fld_iter) << " = "
|
||||
<< normalize_name((*fld_iter)->get_name()) << ";" << endl;
|
||||
}
|
||||
|
||||
f_service_ << indent() << "args.Write(oprot_);" << endl << indent()
|
||||
<< "oprot_.WriteMessageEnd();" << endl;
|
||||
|
||||
indent(f_service_) << "oprot_.Transport.Flush();" << endl;
|
||||
cleanup_member_name_mapping(arg_struct);
|
||||
scope_down(f_service_);
|
||||
|
||||
if (!async_) {
|
||||
indent(f_service_) << "#endif" << endl;
|
||||
}
|
||||
|
||||
cleanup_member_name_mapping(arg_struct);
|
||||
scope_down(f_service_);
|
||||
f_service_ << endl;
|
||||
|
||||
if (!(*f_iter)->is_oneway()) {
|
||||
|
|
4
vendor/git.apache.org/thrift.git/compiler/cpp/src/thrift/generate/t_go_generator.cc
generated
vendored
4
vendor/git.apache.org/thrift.git/compiler/cpp/src/thrift/generate/t_go_generator.cc
generated
vendored
|
@ -61,7 +61,7 @@ static const string endl = "\n"; // avoid ostream << std::endl flushes
|
|||
*/
|
||||
bool format_go_output(const string& file_path);
|
||||
|
||||
const string DEFAULT_THRIFT_IMPORT = "git.apache.org/thrift.git/lib/go/thrift";
|
||||
const string DEFAULT_THRIFT_IMPORT = "github.com/apache/thrift/lib/go/thrift";
|
||||
static std::string package_flag;
|
||||
|
||||
/**
|
||||
|
@ -1323,7 +1323,7 @@ void t_go_generator::generate_go_struct_definition(ostream& out,
|
|||
if (tstruct->is_union())
|
||||
(*m_iter)->set_req(t_field::T_OPTIONAL);
|
||||
if (sorted_keys_pos != (*m_iter)->get_key()) {
|
||||
int first_unused = std::max(1, sorted_keys_pos++);
|
||||
int first_unused = (std::max)(1, sorted_keys_pos++);
|
||||
while (sorted_keys_pos != (*m_iter)->get_key()) {
|
||||
++sorted_keys_pos;
|
||||
}
|
||||
|
|
10
vendor/git.apache.org/thrift.git/compiler/cpp/src/thrift/generate/t_java_generator.cc
generated
vendored
10
vendor/git.apache.org/thrift.git/compiler/cpp/src/thrift/generate/t_java_generator.cc
generated
vendored
|
@ -498,6 +498,11 @@ void t_java_generator::generate_enum(t_enum* tenum) {
|
|||
f_enum << autogen_comment() << java_package() << endl;
|
||||
|
||||
generate_java_doc(f_enum, tenum);
|
||||
|
||||
if (!suppress_generated_annotations_) {
|
||||
generate_javax_generated_annotation(f_enum);
|
||||
}
|
||||
|
||||
if (is_deprecated) {
|
||||
indent(f_enum) << "@Deprecated" << endl;
|
||||
}
|
||||
|
@ -544,6 +549,7 @@ void t_java_generator::generate_enum(t_enum* tenum) {
|
|||
<< endl;
|
||||
indent(f_enum) << " * @return null if the value is not found." << endl;
|
||||
indent(f_enum) << " */" << endl;
|
||||
indent(f_enum) << java_nullable_annotation() << endl;
|
||||
indent(f_enum) << "public static " + tenum->get_name() + " findByValue(int value) { " << endl;
|
||||
|
||||
indent_up();
|
||||
|
@ -827,6 +833,10 @@ void t_java_generator::generate_java_union(t_struct* tstruct) {
|
|||
bool is_final = (tstruct->annotations_.find("final") != tstruct->annotations_.end());
|
||||
bool is_deprecated = this->is_deprecated(tstruct->annotations_);
|
||||
|
||||
if (!suppress_generated_annotations_) {
|
||||
generate_javax_generated_annotation(f_struct);
|
||||
}
|
||||
|
||||
if (is_deprecated) {
|
||||
indent(f_struct) << "@Deprecated" << endl;
|
||||
}
|
||||
|
|
569
vendor/git.apache.org/thrift.git/compiler/cpp/src/thrift/generate/t_js_generator.cc
generated
vendored
569
vendor/git.apache.org/thrift.git/compiler/cpp/src/thrift/generate/t_js_generator.cc
generated
vendored
|
@ -64,7 +64,7 @@ public:
|
|||
|
||||
bool with_ns_ = false;
|
||||
|
||||
for( iter = parsed_options.begin(); iter != parsed_options.end(); ++iter) {
|
||||
for (iter = parsed_options.begin(); iter != parsed_options.end(); ++iter) {
|
||||
if( iter->first.compare("node") == 0) {
|
||||
gen_node_ = true;
|
||||
} else if( iter->first.compare("jquery") == 0) {
|
||||
|
@ -80,10 +80,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
if (gen_node_ && gen_ts_) {
|
||||
throw "Invalid switch: [-gen js:node,ts] options not compatible";
|
||||
}
|
||||
|
||||
if (gen_es6_ && gen_jquery_) {
|
||||
throw "Invalid switch: [-gen js:es6,jquery] options not compatible";
|
||||
}
|
||||
|
@ -203,6 +199,7 @@ public:
|
|||
*/
|
||||
|
||||
std::string js_includes();
|
||||
std::string ts_includes();
|
||||
std::string render_includes();
|
||||
std::string declare_field(t_field* tfield, bool init = false, bool obj = false);
|
||||
std::string function_signature(t_function* tfunction,
|
||||
|
@ -285,7 +282,7 @@ public:
|
|||
* TypeScript Definition File helper functions
|
||||
*/
|
||||
|
||||
string ts_function_signature(t_function* tfunction, bool include_callback);
|
||||
string ts_function_signature(t_function* tfunction, bool include_callback, bool optional_callback);
|
||||
string ts_get_type(t_type* type);
|
||||
|
||||
/**
|
||||
|
@ -302,11 +299,11 @@ public:
|
|||
string ts_declare() { return (ts_module_.empty() ? "declare " : ""); }
|
||||
|
||||
/**
|
||||
* Returns "?" if the given field is optional.
|
||||
* Returns "?" if the given field is optional or has a default value.
|
||||
* @param t_field The field to check
|
||||
* @return string
|
||||
*/
|
||||
string ts_get_req(t_field* field) { return (field->get_req() == t_field::T_OPTIONAL ? "?" : ""); }
|
||||
string ts_get_req(t_field* field) {return (field->get_req() == t_field::T_OPTIONAL || field->get_value() != NULL ? "?" : ""); }
|
||||
|
||||
/**
|
||||
* Returns the documentation, if the provided documentable object has one.
|
||||
|
@ -415,7 +412,7 @@ void t_js_generator::init_generator() {
|
|||
f_types_ << js_includes() << endl << render_includes() << endl;
|
||||
|
||||
if (gen_ts_) {
|
||||
f_types_ts_ << autogen_comment() << endl;
|
||||
f_types_ts_ << autogen_comment() << ts_includes() << endl;
|
||||
}
|
||||
|
||||
if (gen_node_) {
|
||||
|
@ -457,6 +454,20 @@ string t_js_generator::js_includes() {
|
|||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints standard ts imports
|
||||
*/
|
||||
string t_js_generator::ts_includes() {
|
||||
if (gen_node_) {
|
||||
return string(
|
||||
"import thrift = require('thrift');\n"
|
||||
"import Thrift = thrift.Thrift;\n"
|
||||
"import Q = thrift.Q;\n");
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders all the imports necessary for including another Thrift program
|
||||
*/
|
||||
|
@ -518,8 +529,8 @@ void t_js_generator::generate_enum(t_enum* tenum) {
|
|||
|
||||
indent_up();
|
||||
|
||||
vector<t_enum_value*> constants = tenum->get_constants();
|
||||
vector<t_enum_value*>::iterator c_iter;
|
||||
vector<t_enum_value*> const& constants = tenum->get_constants();
|
||||
vector<t_enum_value*>::const_iterator c_iter;
|
||||
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
|
||||
int value = (*c_iter)->get_value();
|
||||
if (gen_ts_) {
|
||||
|
@ -718,16 +729,15 @@ void t_js_generator::generate_js_struct_definition(ostream& out,
|
|||
|
||||
if (gen_node_) {
|
||||
string prefix = has_js_namespace(tstruct->get_program()) ? js_namespace(tstruct->get_program()) : js_const_type_;
|
||||
if (is_exported) {
|
||||
out << prefix << tstruct->get_name() << " = "
|
||||
<< "module.exports." << tstruct->get_name() << " = function(args) {" << endl;
|
||||
} else {
|
||||
out << prefix << tstruct->get_name() << " = function(args) {"
|
||||
<< endl;
|
||||
out << prefix << tstruct->get_name() <<
|
||||
(is_exported ? " = module.exports." + tstruct->get_name() : "");
|
||||
if (gen_ts_) {
|
||||
f_types_ts_ << ts_print_doc(tstruct) << ts_indent() << ts_declare() << "class "
|
||||
<< tstruct->get_name() << (is_exception ? " extends Thrift.TException" : "")
|
||||
<< " {" << endl;
|
||||
}
|
||||
} else {
|
||||
out << js_namespace(tstruct->get_program()) << tstruct->get_name() << " = function(args) {"
|
||||
<< endl;
|
||||
out << js_namespace(tstruct->get_program()) << tstruct->get_name();
|
||||
if (gen_ts_) {
|
||||
f_types_ts_ << ts_print_doc(tstruct) << ts_indent() << ts_declare() << "class "
|
||||
<< tstruct->get_name() << (is_exception ? " extends Thrift.TException" : "")
|
||||
|
@ -735,11 +745,28 @@ void t_js_generator::generate_js_struct_definition(ostream& out,
|
|||
}
|
||||
}
|
||||
|
||||
if (gen_es6_) {
|
||||
if (gen_node_ && is_exception) {
|
||||
out << " = class extends Thrift.TException {" << endl;
|
||||
} else {
|
||||
out << " = class {" << endl;
|
||||
}
|
||||
indent_up();
|
||||
indent(out) << "constructor(args) {" << endl;
|
||||
} else {
|
||||
out << " = function(args) {" << endl;
|
||||
}
|
||||
|
||||
indent_up();
|
||||
|
||||
// Call super() method on inherited Error class
|
||||
if (gen_node_ && is_exception) {
|
||||
out << indent() << "Thrift.TException.call(this, \"" << js_namespace(tstruct->get_program())
|
||||
if (gen_es6_) {
|
||||
indent(out) << "super(args);" << endl;
|
||||
} else {
|
||||
indent(out) << "Thrift.TException.call(this, \"" << js_namespace(tstruct->get_program())
|
||||
<< tstruct->get_name() << "\");" << endl;
|
||||
}
|
||||
out << indent() << "this.name = \"" << js_namespace(tstruct->get_program())
|
||||
<< tstruct->get_name() << "\";" << endl;
|
||||
}
|
||||
|
@ -755,8 +782,14 @@ void t_js_generator::generate_js_struct_definition(ostream& out,
|
|||
out << indent() << dval << ";" << endl;
|
||||
}
|
||||
if (gen_ts_) {
|
||||
f_types_ts_ << ts_indent() << (*m_iter)->get_name() << ": "
|
||||
<< ts_get_type((*m_iter)->get_type()) << ";" << endl;
|
||||
if (gen_node_) {
|
||||
f_types_ts_ << ts_indent() << "public " << (*m_iter)->get_name() << ": "
|
||||
<< ts_get_type((*m_iter)->get_type()) << ";" << endl;
|
||||
} else {
|
||||
f_types_ts_ << ts_indent() << (*m_iter)->get_name() << ": "
|
||||
<< ts_get_type((*m_iter)->get_type()) << ";" << endl;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -782,15 +815,17 @@ void t_js_generator::generate_js_struct_definition(ostream& out,
|
|||
}
|
||||
}
|
||||
|
||||
out << indent() << "if (args) {" << endl;
|
||||
indent(out) << "if (args) {" << endl;
|
||||
indent_up();
|
||||
if (gen_ts_) {
|
||||
f_types_ts_ << endl << ts_indent() << "constructor(args?: { ";
|
||||
}
|
||||
|
||||
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
|
||||
t_type* t = get_true_type((*m_iter)->get_type());
|
||||
out << indent() << indent() << "if (args." << (*m_iter)->get_name() << " !== undefined && args." << (*m_iter)->get_name() << " !== null) {"
|
||||
<< endl << indent() << indent() << indent() << "this." << (*m_iter)->get_name();
|
||||
indent(out) << "if (args." << (*m_iter)->get_name() << " !== undefined && args." << (*m_iter)->get_name() << " !== null) {" << endl;
|
||||
indent_up();
|
||||
indent(out) << "this." << (*m_iter)->get_name();
|
||||
|
||||
if (t->is_struct()) {
|
||||
out << (" = new " + js_type_namespace(t->get_program()) + t->get_name() +
|
||||
|
@ -829,43 +864,60 @@ void t_js_generator::generate_js_struct_definition(ostream& out,
|
|||
out << " = args." << (*m_iter)->get_name() << ";" << endl;
|
||||
}
|
||||
|
||||
indent_down();
|
||||
if (!(*m_iter)->get_req()) {
|
||||
out << indent() << indent() << "} else {" << endl << indent() << indent() << indent()
|
||||
<< "throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, "
|
||||
indent(out) << "} else {" << endl;
|
||||
indent(out)
|
||||
<< " throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, "
|
||||
"'Required field " << (*m_iter)->get_name() << " is unset!');" << endl;
|
||||
}
|
||||
out << indent() << indent() << "}" << endl;
|
||||
indent(out) << "}" << endl;
|
||||
if (gen_ts_) {
|
||||
f_types_ts_ << (*m_iter)->get_name() << ts_get_req(*m_iter) << ": "
|
||||
<< ts_get_type((*m_iter)->get_type()) << "; ";
|
||||
}
|
||||
}
|
||||
|
||||
indent_down();
|
||||
out << indent() << "}" << endl;
|
||||
if (gen_ts_) {
|
||||
f_types_ts_ << "});" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Done with constructor
|
||||
indent_down();
|
||||
out << "};" << endl;
|
||||
if (gen_es6_) {
|
||||
indent(out) << "}" << endl << endl;
|
||||
} else {
|
||||
indent(out) << "};" << endl;
|
||||
}
|
||||
|
||||
if (gen_ts_) {
|
||||
f_types_ts_ << ts_indent() << "}" << endl;
|
||||
}
|
||||
|
||||
if (is_exception) {
|
||||
out << "Thrift.inherits(" << js_namespace(tstruct->get_program()) << tstruct->get_name()
|
||||
<< ", Thrift.TException);" << endl;
|
||||
out << js_namespace(tstruct->get_program()) << tstruct->get_name() << ".prototype.name = '"
|
||||
<< tstruct->get_name() << "';" << endl;
|
||||
} else {
|
||||
// init prototype
|
||||
out << js_namespace(tstruct->get_program()) << tstruct->get_name() << ".prototype = {};"
|
||||
<< endl;
|
||||
if (!gen_es6_) {
|
||||
if (is_exception) {
|
||||
out << "Thrift.inherits(" << js_namespace(tstruct->get_program()) << tstruct->get_name()
|
||||
<< ", Thrift.TException);" << endl;
|
||||
out << js_namespace(tstruct->get_program()) << tstruct->get_name() << ".prototype.name = '"
|
||||
<< tstruct->get_name() << "';" << endl;
|
||||
} else {
|
||||
// init prototype manually if we aren't using es6
|
||||
out << js_namespace(tstruct->get_program()) << tstruct->get_name() << ".prototype = {};"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
generate_js_struct_reader(out, tstruct);
|
||||
generate_js_struct_writer(out, tstruct);
|
||||
|
||||
// Close out the class definition
|
||||
if (gen_es6_) {
|
||||
indent_down();
|
||||
indent(out) << "};" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -875,8 +927,12 @@ void t_js_generator::generate_js_struct_reader(ostream& out, t_struct* tstruct)
|
|||
const vector<t_field*>& fields = tstruct->get_members();
|
||||
vector<t_field*>::const_iterator f_iter;
|
||||
|
||||
out << js_namespace(tstruct->get_program()) << tstruct->get_name()
|
||||
<< ".prototype.read = function(input) {" << endl;
|
||||
if (gen_es6_) {
|
||||
indent(out) << "read (input) {" << endl;
|
||||
} else {
|
||||
indent(out) << js_namespace(tstruct->get_program()) << tstruct->get_name()
|
||||
<< ".prototype.read = function(input) {" << endl;
|
||||
}
|
||||
|
||||
indent_up();
|
||||
|
||||
|
@ -945,7 +1001,12 @@ void t_js_generator::generate_js_struct_reader(ostream& out, t_struct* tstruct)
|
|||
indent(out) << "return;" << endl;
|
||||
|
||||
indent_down();
|
||||
out << indent() << "};" << endl << endl;
|
||||
|
||||
if (gen_es6_) {
|
||||
indent(out) << "}" << endl << endl;
|
||||
} else {
|
||||
indent(out) << "};" << endl << endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -956,8 +1017,12 @@ void t_js_generator::generate_js_struct_writer(ostream& out, t_struct* tstruct)
|
|||
const vector<t_field*>& fields = tstruct->get_members();
|
||||
vector<t_field*>::const_iterator f_iter;
|
||||
|
||||
out << js_namespace(tstruct->get_program()) << tstruct->get_name()
|
||||
<< ".prototype.write = function(output) {" << endl;
|
||||
if (gen_es6_) {
|
||||
indent(out) << "write (output) {" << endl;
|
||||
} else {
|
||||
indent(out) << js_namespace(tstruct->get_program()) << tstruct->get_name()
|
||||
<< ".prototype.write = function(output) {" << endl;
|
||||
}
|
||||
|
||||
indent_up();
|
||||
|
||||
|
@ -987,7 +1052,11 @@ void t_js_generator::generate_js_struct_writer(ostream& out, t_struct* tstruct)
|
|||
out << indent() << "return;" << endl;
|
||||
|
||||
indent_down();
|
||||
out << indent() << "};" << endl << endl;
|
||||
if (gen_es6_) {
|
||||
out << indent() << "}" << endl << endl;
|
||||
} else {
|
||||
out << indent() << "};" << endl << endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1018,6 +1087,39 @@ void t_js_generator::generate_service(t_service* tservice) {
|
|||
<< ".d.ts\" />" << endl;
|
||||
}
|
||||
f_service_ts_ << autogen_comment() << endl;
|
||||
if (gen_node_) {
|
||||
f_service_ts_ << ts_includes() << endl;
|
||||
f_service_ts_ << "import ttypes = require('./" + program_->get_name() + "_types');" << endl;
|
||||
// Generate type aliases
|
||||
// enum
|
||||
vector<t_enum*> const& enums = program_->get_enums();
|
||||
vector<t_enum*>::const_iterator e_iter;
|
||||
for (e_iter = enums.begin(); e_iter != enums.end(); ++e_iter) {
|
||||
f_service_ts_ << "import " << (*e_iter)->get_name() << " = ttypes."
|
||||
<< js_namespace(program_) << (*e_iter)->get_name() << endl;
|
||||
}
|
||||
// const
|
||||
vector<t_const*> const& consts = program_->get_consts();
|
||||
vector<t_const*>::const_iterator c_iter;
|
||||
for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
|
||||
f_service_ts_ << "import " << (*c_iter)->get_name() << " = ttypes."
|
||||
<< js_namespace(program_) << (*c_iter)->get_name() << endl;
|
||||
}
|
||||
// exception
|
||||
vector<t_struct*> const& exceptions = program_->get_xceptions();
|
||||
vector<t_struct*>::const_iterator x_iter;
|
||||
for (x_iter = exceptions.begin(); x_iter != exceptions.end(); ++x_iter) {
|
||||
f_service_ts_ << "import " << (*x_iter)->get_name() << " = ttypes."
|
||||
<< js_namespace(program_) << (*x_iter)->get_name() << endl;
|
||||
}
|
||||
// structs
|
||||
vector<t_struct*> const& structs = program_->get_structs();
|
||||
vector<t_struct*>::const_iterator s_iter;
|
||||
for (s_iter = structs.begin(); s_iter != structs.end(); ++s_iter) {
|
||||
f_service_ts_ << "import " << (*s_iter)->get_name() << " = ttypes."
|
||||
<< js_namespace(program_) << (*s_iter)->get_name() << endl;
|
||||
}
|
||||
}
|
||||
if (!ts_module_.empty()) {
|
||||
f_service_ts_ << "declare module " << ts_module_ << " {";
|
||||
}
|
||||
|
@ -1064,26 +1166,67 @@ void t_js_generator::generate_service_processor(t_service* tservice) {
|
|||
|
||||
if (gen_node_) {
|
||||
string prefix = has_js_namespace(tservice->get_program()) ? js_namespace(tservice->get_program()) : js_const_type_;
|
||||
f_service_ << prefix << service_name_ << "Processor = " << "exports.Processor = function(handler) {" << endl;
|
||||
f_service_ << prefix << service_name_ << "Processor = " << "exports.Processor";
|
||||
if (gen_ts_) {
|
||||
f_service_ts_ << endl << "declare class Processor ";
|
||||
if (tservice->get_extends() != NULL) {
|
||||
f_service_ts_ << "extends " << tservice->get_extends()->get_name() << "Processor ";
|
||||
}
|
||||
f_service_ts_ << "{" << endl;
|
||||
indent_up();
|
||||
f_service_ts_ << ts_indent() << "private _handler: Object;" << endl << endl;
|
||||
f_service_ts_ << ts_indent() << "constructor(handler: Object);" << endl;
|
||||
f_service_ts_ << ts_indent() << "process(input: Thrift.TJSONProtocol, output: Thrift.TJSONProtocol): void;" << endl;
|
||||
indent_down();
|
||||
}
|
||||
} else {
|
||||
f_service_ << js_namespace(tservice->get_program()) << service_name_ << "Processor = "
|
||||
<< "exports.Processor = function(handler) {" << endl;
|
||||
<< "exports.Processor";
|
||||
}
|
||||
|
||||
bool is_subclass_service = tservice->get_extends() != NULL;
|
||||
|
||||
// ES6 Constructor
|
||||
if (gen_es6_) {
|
||||
if (is_subclass_service) {
|
||||
f_service_ << " = class extends " << tservice->get_extends()->get_name() << "Processor {" << endl;
|
||||
} else {
|
||||
f_service_ << " = class {" << endl;
|
||||
}
|
||||
indent_up();
|
||||
indent(f_service_) << "constructor(handler) {" << endl;
|
||||
} else {
|
||||
f_service_ << " = function(handler) {" << endl;
|
||||
}
|
||||
|
||||
indent_up();
|
||||
if (gen_es6_ && is_subclass_service) {
|
||||
indent(f_service_) << "super(handler);" << endl;
|
||||
}
|
||||
indent(f_service_) << "this._handler = handler;" << endl;
|
||||
indent_down();
|
||||
f_service_ << "};" << endl;
|
||||
|
||||
if (tservice->get_extends() != NULL) {
|
||||
// Done with constructor
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << "}" << endl;
|
||||
} else {
|
||||
indent(f_service_) << "};" << endl;
|
||||
}
|
||||
|
||||
// ES5 service inheritance
|
||||
if (!gen_es6_ && is_subclass_service) {
|
||||
indent(f_service_) << "Thrift.inherits(" << js_namespace(tservice->get_program())
|
||||
<< service_name_ << "Processor, " << tservice->get_extends()->get_name()
|
||||
<< "Processor);" << endl;
|
||||
}
|
||||
|
||||
// Generate the server implementation
|
||||
indent(f_service_) << js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Processor.prototype.process = function(input, output) {" << endl;
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << "process (input, output) {" << endl;
|
||||
} else {
|
||||
indent(f_service_) << js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Processor.prototype.process = function(input, output) {" << endl;
|
||||
}
|
||||
|
||||
indent_up();
|
||||
|
||||
|
@ -1101,12 +1244,25 @@ void t_js_generator::generate_service_processor(t_service* tservice) {
|
|||
<< indent() << "}" << endl;
|
||||
|
||||
indent_down();
|
||||
f_service_ << "};" << endl;
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << "}" << endl;
|
||||
} else {
|
||||
indent(f_service_) << "};" << endl;
|
||||
}
|
||||
|
||||
// Generate the process subfunctions
|
||||
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
|
||||
generate_process_function(tservice, *f_iter);
|
||||
}
|
||||
|
||||
// Close off the processor class definition
|
||||
if (gen_es6_) {
|
||||
indent_down();
|
||||
indent(f_service_) << "};" << endl;
|
||||
}
|
||||
if (gen_node_ && gen_ts_) {
|
||||
f_service_ts_ << "}" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1115,9 +1271,18 @@ void t_js_generator::generate_service_processor(t_service* tservice) {
|
|||
* @param tfunction The function to write a dispatcher for
|
||||
*/
|
||||
void t_js_generator::generate_process_function(t_service* tservice, t_function* tfunction) {
|
||||
indent(f_service_) << js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Processor.prototype.process_" + tfunction->get_name()
|
||||
+ " = function(seqid, input, output) {" << endl;
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << "process_" + tfunction->get_name() + " (seqid, input, output) {" << endl;
|
||||
} else {
|
||||
indent(f_service_) << js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Processor.prototype.process_" + tfunction->get_name()
|
||||
+ " = function(seqid, input, output) {" << endl;
|
||||
}
|
||||
if (gen_ts_) {
|
||||
indent_up();
|
||||
f_service_ts_ << ts_indent() << "process_" << tfunction->get_name() << "(seqid: number, input: Thrift.TJSONProtocol, output: Thrift.TJSONProtocol): void;" << endl;
|
||||
indent_down();
|
||||
}
|
||||
|
||||
indent_up();
|
||||
|
||||
|
@ -1149,10 +1314,16 @@ void t_js_generator::generate_process_function(t_service* tservice, t_function*
|
|||
|
||||
f_service_ << ");" << endl;
|
||||
indent_down();
|
||||
f_service_ << "};" << endl;
|
||||
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << "}" << endl;
|
||||
} else {
|
||||
indent(f_service_) << "};" << endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Promise style invocation
|
||||
indent(f_service_) << "if (this._handler." << tfunction->get_name()
|
||||
<< ".length === " << fields.size() << ") {" << endl;
|
||||
indent_up();
|
||||
|
@ -1173,7 +1344,7 @@ void t_js_generator::generate_process_function(t_service* tservice, t_function*
|
|||
indent_down();
|
||||
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << ")).then(function(result) {" << endl;
|
||||
indent(f_service_) << ")).then(result => {" << endl;
|
||||
} else {
|
||||
indent(f_service_) << ").then(function(result) {" << endl;
|
||||
}
|
||||
|
@ -1186,7 +1357,11 @@ void t_js_generator::generate_process_function(t_service* tservice, t_function*
|
|||
<< indent() << "output.flush();" << endl;
|
||||
indent_down();
|
||||
|
||||
indent(f_service_) << "}).catch(function (err) {" << endl;
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << "}).catch(err => {" << endl;
|
||||
} else {
|
||||
indent(f_service_) << "}).catch(function (err) {" << endl;
|
||||
}
|
||||
indent_up();
|
||||
indent(f_service_) << js_let_type_ << "result;" << endl;
|
||||
|
||||
|
@ -1236,6 +1411,9 @@ void t_js_generator::generate_process_function(t_service* tservice, t_function*
|
|||
indent_down();
|
||||
indent(f_service_) << "});" << endl;
|
||||
indent_down();
|
||||
// End promise style invocation
|
||||
|
||||
// Callback style invocation
|
||||
indent(f_service_) << "} else {" << endl;
|
||||
indent_up();
|
||||
indent(f_service_) << "this._handler." << tfunction->get_name() << "(";
|
||||
|
@ -1244,7 +1422,11 @@ void t_js_generator::generate_process_function(t_service* tservice, t_function*
|
|||
f_service_ << "args." << (*f_iter)->get_name() << ", ";
|
||||
}
|
||||
|
||||
f_service_ << "function (err, result) {" << endl;
|
||||
if (gen_es6_) {
|
||||
f_service_ << "(err, result) => {" << endl;
|
||||
} else {
|
||||
f_service_ << "function (err, result) {" << endl;
|
||||
}
|
||||
indent_up();
|
||||
indent(f_service_) << js_let_type_ << "result_obj;" << endl;
|
||||
|
||||
|
@ -1279,8 +1461,15 @@ void t_js_generator::generate_process_function(t_service* tservice, t_function*
|
|||
indent(f_service_) << "});" << endl;
|
||||
indent_down();
|
||||
indent(f_service_) << "}" << endl;
|
||||
// End callback style invocation
|
||||
|
||||
indent_down();
|
||||
indent(f_service_) << "};" << endl;
|
||||
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << "}" << endl;
|
||||
} else {
|
||||
indent(f_service_) << "};" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1354,33 +1543,73 @@ void t_js_generator::generate_service_rest(t_service* tservice) {
|
|||
* @param tservice The service to generate a server for.
|
||||
*/
|
||||
void t_js_generator::generate_service_client(t_service* tservice) {
|
||||
|
||||
bool is_subclass_service = tservice->get_extends() != NULL;
|
||||
|
||||
if (gen_node_) {
|
||||
string prefix = has_js_namespace(tservice->get_program()) ? js_namespace(tservice->get_program()) : js_const_type_;
|
||||
f_service_ << prefix << service_name_ << "Client = "
|
||||
<< "exports.Client = function(output, pClass) {" << endl;
|
||||
f_service_ << prefix << service_name_ << "Client = " << "exports.Client";
|
||||
if (gen_ts_) {
|
||||
f_service_ts_ << ts_print_doc(tservice) << ts_indent() << ts_declare() << "class "
|
||||
<< "Client ";
|
||||
if (tservice->get_extends() != NULL) {
|
||||
f_service_ts_ << "extends " << tservice->get_extends()->get_name() << "Client ";
|
||||
}
|
||||
f_service_ts_ << "{" << endl;
|
||||
}
|
||||
} else {
|
||||
f_service_ << js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Client = function(input, output) {" << endl;
|
||||
<< "Client";
|
||||
if (gen_ts_) {
|
||||
f_service_ts_ << ts_print_doc(tservice) << ts_indent() << ts_declare() << "class "
|
||||
<< service_name_ << "Client ";
|
||||
if (tservice->get_extends() != NULL) {
|
||||
if (is_subclass_service) {
|
||||
f_service_ts_ << "extends " << tservice->get_extends()->get_name() << "Client ";
|
||||
}
|
||||
f_service_ts_ << "{" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// ES6 Constructor
|
||||
if (gen_es6_) {
|
||||
if (is_subclass_service) {
|
||||
f_service_ << " = class extends " << js_namespace(tservice->get_extends()->get_program())
|
||||
<< tservice->get_extends()->get_name() << "Client {" << endl;
|
||||
} else {
|
||||
f_service_ << " = class {" << endl;
|
||||
}
|
||||
indent_up();
|
||||
if (gen_node_) {
|
||||
indent(f_service_) << "constructor(output, pClass) {" << endl;
|
||||
} else {
|
||||
indent(f_service_) << "constructor(input, output) {" << endl;
|
||||
}
|
||||
} else {
|
||||
if (gen_node_) {
|
||||
f_service_ << " = function(output, pClass) {" << endl;
|
||||
} else {
|
||||
f_service_ << " = function(input, output) {" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
indent_up();
|
||||
|
||||
if (gen_node_) {
|
||||
f_service_ << indent() << " this.output = output;" << endl << indent()
|
||||
<< " this.pClass = pClass;" << endl << indent() << " this._seqid = 0;" << endl
|
||||
<< indent() << " this._reqs = {};" << endl;
|
||||
indent(f_service_) << "this.output = output;" << endl;
|
||||
indent(f_service_) << "this.pClass = pClass;" << endl;
|
||||
indent(f_service_) << "this._seqid = 0;" << endl;
|
||||
indent(f_service_) << "this._reqs = {};" << endl;
|
||||
if (gen_ts_) {
|
||||
f_service_ts_ << ts_indent() << "private input: Thrift.TJSONProtocol;" << endl << ts_indent()
|
||||
<< "private output: Thrift.TJSONProtocol;" << endl << ts_indent() << "private seqid: number;"
|
||||
<< endl << endl << ts_indent()
|
||||
<< "constructor(input: Thrift.TJSONProtocol, output?: Thrift.TJSONProtocol);"
|
||||
<< endl;
|
||||
}
|
||||
} else {
|
||||
f_service_ << indent() << " this.input = input;" << endl << indent()
|
||||
<< " this.output = (!output) ? input : output;" << endl << indent()
|
||||
<< " this.seqid = 0;" << endl;
|
||||
indent(f_service_) << "this.input = input;" << endl;
|
||||
indent(f_service_) << "this.output = (!output) ? input : output;" << endl;
|
||||
indent(f_service_) << "this.seqid = 0;" << endl;
|
||||
if (gen_ts_) {
|
||||
f_service_ts_ << ts_indent() << "input: Thrift.TJSONProtocol;" << endl << ts_indent()
|
||||
<< "output: Thrift.TJSONProtocol;" << endl << ts_indent() << "seqid: number;"
|
||||
|
@ -1392,27 +1621,36 @@ void t_js_generator::generate_service_client(t_service* tservice) {
|
|||
|
||||
indent_down();
|
||||
|
||||
f_service_ << indent() << "};" << endl;
|
||||
|
||||
if (tservice->get_extends() != NULL) {
|
||||
indent(f_service_) << "Thrift.inherits(" << js_namespace(tservice->get_program())
|
||||
<< service_name_ << "Client, "
|
||||
<< js_namespace(tservice->get_extends()->get_program())
|
||||
<< tservice->get_extends()->get_name() << "Client);" << endl;
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << "}" << endl;
|
||||
} else {
|
||||
// init prototype
|
||||
indent(f_service_) << js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Client.prototype = {};" << endl;
|
||||
indent(f_service_) << "};" << endl;
|
||||
if (is_subclass_service) {
|
||||
indent(f_service_) << "Thrift.inherits(" << js_namespace(tservice->get_program())
|
||||
<< service_name_ << "Client, "
|
||||
<< js_namespace(tservice->get_extends()->get_program())
|
||||
<< tservice->get_extends()->get_name() << "Client);" << endl;
|
||||
} else {
|
||||
// init prototype
|
||||
indent(f_service_) << js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Client.prototype = {};" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// utils for multiplexed services
|
||||
if (gen_node_) {
|
||||
indent(f_service_) << js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Client.prototype.seqid = function() { return this._seqid; };" << endl
|
||||
<< js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Client.prototype.new_seqid = function() { return this._seqid += 1; };"
|
||||
<< endl;
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << "seqid () { return this._seqid; }" << endl;
|
||||
indent(f_service_) << "new_seqid () { return this._seqid += 1; }" << endl;
|
||||
} else {
|
||||
indent(f_service_) << js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Client.prototype.seqid = function() { return this._seqid; };" << endl
|
||||
<< js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Client.prototype.new_seqid = function() { return this._seqid += 1; };"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate client method implementations
|
||||
vector<t_function*> functions = tservice->get_functions();
|
||||
vector<t_function*>::const_iterator f_iter;
|
||||
|
@ -1424,42 +1662,41 @@ void t_js_generator::generate_service_client(t_service* tservice) {
|
|||
string arglist = argument_list(arg_struct);
|
||||
|
||||
// Open function
|
||||
f_service_ << js_namespace(tservice->get_program()) << service_name_ << "Client.prototype."
|
||||
<< function_signature(*f_iter, "", !gen_es6_) << " {" << endl;
|
||||
f_service_ << endl;
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << funname << " (" << arglist << ") {" << endl;
|
||||
} else {
|
||||
indent(f_service_) << js_namespace(tservice->get_program()) << service_name_ << "Client.prototype."
|
||||
<< function_signature(*f_iter, "", !gen_es6_) << " {" << endl;
|
||||
}
|
||||
|
||||
indent_up();
|
||||
|
||||
if (gen_ts_) {
|
||||
// function definition without callback
|
||||
f_service_ts_ << ts_print_doc(*f_iter) << ts_indent() << ts_function_signature(*f_iter, false) << endl;
|
||||
|
||||
f_service_ts_ << ts_print_doc(*f_iter) << ts_indent() << ts_function_signature(*f_iter, false, false) << endl;
|
||||
if (!gen_es6_) {
|
||||
// overload with callback
|
||||
f_service_ts_ << ts_print_doc(*f_iter) << ts_indent() << ts_function_signature(*f_iter, true) << endl;
|
||||
f_service_ts_ << ts_print_doc(*f_iter) << ts_indent() << ts_function_signature(*f_iter, true, false) << endl;
|
||||
} else {
|
||||
// overload with callback
|
||||
f_service_ts_ << ts_print_doc(*f_iter) << ts_indent() << ts_function_signature(*f_iter, true, true) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (gen_es6_ && gen_node_) {
|
||||
f_service_ << indent() << "this._seqid = this.new_seqid();" << endl;
|
||||
f_service_ << indent() << js_const_type_ << "self = this;" << endl << indent()
|
||||
<< "return new Promise(function(resolve, reject) {" << endl;
|
||||
indent(f_service_) << "this._seqid = this.new_seqid();" << endl;
|
||||
indent(f_service_) << js_const_type_ << "self = this;" << endl << indent()
|
||||
<< "return new Promise((resolve, reject) => {" << endl;
|
||||
indent_up();
|
||||
f_service_ << indent() << "self._reqs[self.seqid()] = function(error, result) {" << endl;
|
||||
indent(f_service_) << "self._reqs[self.seqid()] = (error, result) => {" << endl;
|
||||
indent_up();
|
||||
indent(f_service_) << "if (error) {" << endl;
|
||||
indent_up();
|
||||
indent(f_service_) << "reject(error);" << endl;
|
||||
indent_down();
|
||||
indent(f_service_) << "} else {" << endl;
|
||||
indent_up();
|
||||
indent(f_service_) << "resolve(result);" << endl;
|
||||
indent_down();
|
||||
indent(f_service_) << "}" << endl;
|
||||
indent(f_service_) << "return error ? reject(error) : resolve(result);" << endl;
|
||||
indent_down();
|
||||
indent(f_service_) << "};" << endl;
|
||||
f_service_ << indent() << "self.send_" << funname << "(" << arglist << ");" << endl;
|
||||
indent(f_service_) << "self.send_" << funname << "(" << arglist << ");" << endl;
|
||||
indent_down();
|
||||
f_service_ << indent() << "});" << endl;
|
||||
indent(f_service_) << "});" << endl;
|
||||
} else if (gen_node_) { // Node.js output ./gen-nodejs
|
||||
f_service_ << indent() << "this._seqid = this.new_seqid();" << endl << indent()
|
||||
<< "if (callback === undefined) {" << endl;
|
||||
|
@ -1489,16 +1726,12 @@ void t_js_generator::generate_service_client(t_service* tservice) {
|
|||
indent(f_service_) << "}" << endl;
|
||||
} else if (gen_es6_) {
|
||||
f_service_ << indent() << js_const_type_ << "self = this;" << endl << indent()
|
||||
<< "return new Promise(function(resolve, reject) {" << endl;
|
||||
<< "return new Promise((resolve, reject) => {" << endl;
|
||||
indent_up();
|
||||
f_service_ << indent() << "self.send_" << funname << "(" << arglist
|
||||
<< (arglist.empty() ? "" : ", ") << "function(error, result) {" << endl;
|
||||
<< (arglist.empty() ? "" : ", ") << "(error, result) => {" << endl;
|
||||
indent_up();
|
||||
f_service_ << indent() << "if (error) {" << endl;
|
||||
f_service_ << indent() << " reject(error);" << endl;
|
||||
f_service_ << indent() << "} else {" << endl;
|
||||
f_service_ << indent() << " resolve(result);" << endl;
|
||||
f_service_ << indent() << "}" << endl;
|
||||
indent(f_service_) << "return error ? reject(error) : resolve(result);" << endl;
|
||||
indent_down();
|
||||
f_service_ << indent() << "});" << endl;
|
||||
indent_down();
|
||||
|
@ -1543,11 +1776,24 @@ void t_js_generator::generate_service_client(t_service* tservice) {
|
|||
|
||||
indent_down();
|
||||
|
||||
f_service_ << "};" << endl << endl;
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << "}" << endl << endl;
|
||||
} else {
|
||||
indent(f_service_) << "};" << endl << endl;
|
||||
}
|
||||
|
||||
// Send function
|
||||
f_service_ << js_namespace(tservice->get_program()) << service_name_ << "Client.prototype.send_"
|
||||
<< function_signature(*f_iter, "", !gen_node_) << " {" << endl;
|
||||
if (gen_es6_) {
|
||||
if (gen_node_) {
|
||||
indent(f_service_) << "send_" << funname << " (" << arglist << ") {" << endl;
|
||||
} else {
|
||||
// ES6 js still uses callbacks here. Should refactor this to promise style later..
|
||||
indent(f_service_) << "send_" << funname << " (" << argument_list(arg_struct, true) << ") {" << endl;
|
||||
}
|
||||
} else {
|
||||
indent(f_service_) << js_namespace(tservice->get_program()) << service_name_ << "Client.prototype.send_"
|
||||
<< function_signature(*f_iter, "", !gen_node_) << " {" << endl;
|
||||
}
|
||||
|
||||
indent_up();
|
||||
|
||||
|
@ -1567,23 +1813,25 @@ void t_js_generator::generate_service_client(t_service* tservice) {
|
|||
// Build args
|
||||
if (fields.size() > 0){
|
||||
f_service_ << indent() << js_const_type_ << "params = {" << endl;
|
||||
indent_up();
|
||||
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
|
||||
f_service_ << indent() << indent() << (*fld_iter)->get_name() << ": " << (*fld_iter)->get_name();
|
||||
indent(f_service_) << (*fld_iter)->get_name() << ": " << (*fld_iter)->get_name();
|
||||
if (fld_iter != fields.end()-1) {
|
||||
f_service_ << "," << endl;
|
||||
} else {
|
||||
f_service_ << endl;
|
||||
}
|
||||
}
|
||||
f_service_ << indent() << "};" << endl;
|
||||
f_service_ << indent() << js_const_type_ << "args = new " << argsname << "(params);" << endl;
|
||||
indent_down();
|
||||
indent(f_service_) << "};" << endl;
|
||||
indent(f_service_) << js_const_type_ << "args = new " << argsname << "(params);" << endl;
|
||||
} else {
|
||||
f_service_ << indent() << js_const_type_ << "args = new " << argsname << "();" << endl;
|
||||
indent(f_service_) << js_const_type_ << "args = new " << argsname << "();" << endl;
|
||||
}
|
||||
|
||||
|
||||
// Serialize the request header within try/catch
|
||||
f_service_ << indent() << "try {" << endl;
|
||||
indent(f_service_) << "try {" << endl;
|
||||
indent_up();
|
||||
|
||||
if (gen_node_) {
|
||||
|
@ -1617,7 +1865,7 @@ void t_js_generator::generate_service_client(t_service* tservice) {
|
|||
f_service_ << indent() << "this.output.getTransport().flush(true, null);" << endl;
|
||||
f_service_ << indent() << "callback();" << endl;
|
||||
} else {
|
||||
f_service_ << indent() << "this.output.getTransport().flush(true, function() {" << endl;
|
||||
f_service_ << indent() << "this.output.getTransport().flush(true, () => {" << endl;
|
||||
indent_up();
|
||||
f_service_ << indent() << js_let_type_ << "error = null, result = null;" << endl;
|
||||
f_service_ << indent() << "try {" << endl;
|
||||
|
@ -1627,7 +1875,7 @@ void t_js_generator::generate_service_client(t_service* tservice) {
|
|||
f_service_ << indent() << "}" << endl;
|
||||
f_service_ << indent() << "callback(error, result);" << endl;
|
||||
indent_down();
|
||||
f_service_ << indent() << "});";
|
||||
f_service_ << indent() << "});" << endl;
|
||||
}
|
||||
} else {
|
||||
f_service_ << indent() << "if (callback) {" << endl;
|
||||
|
@ -1678,26 +1926,40 @@ void t_js_generator::generate_service_client(t_service* tservice) {
|
|||
|
||||
indent_down();
|
||||
|
||||
f_service_ << "};" << endl;
|
||||
// Close send function
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << "}" << endl;
|
||||
} else {
|
||||
indent(f_service_) << "};" << endl;
|
||||
}
|
||||
|
||||
// Receive function
|
||||
if (!(*f_iter)->is_oneway()) {
|
||||
std::string resultname = js_namespace(tservice->get_program()) + service_name_ + "_"
|
||||
+ (*f_iter)->get_name() + "_result";
|
||||
|
||||
f_service_ << endl;
|
||||
// Open receive function
|
||||
if (gen_node_) {
|
||||
// Open function
|
||||
f_service_ << endl << js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Client.prototype.recv_" << (*f_iter)->get_name()
|
||||
<< " = function(input,mtype,rseqid) {" << endl;
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << "recv_" << (*f_iter)->get_name() << " (input, mtype, rseqid) {" << endl;
|
||||
} else {
|
||||
indent(f_service_) << js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Client.prototype.recv_" << (*f_iter)->get_name()
|
||||
<< " = function(input,mtype,rseqid) {" << endl;
|
||||
}
|
||||
} else {
|
||||
t_struct noargs(program_);
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << "recv_" << (*f_iter)->get_name() << " () {" << endl;
|
||||
} else {
|
||||
t_struct noargs(program_);
|
||||
|
||||
t_function recv_function((*f_iter)->get_returntype(),
|
||||
string("recv_") + (*f_iter)->get_name(),
|
||||
&noargs);
|
||||
// Open function
|
||||
f_service_ << endl << js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Client.prototype." << function_signature(&recv_function) << " {" << endl;
|
||||
t_function recv_function((*f_iter)->get_returntype(),
|
||||
string("recv_") + (*f_iter)->get_name(),
|
||||
&noargs);
|
||||
indent(f_service_) << js_namespace(tservice->get_program()) << service_name_
|
||||
<< "Client.prototype." << function_signature(&recv_function) << " {" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
indent_up();
|
||||
|
@ -1755,15 +2017,24 @@ void t_js_generator::generate_service_client(t_service* tservice) {
|
|||
}
|
||||
}
|
||||
|
||||
// Close function
|
||||
// Close receive function
|
||||
indent_down();
|
||||
f_service_ << "};" << endl;
|
||||
if (gen_es6_) {
|
||||
indent(f_service_) << "}" << endl;
|
||||
} else {
|
||||
indent(f_service_) << "};" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Finish class definitions
|
||||
if (gen_ts_) {
|
||||
f_service_ts_ << ts_indent() << "}" << endl;
|
||||
}
|
||||
if (gen_es6_) {
|
||||
indent_down();
|
||||
f_service_ << "};" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::string t_js_generator::render_recv_throw(std::string var) {
|
||||
|
@ -2351,7 +2622,7 @@ string t_js_generator::ts_get_type(t_type* type) {
|
|||
* @param bool in-/exclude the callback argument
|
||||
* @return String of rendered function definition
|
||||
*/
|
||||
std::string t_js_generator::ts_function_signature(t_function* tfunction, bool include_callback) {
|
||||
std::string t_js_generator::ts_function_signature(t_function* tfunction, bool include_callback, bool optional_callback) {
|
||||
string str;
|
||||
const vector<t_field*>& fields = tfunction->get_arglist()->get_members();
|
||||
vector<t_field*>::const_iterator f_iter;
|
||||
|
@ -2367,7 +2638,29 @@ std::string t_js_generator::ts_function_signature(t_function* tfunction, bool in
|
|||
}
|
||||
|
||||
if (include_callback) {
|
||||
str += "callback: (data: " + ts_get_type(tfunction->get_returntype()) + ")=>void): ";
|
||||
string callback_optional_string = optional_callback ? "?" : "";
|
||||
if (gen_node_) {
|
||||
t_struct* exceptions = tfunction->get_xceptions();
|
||||
string exception_types;
|
||||
if (exceptions) {
|
||||
const vector<t_field*>& members = exceptions->get_members();
|
||||
for (vector<t_field*>::const_iterator it = members.begin(); it != members.end(); ++it) {
|
||||
t_type* t = get_true_type((*it)->get_type());
|
||||
if (it == members.begin()) {
|
||||
exception_types = t->get_name();
|
||||
} else {
|
||||
exception_types += " | " + t->get_name();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (exception_types == "") {
|
||||
str += "callback" + callback_optional_string + ": (error: void, response: " + ts_get_type(tfunction->get_returntype()) + ")=>void): ";
|
||||
} else {
|
||||
str += "callback" + callback_optional_string + ": (error: " + exception_types + ", response: " + ts_get_type(tfunction->get_returntype()) + ")=>void): ";
|
||||
}
|
||||
} else {
|
||||
str += "callback" + callback_optional_string + ": (data: " + ts_get_type(tfunction->get_returntype()) + ")=>void): ";
|
||||
}
|
||||
|
||||
if (gen_jquery_) {
|
||||
str += "JQueryPromise<" + ts_get_type(tfunction->get_returntype()) +">;";
|
||||
|
|
20
vendor/git.apache.org/thrift.git/compiler/cpp/src/thrift/generate/t_perl_generator.cc
generated
vendored
20
vendor/git.apache.org/thrift.git/compiler/cpp/src/thrift/generate/t_perl_generator.cc
generated
vendored
|
@ -354,7 +354,7 @@ string t_perl_generator::render_const_value(t_type* type, t_const_value* value)
|
|||
} else if (type->is_enum()) {
|
||||
out << value->get_integer();
|
||||
} else if (type->is_struct() || type->is_xception()) {
|
||||
out << "new " << perl_namespace(type->get_program()) << type->get_name() << "({" << endl;
|
||||
out << perl_namespace(type->get_program()) << type->get_name() << "->new({" << endl;
|
||||
indent_up();
|
||||
|
||||
const vector<t_field*>& fields = ((t_struct*)type)->get_members();
|
||||
|
@ -546,7 +546,7 @@ void t_perl_generator::generate_perl_struct_reader(ostream& out, t_struct* tstru
|
|||
indent(out) << "$xfer += $input->readStructBegin(\\$fname);" << endl;
|
||||
|
||||
// Loop over reading in fields
|
||||
indent(out) << "while (1) " << endl;
|
||||
indent(out) << "while (1)" << endl;
|
||||
|
||||
scope_up(out);
|
||||
|
||||
|
@ -758,7 +758,7 @@ void t_perl_generator::generate_service_processor(t_service* tservice) {
|
|||
|
||||
f_service_ << indent() << "$input->skip(Thrift::TType::STRUCT);" << endl << indent()
|
||||
<< "$input->readMessageEnd();" << endl << indent()
|
||||
<< "my $x = new Thrift::TApplicationException('Function '.$fname.' not implemented.', "
|
||||
<< "my $x = Thrift::TApplicationException->new('Function '.$fname.' not implemented.', "
|
||||
"Thrift::TApplicationException::UNKNOWN_METHOD);" << endl << indent()
|
||||
<< "$output->writeMessageBegin($fname, Thrift::TMessageType::EXCEPTION, $rseqid);" << endl
|
||||
<< indent() << "$x->write($output);" << endl << indent()
|
||||
|
@ -798,7 +798,7 @@ void t_perl_generator::generate_process_function(t_service* tservice, t_function
|
|||
string resultname = perl_namespace(tservice->get_program()) + service_name_ + "_"
|
||||
+ tfunction->get_name() + "_result";
|
||||
|
||||
f_service_ << indent() << "my $args = new " << argsname << "();" << endl << indent()
|
||||
f_service_ << indent() << "my $args = " << argsname << "->new();" << endl << indent()
|
||||
<< "$args->read($input);" << endl;
|
||||
|
||||
f_service_ << indent() << "$input->readMessageEnd();" << endl;
|
||||
|
@ -809,7 +809,7 @@ void t_perl_generator::generate_process_function(t_service* tservice, t_function
|
|||
|
||||
// Declare result for non oneway function
|
||||
if (!tfunction->is_oneway()) {
|
||||
f_service_ << indent() << "my $result = new " << resultname << "();" << endl;
|
||||
f_service_ << indent() << "my $result = " << resultname << "->new();" << endl;
|
||||
}
|
||||
|
||||
// Try block for a function with exceptions
|
||||
|
@ -858,7 +858,7 @@ void t_perl_generator::generate_process_function(t_service* tservice, t_function
|
|||
f_service_ << indent() << "if ($@) {" << endl;
|
||||
indent_up();
|
||||
f_service_ << indent() << "$@ =~ s/^\\s+|\\s+$//g;" << endl
|
||||
<< indent() << "my $err = new Thrift::TApplicationException(\"Unexpected Exception: \" . $@, Thrift::TApplicationException::INTERNAL_ERROR);" << endl
|
||||
<< indent() << "my $err = Thrift::TApplicationException->new(\"Unexpected Exception: \" . $@, Thrift::TApplicationException::INTERNAL_ERROR);" << endl
|
||||
<< indent() << "$output->writeMessageBegin('" << tfunction->get_name() << "', Thrift::TMessageType::EXCEPTION, $seqid);" << endl
|
||||
<< indent() << "$err->write($output);" << endl
|
||||
<< indent() << "$output->writeMessageEnd();" << endl
|
||||
|
@ -1106,7 +1106,7 @@ void t_perl_generator::generate_service_client(t_service* tservice) {
|
|||
<< "', " << ((*f_iter)->is_oneway() ? "Thrift::TMessageType::ONEWAY" : "Thrift::TMessageType::CALL")
|
||||
<< ", $self->{seqid});" << endl;
|
||||
|
||||
f_service_ << indent() << "my $args = new " << argsname << "();" << endl;
|
||||
f_service_ << indent() << "my $args = " << argsname << "->new();" << endl;
|
||||
|
||||
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
|
||||
f_service_ << indent() << "$args->{" << (*fld_iter)->get_name() << "} = $"
|
||||
|
@ -1140,12 +1140,12 @@ void t_perl_generator::generate_service_client(t_service* tservice) {
|
|||
|
||||
f_service_ << indent() << "$self->{input}->readMessageBegin(\\$fname, \\$mtype, \\$rseqid);"
|
||||
<< endl << indent() << "if ($mtype == Thrift::TMessageType::EXCEPTION) {" << endl
|
||||
<< indent() << " my $x = new Thrift::TApplicationException();" << endl << indent()
|
||||
<< indent() << " my $x = Thrift::TApplicationException->new();" << endl << indent()
|
||||
<< " $x->read($self->{input});" << endl << indent()
|
||||
<< " $self->{input}->readMessageEnd();" << endl << indent() << " die $x;" << endl
|
||||
<< indent() << "}" << endl;
|
||||
|
||||
f_service_ << indent() << "my $result = new " << resultname << "();" << endl << indent()
|
||||
f_service_ << indent() << "my $result = " << resultname << "->new();" << endl << indent()
|
||||
<< "$result->read($self->{input});" << endl;
|
||||
|
||||
f_service_ << indent() << "$self->{input}->readMessageEnd();" << endl << endl;
|
||||
|
@ -1586,7 +1586,7 @@ string t_perl_generator::declare_field(t_field* tfield, bool init, bool obj) {
|
|||
result += " = []";
|
||||
} else if (type->is_struct() || type->is_xception()) {
|
||||
if (obj) {
|
||||
result += " = new " + perl_namespace(type->get_program()) + type->get_name() + "()";
|
||||
result += " = " + perl_namespace(type->get_program()) + type->get_name() + "->new()";
|
||||
} else {
|
||||
result += " = undef";
|
||||
}
|
||||
|
|
6
vendor/git.apache.org/thrift.git/compiler/cpp/src/thrift/generate/t_py_generator.cc
generated
vendored
6
vendor/git.apache.org/thrift.git/compiler/cpp/src/thrift/generate/t_py_generator.cc
generated
vendored
|
@ -1961,8 +1961,10 @@ void t_py_generator::generate_process_function(t_service* tservice, t_function*
|
|||
indent(f_service_) << "def write_results_success_" << tfunction->get_name()
|
||||
<< "(self, success, result, seqid, oprot):" << endl;
|
||||
indent_up();
|
||||
f_service_ << indent() << "result.success = success" << endl
|
||||
<< indent() << "oprot.writeMessageBegin(\"" << tfunction->get_name()
|
||||
if (!tfunction->get_returntype()->is_void()) {
|
||||
f_service_ << indent() << "result.success = success" << endl;
|
||||
}
|
||||
f_service_ << indent() << "oprot.writeMessageBegin(\"" << tfunction->get_name()
|
||||
<< "\", TMessageType.REPLY, seqid)" << endl
|
||||
<< indent() << "result.write(oprot)" << endl
|
||||
<< indent() << "oprot.writeMessageEnd()" << endl
|
||||
|
|
89
vendor/git.apache.org/thrift.git/compiler/cpp/src/thrift/generate/t_rs_generator.cc
generated
vendored
89
vendor/git.apache.org/thrift.git/compiler/cpp/src/thrift/generate/t_rs_generator.cc
generated
vendored
|
@ -127,7 +127,7 @@ private:
|
|||
void render_const_value_holder(const string& name, t_type* ttype, t_const_value* tvalue);
|
||||
|
||||
// Write the actual const value - the right side of a const definition.
|
||||
void render_const_value(t_type* ttype, t_const_value* tvalue);
|
||||
void render_const_value(t_type* ttype, t_const_value* tvalue, bool is_owned = true);
|
||||
|
||||
// Write a const struct (returned from `const_value` method).
|
||||
void render_const_struct(t_type* ttype, t_const_value* tvalue);
|
||||
|
@ -355,8 +355,8 @@ private:
|
|||
|
||||
string handler_successful_return_struct(t_function* tfunc);
|
||||
|
||||
// Writes the result of `render_rift_error_struct` wrapped in an `Err(thrift::Error(...))`.
|
||||
void render_rift_error(
|
||||
// Writes the result of `render_thrift_error_struct` wrapped in an `Err(thrift::Error(...))`.
|
||||
void render_thrift_error(
|
||||
const string& error_kind,
|
||||
const string& error_struct,
|
||||
const string& sub_error_kind,
|
||||
|
@ -377,7 +377,7 @@ private:
|
|||
// message: "This is some error message",
|
||||
// }
|
||||
// ```
|
||||
void render_rift_error_struct(
|
||||
void render_thrift_error_struct(
|
||||
const string& error_struct,
|
||||
const string& sub_error_kind,
|
||||
const string& error_message
|
||||
|
@ -411,6 +411,9 @@ private:
|
|||
// Return a string representing the rust type given a `t_type`.
|
||||
string to_rust_type(t_type* ttype, bool ordered_float = true);
|
||||
|
||||
// Return a string representing the `const` rust type given a `t_type`
|
||||
string to_rust_const_type(t_type* ttype, bool ordered_float = true);
|
||||
|
||||
// Return a string representing the rift `protocol::TType` given a `t_type`.
|
||||
string to_rust_field_type_enum(t_type* ttype);
|
||||
|
||||
|
@ -499,6 +502,9 @@ private:
|
|||
// the server half of a Thrift service.
|
||||
string rust_sync_processor_impl_name(t_service *tservice);
|
||||
|
||||
// Return the variant name for an enum variant
|
||||
string rust_enum_variant_name(const string& name);
|
||||
|
||||
// Properly uppercase names for use in Rust.
|
||||
string rust_upper_case(const string& name);
|
||||
|
||||
|
@ -645,8 +651,8 @@ void t_rs_generator::render_const_value(const string& name, t_type* ttype, t_con
|
|||
throw "cannot generate simple rust constant for " + ttype->get_name();
|
||||
}
|
||||
|
||||
f_gen_ << "pub const " << rust_upper_case(name) << ": " << to_rust_type(ttype) << " = ";
|
||||
render_const_value(ttype, tvalue);
|
||||
f_gen_ << "pub const " << rust_upper_case(name) << ": " << to_rust_const_type(ttype) << " = ";
|
||||
render_const_value(ttype, tvalue, false);
|
||||
f_gen_ << ";" << endl;
|
||||
f_gen_ << endl;
|
||||
}
|
||||
|
@ -673,15 +679,22 @@ void t_rs_generator::render_const_value_holder(const string& name, t_type* ttype
|
|||
f_gen_ << endl;
|
||||
}
|
||||
|
||||
void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue) {
|
||||
void t_rs_generator::render_const_value(t_type* ttype, t_const_value* tvalue, bool is_owned) {
|
||||
if (ttype->is_base_type()) {
|
||||
t_base_type* tbase_type = (t_base_type*)ttype;
|
||||
switch (tbase_type->get_base()) {
|
||||
case t_base_type::TYPE_STRING:
|
||||
if (tbase_type->is_binary()) {
|
||||
f_gen_ << "\"" << tvalue->get_string() << "\""<< ".to_owned().into_bytes()";
|
||||
if (is_owned) {
|
||||
f_gen_ << "\"" << tvalue->get_string() << "\""<< ".to_owned().into_bytes()";
|
||||
} else {
|
||||
f_gen_ << "b\"" << tvalue->get_string() << "\"";
|
||||
}
|
||||
} else {
|
||||
f_gen_ << "\"" << tvalue->get_string() << "\""<< ".to_owned()";
|
||||
f_gen_ << "\"" << tvalue->get_string() << "\"";
|
||||
if (is_owned) {
|
||||
f_gen_ << ".to_owned()";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case t_base_type::TYPE_BOOL:
|
||||
|
@ -873,7 +886,7 @@ void t_rs_generator::render_enum_definition(t_enum* tenum, const string& enum_na
|
|||
render_rustdoc((t_doc*) val);
|
||||
f_gen_
|
||||
<< indent()
|
||||
<< uppercase(val->get_name())
|
||||
<< rust_enum_variant_name(val->get_name())
|
||||
<< " = "
|
||||
<< val->get_value()
|
||||
<< ","
|
||||
|
@ -934,12 +947,12 @@ void t_rs_generator::render_enum_conversion(t_enum* tenum, const string& enum_na
|
|||
f_gen_
|
||||
<< indent()
|
||||
<< val->get_value()
|
||||
<< " => Ok(" << enum_name << "::" << uppercase(val->get_name()) << "),"
|
||||
<< " => Ok(" << enum_name << "::" << rust_enum_variant_name(val->get_name()) << "),"
|
||||
<< endl;
|
||||
}
|
||||
f_gen_ << indent() << "_ => {" << endl;
|
||||
indent_up();
|
||||
render_rift_error(
|
||||
render_thrift_error(
|
||||
"Protocol",
|
||||
"ProtocolError",
|
||||
"ProtocolErrorKind::InvalidData",
|
||||
|
@ -1320,7 +1333,7 @@ void t_rs_generator::render_result_struct_to_result_method(t_struct* tstruct) {
|
|||
indent_up();
|
||||
// if we haven't found a valid return value *or* a user exception
|
||||
// then we're in trouble; return a default error
|
||||
render_rift_error(
|
||||
render_thrift_error(
|
||||
"Application",
|
||||
"ApplicationError",
|
||||
"ApplicationErrorKind::MissingResult",
|
||||
|
@ -1854,7 +1867,7 @@ void t_rs_generator::render_union_sync_read(const string &union_name, t_struct *
|
|||
// return the value or an error
|
||||
f_gen_ << indent() << "if received_field_count == 0 {" << endl;
|
||||
indent_up();
|
||||
render_rift_error(
|
||||
render_thrift_error(
|
||||
"Protocol",
|
||||
"ProtocolError",
|
||||
"ProtocolErrorKind::InvalidData",
|
||||
|
@ -1863,7 +1876,7 @@ void t_rs_generator::render_union_sync_read(const string &union_name, t_struct *
|
|||
indent_down();
|
||||
f_gen_ << indent() << "} else if received_field_count > 1 {" << endl;
|
||||
indent_up();
|
||||
render_rift_error(
|
||||
render_thrift_error(
|
||||
"Protocol",
|
||||
"ProtocolError",
|
||||
"ProtocolErrorKind::InvalidData",
|
||||
|
@ -2565,7 +2578,7 @@ void t_rs_generator::render_sync_processor_definition_and_impl(t_service *tservi
|
|||
render_process_match_statements(tservice);
|
||||
f_gen_ << indent() << "method => {" << endl;
|
||||
indent_up();
|
||||
render_rift_error(
|
||||
render_thrift_error(
|
||||
"Application",
|
||||
"ApplicationError",
|
||||
"ApplicationErrorKind::UnknownMethod",
|
||||
|
@ -2844,7 +2857,7 @@ void t_rs_generator::render_sync_handler_failed_user_exception_branch(t_function
|
|||
|
||||
f_gen_ << indent() << "let ret_err = {" << endl;
|
||||
indent_up();
|
||||
render_rift_error_struct("ApplicationError", "ApplicationErrorKind::Unknown", "usr_err.description()");
|
||||
render_thrift_error_struct("ApplicationError", "ApplicationErrorKind::Unknown", "usr_err.description()");
|
||||
indent_down();
|
||||
f_gen_ << indent() << "};" << endl;
|
||||
render_sync_handler_send_exception_response(tfunc, "ret_err");
|
||||
|
@ -2867,7 +2880,7 @@ void t_rs_generator::render_sync_handler_failed_application_exception_branch(
|
|||
void t_rs_generator::render_sync_handler_failed_default_exception_branch(t_function *tfunc) {
|
||||
f_gen_ << indent() << "let ret_err = {" << endl;
|
||||
indent_up();
|
||||
render_rift_error_struct("ApplicationError", "ApplicationErrorKind::Unknown", "e.description()");
|
||||
render_thrift_error_struct("ApplicationError", "ApplicationErrorKind::Unknown", "e.description()");
|
||||
indent_down();
|
||||
f_gen_ << indent() << "};" << endl;
|
||||
if (tfunc->is_oneway()) {
|
||||
|
@ -2944,7 +2957,7 @@ void t_rs_generator::render_rustdoc(t_doc* tdoc) {
|
|||
generate_docstring_comment(f_gen_, "", "/// ", tdoc->get_doc(), "");
|
||||
}
|
||||
|
||||
void t_rs_generator::render_rift_error(
|
||||
void t_rs_generator::render_thrift_error(
|
||||
const string& error_kind,
|
||||
const string& error_struct,
|
||||
const string& sub_error_kind,
|
||||
|
@ -2954,14 +2967,14 @@ void t_rs_generator::render_rift_error(
|
|||
indent_up();
|
||||
f_gen_ << indent() << "thrift::Error::" << error_kind << "(" << endl;
|
||||
indent_up();
|
||||
render_rift_error_struct(error_struct, sub_error_kind, error_message);
|
||||
render_thrift_error_struct(error_struct, sub_error_kind, error_message);
|
||||
indent_down();
|
||||
f_gen_ << indent() << ")" << endl;
|
||||
indent_down();
|
||||
f_gen_ << indent() << ")" << endl;
|
||||
}
|
||||
|
||||
void t_rs_generator::render_rift_error_struct(
|
||||
void t_rs_generator::render_thrift_error_struct(
|
||||
const string& error_struct,
|
||||
const string& sub_error_kind,
|
||||
const string& error_message
|
||||
|
@ -3022,7 +3035,7 @@ string t_rs_generator::to_rust_type(t_type* ttype, bool ordered_float) {
|
|||
rust_type = ttypedef->is_forward_typedef() ? "Box<" + rust_type + ">" : rust_type;
|
||||
return rust_type;
|
||||
} else if (ttype->is_enum()) {
|
||||
return rust_namespace(ttype) + ttype->get_name();
|
||||
return rust_namespace(ttype) + rust_camel_case(ttype->get_name());
|
||||
} else if (ttype->is_struct() || ttype->is_xception()) {
|
||||
return rust_namespace(ttype) + rust_camel_case(ttype->get_name());
|
||||
} else if (ttype->is_map()) {
|
||||
|
@ -3039,6 +3052,21 @@ string t_rs_generator::to_rust_type(t_type* ttype, bool ordered_float) {
|
|||
throw "cannot find rust type for " + ttype->get_name();
|
||||
}
|
||||
|
||||
string t_rs_generator::to_rust_const_type(t_type* ttype, bool ordered_float) {
|
||||
if (ttype->is_base_type()) {
|
||||
t_base_type* tbase_type = ((t_base_type*)ttype);
|
||||
if (tbase_type->get_base() == t_base_type::TYPE_STRING) {
|
||||
if (tbase_type->is_binary()) {
|
||||
return "&[u8]";
|
||||
} else {
|
||||
return "&str";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return to_rust_type(ttype, ordered_float);
|
||||
}
|
||||
|
||||
string t_rs_generator::to_rust_field_type_enum(t_type* ttype) {
|
||||
ttype = get_true_type(ttype);
|
||||
if (ttype->is_base_type()) {
|
||||
|
@ -3254,6 +3282,23 @@ string t_rs_generator::rust_sync_processor_impl_name(t_service *tservice) {
|
|||
return "T" + rust_camel_case(tservice->get_name()) + "ProcessFunctions";
|
||||
}
|
||||
|
||||
string t_rs_generator::rust_enum_variant_name(const string &name) {
|
||||
bool all_uppercase = true;
|
||||
|
||||
for (size_t i = 0; i < name.size(); i++) {
|
||||
if (isalnum(name[i]) && islower(name[i])) {
|
||||
all_uppercase = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (all_uppercase) {
|
||||
return capitalize(camelcase(lowercase(name)));
|
||||
} else {
|
||||
return capitalize(camelcase(name));
|
||||
}
|
||||
}
|
||||
|
||||
string t_rs_generator::rust_upper_case(const string& name) {
|
||||
string str(uppercase(underscore(name)));
|
||||
string_replace(str, "__", "_");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue