You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by hc...@apache.org on 2014/11/18 11:34:18 UTC
[26/37] thrift git commit: Revert "THRIFT-2729: C++ - .clang-format
created and applied"
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/compiler/cpp/src/generate/t_haxe_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_haxe_generator.cc b/compiler/cpp/src/generate/t_haxe_generator.cc
index 504bea9..bd22e59 100644
--- a/compiler/cpp/src/generate/t_haxe_generator.cc
+++ b/compiler/cpp/src/generate/t_haxe_generator.cc
@@ -37,21 +37,23 @@ using std::string;
using std::stringstream;
using std::vector;
-static const string endl = "\n"; // avoid ostream << std::endl flushes
+static const string endl = "\n"; // avoid ostream << std::endl flushes
/**
* Haxe code generator.
*
*/
class t_haxe_generator : public t_oop_generator {
-public:
- t_haxe_generator(t_program* program,
- const std::map<std::string, std::string>& parsed_options,
- const std::string& option_string)
- : t_oop_generator(program) {
- (void)option_string;
+ public:
+ t_haxe_generator(
+ t_program* program,
+ const std::map<std::string, std::string>& parsed_options,
+ const std::string& option_string)
+ : t_oop_generator(program)
+ {
+ (void) option_string;
std::map<std::string, std::string>::const_iterator iter;
-
+
iter = parsed_options.find("callbacks");
callbacks_ = (iter != parsed_options.end());
@@ -71,22 +73,14 @@ public:
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
-
- void print_const_value(std::ofstream& out,
- std::string name,
- t_type* type,
- t_const_value* value,
- bool in_static,
- bool defval = false);
- std::string render_const_value(ofstream& out,
- std::string name,
- t_type* type,
- t_const_value* value);
+ void generate_typedef (t_typedef* ttypedef);
+ void generate_enum (t_enum* tenum);
+ void generate_struct (t_struct* tstruct);
+ void generate_xception(t_struct* txception);
+ void generate_service (t_service* tservice);
+
+ void print_const_value(std::ofstream& out, std::string name, t_type* type, t_const_value* value, bool in_static, bool defval=false);
+ std::string render_const_value(ofstream& out, std::string name, t_type* type, t_const_value* value);
/**
* Service-level generation functions
@@ -94,11 +88,8 @@ public:
void generate_haxe_struct(t_struct* tstruct, bool is_exception, bool is_result = false);
- void generate_haxe_struct_definition(std::ofstream& out,
- t_struct* tstruct,
- bool is_xception = false,
- bool is_result = false);
- // removed -- equality,compare_to
+ void generate_haxe_struct_definition(std::ofstream& out, t_struct* tstruct, bool is_xception=false, bool is_result=false);
+ //removed -- equality,compare_to
void generate_haxe_struct_reader(std::ofstream& out, t_struct* tstruct);
void generate_haxe_validator(std::ofstream& out, t_struct* tstruct);
void generate_haxe_struct_result_writer(std::ofstream& out, t_struct* tstruct);
@@ -107,14 +98,8 @@ public:
void generate_haxe_meta_data_map(std::ofstream& out, t_struct* tstruct);
void generate_field_value_meta_data(std::ofstream& out, t_type* type);
std::string get_haxe_type_string(t_type* type);
- void generate_reflection_setters(std::ostringstream& out,
- t_type* type,
- std::string field_name,
- std::string cap_name);
- void generate_reflection_getters(std::ostringstream& out,
- t_type* type,
- std::string field_name,
- std::string cap_name);
+ void generate_reflection_setters(std::ostringstream& out, t_type* type, std::string field_name, std::string cap_name);
+ void generate_reflection_getters(std::ostringstream& out, t_type* type, std::string field_name, std::string cap_name);
void generate_generic_field_getters_setters(std::ofstream& out, t_struct* tstruct);
void generate_generic_isset_method(std::ofstream& out, t_struct* tstruct);
void generate_property_getters_setters(std::ofstream& out, t_struct* tstruct);
@@ -124,51 +109,73 @@ public:
std::string generate_isset_check(t_field* field);
std::string generate_isset_check(std::string field);
void generate_isset_set(ofstream& out, t_field* field);
- // removed std::string isset_field_id(t_field* field);
-
- void generate_service_interface(t_service* tservice);
- void generate_service_helpers(t_service* tservice);
- void generate_service_client(t_service* tservice);
- void generate_service_server(t_service* tservice);
- void generate_process_function(t_service* tservice, t_function* tfunction);
+ //removed std::string isset_field_id(t_field* field);
+
+ void generate_service_interface (t_service* tservice);
+ void generate_service_helpers (t_service* tservice);
+ void generate_service_client (t_service* tservice);
+ void generate_service_server (t_service* tservice);
+ void generate_process_function (t_service* tservice, t_function* tfunction);
void generate_service_method_signature(t_function* tfunction, bool is_interface);
-
+
/**
* Serialization constructs
*/
- void generate_deserialize_field(std::ofstream& out, t_field* tfield, std::string prefix = "");
+ void generate_deserialize_field (std::ofstream& out,
+ t_field* tfield,
+ std::string prefix="");
- void generate_deserialize_struct(std::ofstream& out, t_struct* tstruct, std::string prefix = "");
+ void generate_deserialize_struct (std::ofstream& out,
+ t_struct* tstruct,
+ std::string prefix="");
- void generate_deserialize_container(std::ofstream& out, t_type* ttype, std::string prefix = "");
+ void generate_deserialize_container (std::ofstream& out,
+ t_type* ttype,
+ std::string prefix="");
- void generate_deserialize_set_element(std::ofstream& out, t_set* tset, std::string prefix = "");
+ void generate_deserialize_set_element (std::ofstream& out,
+ t_set* tset,
+ std::string prefix="");
- void generate_deserialize_map_element(std::ofstream& out, t_map* tmap, std::string prefix = "");
+ void generate_deserialize_map_element (std::ofstream& out,
+ t_map* tmap,
+ std::string prefix="");
- void generate_deserialize_list_element(std::ofstream& out,
- t_list* tlist,
- std::string prefix = "");
+ void generate_deserialize_list_element (std::ofstream& out,
+ t_list* tlist,
+ std::string prefix="");
- void generate_serialize_field(std::ofstream& out, t_field* tfield, std::string prefix = "");
+ void generate_serialize_field (std::ofstream& out,
+ t_field* tfield,
+ std::string prefix="");
- void generate_serialize_struct(std::ofstream& out, t_struct* tstruct, std::string prefix = "");
+ void generate_serialize_struct (std::ofstream& out,
+ t_struct* tstruct,
+ std::string prefix="");
- void generate_serialize_container(std::ofstream& out, t_type* ttype, std::string prefix = "");
+ void generate_serialize_container (std::ofstream& out,
+ t_type* ttype,
+ std::string prefix="");
- void generate_serialize_map_element(std::ofstream& out,
- t_map* tmap,
- std::string iter,
- std::string map);
+ void generate_serialize_map_element (std::ofstream& out,
+ t_map* tmap,
+ std::string iter,
+ std::string map);
- void generate_serialize_set_element(std::ofstream& out, t_set* tmap, std::string iter);
+ void generate_serialize_set_element (std::ofstream& out,
+ t_set* tmap,
+ std::string iter);
- void generate_serialize_list_element(std::ofstream& out, t_list* tlist, std::string iter);
+ void generate_serialize_list_element (std::ofstream& out,
+ t_list* tlist,
+ std::string iter);
- void generate_haxe_doc(std::ofstream& out, t_doc* tdoc);
+ void generate_haxe_doc (std::ofstream& out,
+ t_doc* tdoc);
- void generate_haxe_doc(std::ofstream& out, t_function* tdoc);
+ void generate_haxe_doc (std::ofstream& out,
+ t_function* tdoc);
/**
* Helper rendering functions
@@ -177,11 +184,11 @@ public:
std::string haxe_package();
std::string haxe_type_imports();
std::string haxe_thrift_imports();
- std::string haxe_thrift_gen_imports(t_struct* tstruct, string& imports);
- std::string haxe_thrift_gen_imports(t_service* tservice);
- std::string type_name(t_type* ttype, bool in_container = false, bool in_init = false);
- std::string base_type_name(t_base_type* tbase, bool in_container = false);
- std::string declare_field(t_field* tfield, bool init = false);
+ std::string haxe_thrift_gen_imports(t_struct* tstruct, string& imports);
+ std::string haxe_thrift_gen_imports(t_service* tservice);
+ std::string type_name(t_type* ttype, bool in_container=false, bool in_init=false);
+ std::string base_type_name(t_base_type* tbase, bool in_container=false);
+ std::string declare_field(t_field* tfield, bool init=false);
std::string function_signature_callback(t_function* tfunction);
std::string function_signature_normal(t_function* tfunction);
std::string argument_list(t_struct* tstruct);
@@ -214,9 +221,9 @@ public:
std::string constant_name(std::string name);
-private:
+ private:
bool callbacks_;
-
+
/**
* File streams
*/
@@ -224,8 +231,10 @@ private:
std::string package_name_;
std::ofstream f_service_;
std::string package_dir_;
+
};
+
/**
* Prepares for file generation by opening up the necessary file output
* streams.
@@ -255,7 +264,7 @@ void t_haxe_generator::init_generator() {
while ((loc = dir.find(".")) != string::npos) {
subdir = subdir + "/" + dir.substr(0, loc);
MKDIR(subdir.c_str());
- dir = dir.substr(loc + 1);
+ dir = dir.substr(loc+1);
}
if (dir.size() > 0) {
subdir = subdir + "/" + dir;
@@ -283,10 +292,18 @@ string t_haxe_generator::haxe_package() {
* @return List of imports for haxe types that are used in here
*/
string t_haxe_generator::haxe_type_imports() {
- return string() + "import org.apache.thrift.helper.*;\n" + "import haxe.io.Bytes;\n"
- + "import haxe.ds.IntMap;\n" + "import haxe.ds.StringMap;\n"
- + "import haxe.ds.ObjectMap;\n" + "\n" + "#if flash\n"
- + "import flash.errors.ArgumentError;\n" + "#end\n" + "\n";
+ return
+ string() +
+ "import org.apache.thrift.helper.*;\n" +
+ "import haxe.io.Bytes;\n" +
+ "import haxe.ds.IntMap;\n" +
+ "import haxe.ds.StringMap;\n" +
+ "import haxe.ds.ObjectMap;\n" +
+ "\n" +
+ "#if flash\n" +
+ "import flash.errors.ArgumentError;\n" +
+ "#end\n" +
+ "\n";
}
/**
@@ -295,8 +312,12 @@ string t_haxe_generator::haxe_type_imports() {
* @return List of imports necessary for thrift
*/
string t_haxe_generator::haxe_thrift_imports() {
- return string() + "import org.apache.thrift.*;\n" + "import org.apache.thrift.meta_data.*;\n"
- + "import org.apache.thrift.protocol.*;\n" + "\n";
+ return
+ string() +
+ "import org.apache.thrift.*;\n" +
+ "import org.apache.thrift.meta_data.*;\n" +
+ "import org.apache.thrift.protocol.*;\n" +
+ "\n";
}
/**
@@ -309,7 +330,7 @@ string t_haxe_generator::haxe_thrift_gen_imports(t_struct* tstruct, string& impo
const vector<t_field*>& members = tstruct->get_members();
vector<t_field*>::const_iterator m_iter;
- // For each type check if it is from a different namespace
+ //For each type check if it is from a different namespace
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
t_program* program = (*m_iter)->get_type()->get_program();
if (program != NULL && program != program_) {
@@ -321,9 +342,10 @@ string t_haxe_generator::haxe_thrift_gen_imports(t_struct* tstruct, string& impo
}
}
}
- return imports;
+ return imports;
}
+
/**
* Prints imports needed for a given type
*
@@ -334,31 +356,31 @@ string t_haxe_generator::haxe_thrift_gen_imports(t_service* tservice) {
const vector<t_function*>& functions = tservice->get_functions();
vector<t_function*>::const_iterator f_iter;
- // For each type check if it is from a different namespace
+ //For each type check if it is from a different namespace
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
t_program* program = (*f_iter)->get_returntype()->get_program();
if (program != NULL && program != program_) {
string package = program->get_namespace("haxe");
if (!package.empty()) {
if (imports.find(package + "." + (*f_iter)->get_returntype()->get_name()) == string::npos) {
- imports.append("import " + package + "." + (*f_iter)->get_returntype()->get_name()
- + ";\n");
+ imports.append("import " + package + "." + (*f_iter)->get_returntype()->get_name() + ";\n");
}
}
}
- haxe_thrift_gen_imports((*f_iter)->get_arglist(), imports);
- haxe_thrift_gen_imports((*f_iter)->get_xceptions(), imports);
- }
+ haxe_thrift_gen_imports((*f_iter)->get_arglist(), imports);
+ haxe_thrift_gen_imports((*f_iter)->get_xceptions(), imports);
+ }
+
return imports;
+
}
/**
* Nothing in haxe
*/
-void t_haxe_generator::close_generator() {
-}
+void t_haxe_generator::close_generator() {}
/**
* Generates a typedef. This is not done in haxe, since it does
@@ -368,7 +390,7 @@ void t_haxe_generator::close_generator() {
* @param ttypedef The type definition
*/
void t_haxe_generator::generate_typedef(t_typedef* ttypedef) {
- (void)ttypedef;
+ (void) ttypedef;
}
/**
@@ -383,25 +405,31 @@ void t_haxe_generator::generate_enum(t_enum* tenum) {
f_enum.open(f_enum_name.c_str());
// Comment and package it
- f_enum << autogen_comment() << haxe_package() << ";" << endl << endl;
-
+ f_enum <<
+ autogen_comment() <<
+ haxe_package() << ";" << endl << endl;
+
// Add haxe imports
- f_enum << string() + "import org.apache.thrift.helper.*;" << endl << endl;
-
- indent(f_enum) << "class " << get_cap_name(tenum->get_name()) << " ";
+ f_enum << string() +
+ "import org.apache.thrift.helper.*;" << endl <<
+ endl;
+
+ indent(f_enum) <<
+ "class " << get_cap_name(tenum->get_name()) << " ";
scope_up(f_enum);
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
int value = (*c_iter)->get_value();
- indent(f_enum) << "public static inline var " << (*c_iter)->get_name() << " : Int = " << value
- << ";" << endl;
+ indent(f_enum) <<
+ "public static inline var " << (*c_iter)->get_name() <<
+ " : Int = " << value << ";" << endl;
}
-
+
// Create a static Set with all valid values for this enum
f_enum << endl;
-
+
indent(f_enum) << "public static var VALID_VALUES = { new IntSet( [";
indent_up();
bool firstValue = true;
@@ -426,7 +454,7 @@ void t_haxe_generator::generate_enum(t_enum* tenum) {
indent(f_enum) << "]; };" << endl;
scope_down(f_enum); // end class
-
+
f_enum.close();
}
@@ -443,13 +471,18 @@ void t_haxe_generator::generate_consts(std::vector<t_const*> consts) {
f_consts.open(f_consts_name.c_str());
// Print header
- f_consts << autogen_comment() << haxe_package() << ";" << endl << endl;
-
+ f_consts <<
+ autogen_comment() << haxe_package() << ";" << endl << endl;
+
f_consts << endl;
-
+
f_consts << haxe_type_imports();
- indent(f_consts) << "class " << get_cap_name(program_name_) << "Constants {" << endl << endl;
+
+
+ indent(f_consts) <<
+ "class " << get_cap_name(program_name_) <<
+ "Constants {" << endl << endl;
indent_up();
vector<t_const*>::iterator c_iter;
for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
@@ -460,21 +493,18 @@ void t_haxe_generator::generate_consts(std::vector<t_const*> consts) {
false);
}
indent_down();
- indent(f_consts) << "}" << endl;
+ indent(f_consts) <<
+ "}" << endl;
f_consts.close();
}
-void t_haxe_generator::print_const_value(std::ofstream& out,
- string name,
- t_type* type,
- t_const_value* value,
- bool in_static,
- bool defval) {
+void t_haxe_generator::print_const_value(std::ofstream& out, string name, t_type* type, t_const_value* value, bool in_static, bool defval) {
type = get_true_type(type);
-
+
indent(out);
if (!defval) {
- out << (in_static ? "var " : "public static inline var ");
+ out <<
+ (in_static ? "var " : "public static inline var ");
}
if (type->is_base_type()) {
string v2 = render_const_value(out, name, type, value);
@@ -485,7 +515,7 @@ void t_haxe_generator::print_const_value(std::ofstream& out,
out << " = " << v2 << ";" << endl << endl;
} else if (type->is_enum()) {
out << name;
- if (!defval) {
+ if(!defval) {
out << ":" << type_name(type);
}
out << " = " << value->get_integer() << ";" << endl << endl;
@@ -494,8 +524,7 @@ void t_haxe_generator::print_const_value(std::ofstream& out,
vector<t_field*>::const_iterator f_iter;
const map<t_const_value*, t_const_value*>& val = value->get_map();
map<t_const_value*, t_const_value*>::const_iterator v_iter;
- out << name << ":" << type_name(type) << " = new " << type_name(type, false, true) << "();"
- << endl;
+ out << name << ":" << type_name(type) << " = new " << type_name(type, false, true) << "();" << endl;
if (!in_static) {
indent(out) << "{" << endl;
indent_up();
@@ -525,7 +554,7 @@ void t_haxe_generator::print_const_value(std::ofstream& out,
out << endl;
} else if (type->is_map()) {
out << name;
- if (!defval) {
+ if(!defval){
out << ":" << type_name(type);
}
out << " = new " << type_name(type, false, true) << "();" << endl;
@@ -553,7 +582,7 @@ void t_haxe_generator::print_const_value(std::ofstream& out,
out << endl;
} else if (type->is_list() || type->is_set()) {
out << name;
- if (!defval) {
+ if(!defval) {
out << ":" << type_name(type);
}
out << " = new " << type_name(type, false, true) << "();" << endl;
@@ -573,8 +602,7 @@ void t_haxe_generator::print_const_value(std::ofstream& out,
vector<t_const_value*>::const_iterator v_iter;
for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
string val = render_const_value(out, name, etype, *v_iter);
- indent(out) << name << "." << (type->is_list() ? "push" : "add") << "(" << val << ");"
- << endl;
+ indent(out) << name << "." << (type->is_list() ? "push" : "add") << "(" << val << ");" << endl;
}
if (!in_static) {
indent_down();
@@ -588,44 +616,41 @@ void t_haxe_generator::print_const_value(std::ofstream& out,
}
}
-string t_haxe_generator::render_const_value(ofstream& out,
- string name,
- t_type* type,
- t_const_value* value) {
- (void)name;
+string t_haxe_generator::render_const_value(ofstream& out, string name, t_type* type, t_const_value* value) {
+ (void) name;
type = get_true_type(type);
std::ostringstream render;
-
+
if (type->is_base_type()) {
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
switch (tbase) {
- case t_base_type::TYPE_STRING:
- render << '"' << get_escaped_string(value) << '"';
- break;
- case t_base_type::TYPE_BOOL:
- render << ((value->get_integer() > 0) ? "true" : "false");
- break;
- case t_base_type::TYPE_BYTE:
- render << "(byte)" << value->get_integer();
- break;
- case t_base_type::TYPE_I16:
- render << "(short)" << value->get_integer();
- break;
- case t_base_type::TYPE_I32:
- render << value->get_integer();
- break;
- case t_base_type::TYPE_I64:
- render << value->get_integer() << "L";
- break;
- case t_base_type::TYPE_DOUBLE:
- if (value->get_type() == t_const_value::CV_INTEGER) {
- render << "(double)" << value->get_integer();
- } else {
- render << value->get_double();
- }
- break;
- default:
- throw "compiler error: no const of base type " + t_base_type::t_base_name(tbase);
+ case t_base_type::TYPE_STRING:
+ render << '"' << get_escaped_string(value) << '"';
+ break;
+ case t_base_type::TYPE_BOOL:
+ render << ((value->get_integer() > 0) ? "true" : "false");
+ break;
+ case t_base_type::TYPE_BYTE:
+ render << "(byte)" << value->get_integer();
+ break;
+ case t_base_type::TYPE_I16:
+ render << "(short)" << value->get_integer();
+ break;
+ case t_base_type::TYPE_I32:
+ render << value->get_integer();
+ break;
+ case t_base_type::TYPE_I64:
+ render << value->get_integer() << "L";
+ break;
+ case t_base_type::TYPE_DOUBLE:
+ if (value->get_type() == t_const_value::CV_INTEGER) {
+ render << "(double)" << value->get_integer();
+ } else {
+ render << value->get_double();
+ }
+ break;
+ default:
+ throw "compiler error: no const of base type " + t_base_type::t_base_name(tbase);
}
} else if (type->is_enum()) {
render << value->get_integer();
@@ -634,10 +659,11 @@ string t_haxe_generator::render_const_value(ofstream& out,
print_const_value(out, t, type, value, true);
render << t;
}
-
+
return render.str();
}
+
/**
* Generates a struct definition for a thrift data type. This is a class
* with data members, read(), write(), and an inner Isset class.
@@ -657,28 +683,35 @@ void t_haxe_generator::generate_xception(t_struct* txception) {
generate_haxe_struct(txception, true);
}
+
/**
* Haxe struct definition.
*
* @param tstruct The struct definition
*/
-void t_haxe_generator::generate_haxe_struct(t_struct* tstruct, bool is_exception, bool is_result) {
+void t_haxe_generator::generate_haxe_struct(t_struct* tstruct,
+ bool is_exception,
+ bool is_result) {
// Make output file
string f_struct_name = package_dir_ + "/" + get_cap_name(tstruct->get_name()) + ".hx";
ofstream f_struct;
f_struct.open(f_struct_name.c_str());
- f_struct << autogen_comment() << haxe_package() << ";" << endl;
-
+ f_struct <<
+ autogen_comment() <<
+ haxe_package() << ";" << endl;
+
f_struct << endl;
-
+
string imports;
- f_struct << haxe_type_imports() << haxe_thrift_imports()
- << haxe_thrift_gen_imports(tstruct, imports) << endl;
-
+ f_struct <<
+ haxe_type_imports() <<
+ haxe_thrift_imports() <<
+ haxe_thrift_gen_imports(tstruct, imports) << endl;
+
generate_haxe_struct_definition(f_struct, tstruct, is_exception, is_result);
-
+
f_struct.close();
}
@@ -692,15 +725,16 @@ void t_haxe_generator::generate_haxe_struct(t_struct* tstruct, bool is_exception
* @param in_class If inside a class, needs to be static class
* @param is_result If this is a result it needs a different writer
*/
-void t_haxe_generator::generate_haxe_struct_definition(ofstream& out,
+void t_haxe_generator::generate_haxe_struct_definition(ofstream &out,
t_struct* tstruct,
bool is_exception,
bool is_result) {
generate_haxe_doc(out, tstruct);
- string clsname = get_cap_name(tstruct->get_name());
-
- indent(out) << "class " << clsname << " ";
+ string clsname = get_cap_name( tstruct->get_name());
+
+ indent(out) <<
+ "class " << clsname << " ";
if (is_exception) {
out << "extends TException ";
@@ -710,79 +744,78 @@ void t_haxe_generator::generate_haxe_struct_definition(ofstream& out,
scope_up(out);
indent(out) << endl;
- indent(out) << "static var STRUCT_DESC = { new TStruct(\"" << tstruct->get_name() << "\"); };"
- << endl;
+ indent(out) <<
+ "static var STRUCT_DESC = { new TStruct(\"" << tstruct->get_name() << "\"); };" << endl;
const vector<t_field*>& members = tstruct->get_members();
vector<t_field*>::const_iterator m_iter;
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- indent(out) << "static var " << constant_name((*m_iter)->get_name())
- << "_FIELD_DESC = { new TField(\"" << (*m_iter)->get_name() << "\", "
- << type_to_enum((*m_iter)->get_type()) << ", " << (*m_iter)->get_key() << "); };"
- << endl;
+ indent(out) <<
+ "static var " << constant_name((*m_iter)->get_name()) <<
+ "_FIELD_DESC = { new TField(\"" << (*m_iter)->get_name() << "\", " <<
+ type_to_enum((*m_iter)->get_type()) << ", " <<
+ (*m_iter)->get_key() << "); };" << endl;
}
out << endl;
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
generate_haxe_doc(out, *m_iter);
- // indent(out) << "private var _" << (*m_iter)->get_name() + " : " +
- // type_name((*m_iter)->get_type()) << ";" << endl;
+ //indent(out) << "private var _" << (*m_iter)->get_name() + " : " + type_name((*m_iter)->get_type()) << ";" << endl;
indent(out) << "@:isVar" << endl;
- indent(out) << "public var "
- << (*m_iter)->get_name() + "(get,set) : "
- + get_cap_name(type_name((*m_iter)->get_type())) << ";" << endl;
+ indent(out) << "public var " << (*m_iter)->get_name() + "(get,set) : " + get_cap_name(type_name((*m_iter)->get_type())) << ";" << endl;
}
-
+
out << endl;
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- indent(out) << "inline static var " << upcase_string((*m_iter)->get_name())
- << "_FIELD_ID : Int = " << (*m_iter)->get_key() << ";" << endl;
+ indent(out) << "inline static var " << upcase_string((*m_iter)->get_name()) << "_FIELD_ID : Int = " << (*m_iter)->get_key() << ";" << endl;
}
-
+
out << endl;
-
+
// Inner Isset class
if (members.size() > 0) {
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- if (!type_can_be_null((*m_iter)->get_type())) {
- indent(out) << "private var __isset_" << (*m_iter)->get_name() << " : Bool = false;"
- << endl;
+ if (!type_can_be_null((*m_iter)->get_type())){
+ indent(out) <<
+ "private var __isset_" << (*m_iter)->get_name() << " : Bool = false;" << endl;
+ }
}
- }
}
-
+
out << endl;
-
+
+
// Static initializer to populate global class to struct metadata map
- if (false) {
+ if( false) {
// TODO: reactivate when needed
generate_haxe_meta_data_map(out, tstruct);
indent(out) << "{" << endl;
indent_up();
- indent(out) << "FieldMetaData.addStructMetaDataMap(" << type_name(tstruct) << ", metaDataMap);"
- << endl;
+ indent(out) << "FieldMetaData.addStructMetaDataMap(" << type_name(tstruct) << ", metaDataMap);" << endl;
indent_down();
indent(out) << "}" << endl;
indent(out) << "}" << endl;
}
-
+
// Default constructor
- indent(out) << "public function new() {" << endl;
+ indent(out) <<
+ "public function new() {" << endl;
indent_up();
- if (is_exception) {
- indent(out) << "super();" << endl;
+ if( is_exception) {
+ indent(out) <<
+ "super();" << endl;
}
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
if ((*m_iter)->get_value() != NULL) {
- indent(out) << "this." << (*m_iter)->get_name() << " = "
- << (*m_iter)->get_value()->get_integer() << ";" << endl;
+ indent(out) << "this." << (*m_iter)->get_name() << " = " << (*m_iter)->get_value()->get_integer() << ";" <<
+ endl;
}
}
indent_down();
indent(out) << "}" << endl << endl;
-
+
generate_property_getters_setters(out, tstruct);
generate_generic_field_getters_setters(out, tstruct);
generate_generic_isset_method(out, tstruct);
@@ -804,129 +837,139 @@ void t_haxe_generator::generate_haxe_struct_definition(ofstream& out,
*
* @param tstruct The struct definition
*/
-void t_haxe_generator::generate_haxe_struct_reader(ofstream& out, t_struct* tstruct) {
- out << indent() << "public function read( iprot : TProtocol) : Void {" << endl;
+void t_haxe_generator::generate_haxe_struct_reader(ofstream& out,
+ t_struct* tstruct) {
+ out <<
+ indent() << "public function read( iprot : TProtocol) : Void {" << endl;
indent_up();
const vector<t_field*>& fields = tstruct->get_members();
vector<t_field*>::const_iterator f_iter;
// Declare stack tmp variables and read struct header
- out << indent() << "var field : TField;" << endl << indent() << "iprot.readStructBegin();"
- << endl;
+ out <<
+ indent() << "var field : TField;" << endl <<
+ indent() << "iprot.readStructBegin();" << endl;
// Loop over reading in fields
- indent(out) << "while (true)" << endl;
- scope_up(out);
-
- // Read beginning field marker
- indent(out) << "field = iprot.readFieldBegin();" << endl;
+ indent(out) <<
+ "while (true)" << endl;
+ scope_up(out);
- // Check for field STOP marker and break
- indent(out) << "if (field.type == TType.STOP) { " << endl;
- indent_up();
- indent(out) << "break;" << endl;
- indent_down();
- indent(out) << "}" << endl;
+ // Read beginning field marker
+ indent(out) <<
+ "field = iprot.readFieldBegin();" << endl;
- // Switch statement on the field we are reading
- indent(out) << "switch (field.id)" << endl;
+ // Check for field STOP marker and break
+ indent(out) <<
+ "if (field.type == TType.STOP) { " << endl;
+ indent_up();
+ indent(out) <<
+ "break;" << endl;
+ indent_down();
+ indent(out) <<
+ "}" << endl;
- scope_up(out);
+ // Switch statement on the field we are reading
+ indent(out) <<
+ "switch (field.id)" << endl;
- // Generate deserialization code for known cases
- for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- indent(out) << "case " << upcase_string((*f_iter)->get_name()) << "_FIELD_ID:" << endl;
- indent_up();
- indent(out) << "if (field.type == " << type_to_enum((*f_iter)->get_type()) << ") {" << endl;
- indent_up();
+ scope_up(out);
- generate_deserialize_field(out, *f_iter, "this.");
- generate_isset_set(out, *f_iter);
- indent_down();
- out << indent() << "} else { " << endl << indent() << " TProtocolUtil.skip(iprot, field.type);"
- << endl << indent() << "}" << endl;
- indent_down();
- }
+ // Generate deserialization code for known cases
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
+ indent(out) <<
+ "case " << upcase_string((*f_iter)->get_name()) << "_FIELD_ID:" << endl;
+ indent_up();
+ indent(out) <<
+ "if (field.type == " << type_to_enum((*f_iter)->get_type()) << ") {" << endl;
+ indent_up();
- // In the default case we skip the field
- out << indent() << "default:" << endl << indent() << " TProtocolUtil.skip(iprot, field.type);"
- << endl;
+ generate_deserialize_field(out, *f_iter, "this.");
+ generate_isset_set(out, *f_iter);
+ indent_down();
+ out <<
+ indent() << "} else { " << endl <<
+ indent() << " TProtocolUtil.skip(iprot, field.type);" << endl <<
+ indent() << "}" << endl;
+ indent_down();
+ }
- scope_down(out);
+ // In the default case we skip the field
+ out <<
+ indent() << "default:" << endl <<
+ indent() << " TProtocolUtil.skip(iprot, field.type);" << endl;
- // Read field end marker
- indent(out) << "iprot.readFieldEnd();" << endl;
+ scope_down(out);
- scope_down(out);
+ // Read field end marker
+ indent(out) <<
+ "iprot.readFieldEnd();" << endl;
- out << indent() << "iprot.readStructEnd();" << endl << endl;
+ scope_down(out);
- // check for required fields of primitive type
- // (which can be checked here but not in the general validate method)
- out << endl << indent() << "// check for required fields of primitive type, which can't be "
- "checked in the validate method" << endl;
- for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- if ((*f_iter)->get_req() == t_field::T_REQUIRED && !type_can_be_null((*f_iter)->get_type())) {
- out << indent() << "if (!__isset_" << (*f_iter)->get_name() << ") {" << endl << indent()
- << " throw new TProtocolException(TProtocolException.UNKNOWN, \"Required field '"
- << (*f_iter)->get_name()
- << "' was not found in serialized data! Struct: \" + toString());" << endl << indent()
- << "}" << endl;
+ out <<
+ indent() << "iprot.readStructEnd();" << endl << endl;
+
+ // check for required fields of primitive type
+ // (which can be checked here but not in the general validate method)
+ out << endl << indent() << "// check for required fields of primitive type, which can't be checked in the validate method" << endl;
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
+ if ((*f_iter)->get_req() == t_field::T_REQUIRED && !type_can_be_null((*f_iter)->get_type())) {
+ out <<
+ indent() << "if (!__isset_" << (*f_iter)->get_name() << ") {" << endl <<
+ indent() << " throw new TProtocolException(TProtocolException.UNKNOWN, \"Required field '" << (*f_iter)->get_name() << "' was not found in serialized data! Struct: \" + toString());" << endl <<
+ indent() << "}" << endl;
+ }
}
- }
- // performs various checks (e.g. check that all required fields are set)
- indent(out) << "validate();" << endl;
+ // performs various checks (e.g. check that all required fields are set)
+ indent(out) << "validate();" << endl;
indent_down();
- out << indent() << "}" << endl << endl;
+ out <<
+ indent() << "}" << endl <<
+ endl;
}
// generates haxe method to perform various checks
// (e.g. check that all required fields are set)
-void t_haxe_generator::generate_haxe_validator(ofstream& out, t_struct* tstruct) {
+void t_haxe_generator::generate_haxe_validator(ofstream& out,
+ t_struct* tstruct){
indent(out) << "public function validate() : Void {" << endl;
- indent_up();
-
+ indent_up();
+
const vector<t_field*>& fields = tstruct->get_members();
vector<t_field*>::const_iterator f_iter;
-
+
out << indent() << "// check for required fields" << endl;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
if ((*f_iter)->get_req() == t_field::T_REQUIRED) {
if (type_can_be_null((*f_iter)->get_type())) {
indent(out) << "if (" << (*f_iter)->get_name() << " == null) {" << endl;
- indent(out)
- << " throw new TProtocolException(TProtocolException.UNKNOWN, \"Required field '"
- << (*f_iter)->get_name() << "' was not present! Struct: \" + toString());" << endl;
+ indent(out) << " throw new TProtocolException(TProtocolException.UNKNOWN, \"Required field '" << (*f_iter)->get_name() << "' was not present! Struct: \" + toString());" << endl;
indent(out) << "}" << endl;
} else {
- indent(out) << "// alas, we cannot check '" << (*f_iter)->get_name()
- << "' because it's a primitive." << endl;
+ indent(out) << "// alas, we cannot check '" << (*f_iter)->get_name() << "' because it's a primitive." << endl;
}
}
}
-
+
// check that fields of type enum have valid values
out << indent() << "// check that fields of type enum have valid values" << endl;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
t_field* field = (*f_iter);
t_type* type = field->get_type();
// if field is an enum, check that its value is valid
- if (type->is_enum()) {
- indent(out) << "if (" << generate_isset_check(field) << " && !"
- << get_cap_name(get_enum_class_name(type)) << ".VALID_VALUES.contains("
- << field->get_name() << ")){" << endl;
+ if (type->is_enum()){
+ indent(out) << "if (" << generate_isset_check(field) << " && !" << get_cap_name(get_enum_class_name(type)) << ".VALID_VALUES.contains(" << field->get_name() << ")){" << endl;
indent_up();
- indent(out) << "throw new TProtocolException(TProtocolException.UNKNOWN, \"The field '"
- << field->get_name() << "' has been assigned the invalid value \" + "
- << field->get_name() << ");" << endl;
+ indent(out) << "throw new TProtocolException(TProtocolException.UNKNOWN, \"The field '" << field->get_name() << "' has been assigned the invalid value \" + " << field->get_name() << ");" << endl;
indent_down();
indent(out) << "}" << endl;
- }
- }
-
+ }
+ }
+
indent_down();
indent(out) << "}" << endl << endl;
}
@@ -936,8 +979,10 @@ void t_haxe_generator::generate_haxe_validator(ofstream& out, t_struct* tstruct)
*
* @param tstruct The struct definition
*/
-void t_haxe_generator::generate_haxe_struct_writer(ofstream& out, t_struct* tstruct) {
- out << indent() << "public function write(oprot:TProtocol) : Void {" << endl;
+void t_haxe_generator::generate_haxe_struct_writer(ofstream& out,
+ t_struct* tstruct) {
+ out <<
+ indent() << "public function write(oprot:TProtocol) : Void {" << endl;
indent_up();
string name = tstruct->get_name();
@@ -952,18 +997,19 @@ void t_haxe_generator::generate_haxe_struct_writer(ofstream& out, t_struct* tstr
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
bool null_allowed = type_can_be_null((*f_iter)->get_type());
if (null_allowed) {
- out << indent() << "if (this." << (*f_iter)->get_name() << " != null) {" << endl;
+ out <<
+ indent() << "if (this." << (*f_iter)->get_name() << " != null) {" << endl;
indent_up();
}
- indent(out) << "oprot.writeFieldBegin(" << constant_name((*f_iter)->get_name())
- << "_FIELD_DESC);" << endl;
+ indent(out) << "oprot.writeFieldBegin(" << constant_name((*f_iter)->get_name()) << "_FIELD_DESC);" << endl;
// Write field contents
generate_serialize_field(out, *f_iter, "this.");
// Write field closer
- indent(out) << "oprot.writeFieldEnd();" << endl;
+ indent(out) <<
+ "oprot.writeFieldEnd();" << endl;
if (null_allowed) {
indent_down();
@@ -971,11 +1017,14 @@ void t_haxe_generator::generate_haxe_struct_writer(ofstream& out, t_struct* tstr
}
}
// Write the struct map
- out << indent() << "oprot.writeFieldStop();" << endl << indent() << "oprot.writeStructEnd();"
- << endl;
+ out <<
+ indent() << "oprot.writeFieldStop();" << endl <<
+ indent() << "oprot.writeStructEnd();" << endl;
indent_down();
- out << indent() << "}" << endl << endl;
+ out <<
+ indent() << "}" << endl <<
+ endl;
}
/**
@@ -986,8 +1035,10 @@ void t_haxe_generator::generate_haxe_struct_writer(ofstream& out, t_struct* tstr
*
* @param tstruct The struct definition
*/
-void t_haxe_generator::generate_haxe_struct_result_writer(ofstream& out, t_struct* tstruct) {
- out << indent() << "public function write(oprot:TProtocol) : Void {" << endl;
+void t_haxe_generator::generate_haxe_struct_result_writer(ofstream& out,
+ t_struct* tstruct) {
+ out <<
+ indent() << "public function write(oprot:TProtocol) : Void {" << endl;
indent_up();
string name = tstruct->get_name();
@@ -995,12 +1046,14 @@ void t_haxe_generator::generate_haxe_struct_result_writer(ofstream& out, t_struc
vector<t_field*>::const_iterator f_iter;
indent(out) << "oprot.writeStructBegin(STRUCT_DESC);" << endl;
-
+
bool first = true;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
if (first) {
first = false;
- out << endl << indent() << "if ";
+ out <<
+ endl <<
+ indent() << "if ";
} else {
out << " else if ";
}
@@ -1008,45 +1061,43 @@ void t_haxe_generator::generate_haxe_struct_result_writer(ofstream& out, t_struc
out << "(this." << generate_isset_check(*f_iter) << ") {" << endl;
indent_up();
-
- indent(out) << "oprot.writeFieldBegin(" << constant_name((*f_iter)->get_name())
- << "_FIELD_DESC);" << endl;
+
+ indent(out) << "oprot.writeFieldBegin(" << constant_name((*f_iter)->get_name()) << "_FIELD_DESC);" << endl;
// Write field contents
generate_serialize_field(out, *f_iter, "this.");
// Write field closer
- indent(out) << "oprot.writeFieldEnd();" << endl;
+ indent(out) <<
+ "oprot.writeFieldEnd();" << endl;
indent_down();
indent(out) << "}";
}
// Write the struct map
- out << endl << indent() << "oprot.writeFieldStop();" << endl << indent()
- << "oprot.writeStructEnd();" << endl;
+ out <<
+ endl <<
+ indent() << "oprot.writeFieldStop();" << endl <<
+ indent() << "oprot.writeStructEnd();" << endl;
indent_down();
- out << indent() << "}" << endl << endl;
+ out <<
+ indent() << "}" << endl <<
+ endl;
}
-void t_haxe_generator::generate_reflection_getters(ostringstream& out,
- t_type* type,
- string field_name,
- string cap_name) {
- (void)type;
- (void)cap_name;
+void t_haxe_generator::generate_reflection_getters(ostringstream& out, t_type* type, string field_name, string cap_name) {
+ (void) type;
+ (void) cap_name;
indent(out) << "case " << upcase_string(field_name) << "_FIELD_ID:" << endl;
indent_up();
indent(out) << "return this." << field_name << ";" << endl;
indent_down();
}
-void t_haxe_generator::generate_reflection_setters(ostringstream& out,
- t_type* type,
- string field_name,
- string cap_name) {
- (void)type;
- (void)cap_name;
+void t_haxe_generator::generate_reflection_setters(ostringstream& out, t_type* type, string field_name, string cap_name) {
+ (void) type;
+ (void) cap_name;
indent(out) << "case " << upcase_string(field_name) << "_FIELD_ID:" << endl;
indent_up();
indent(out) << "if (value == null) {" << endl;
@@ -1058,8 +1109,7 @@ void t_haxe_generator::generate_reflection_setters(ostringstream& out,
indent_down();
}
-void t_haxe_generator::generate_generic_field_getters_setters(std::ofstream& out,
- t_struct* tstruct) {
+void t_haxe_generator::generate_generic_field_getters_setters(std::ofstream& out, t_struct* tstruct) {
std::ostringstream getter_stream;
std::ostringstream setter_stream;
@@ -1079,6 +1129,7 @@ void t_haxe_generator::generate_generic_field_getters_setters(std::ofstream& out
indent_down();
}
+
// create the setter
indent(out) << "public function setFieldValue(fieldID : Int, value : Dynamic) : Void {" << endl;
indent_up();
@@ -1092,7 +1143,7 @@ void t_haxe_generator::generate_generic_field_getters_setters(std::ofstream& out
} else {
indent(out) << "throw new ArgumentError(\"Field \" + fieldID + \" doesn't exist!\");" << endl;
}
-
+
indent_down();
indent(out) << "}" << endl << endl;
@@ -1116,13 +1167,12 @@ void t_haxe_generator::generate_generic_field_getters_setters(std::ofstream& out
}
// Creates a generic isSet method that takes the field number as argument
-void t_haxe_generator::generate_generic_isset_method(std::ofstream& out, t_struct* tstruct) {
+void t_haxe_generator::generate_generic_isset_method(std::ofstream& out, t_struct* tstruct){
const vector<t_field*>& fields = tstruct->get_members();
vector<t_field*>::const_iterator f_iter;
// create the isSet method
- indent(out) << "// Returns true if field corresponding to fieldID is set (has been assigned a "
- "value) and false otherwise" << endl;
+ indent(out) << "// Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise" << endl;
indent(out) << "public function isSet(fieldID : Int) : Bool {" << endl;
indent_up();
if (fields.size() > 0) {
@@ -1152,7 +1202,8 @@ void t_haxe_generator::generate_generic_isset_method(std::ofstream& out, t_struc
*
* @param tstruct The struct definition
*/
-void t_haxe_generator::generate_property_getters_setters(ofstream& out, t_struct* tstruct) {
+void t_haxe_generator::generate_property_getters_setters(ofstream& out,
+ t_struct* tstruct) {
const vector<t_field*>& fields = tstruct->get_members();
vector<t_field*>::const_iterator f_iter;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
@@ -1160,29 +1211,32 @@ void t_haxe_generator::generate_property_getters_setters(ofstream& out, t_struct
t_type* type = get_true_type(field->get_type());
std::string field_name = field->get_name();
std::string cap_name = get_cap_name(field_name);
-
+
// Simple getter
generate_haxe_doc(out, field);
- indent(out) << "public function get_" << field_name << "() : " << get_cap_name(type_name(type))
- << " {" << endl;
+ indent(out) << "public function get_" << field_name << "() : " <<
+ get_cap_name(type_name(type)) << " {" << endl;
indent_up();
indent(out) << "return this." << field_name << ";" << endl;
indent_down();
indent(out) << "}" << endl << endl;
-
+
// Simple setter
generate_haxe_doc(out, field);
- indent(out) << "public function set_" << field_name << "(" << field_name << ":"
- << get_cap_name(type_name(type)) << ") : " << get_cap_name(type_name(type)) << " {"
- << endl;
+ indent(out) <<
+ "public function set_" << field_name <<
+ "(" << field_name << ":" << get_cap_name(type_name(type)) << ") : " <<
+ get_cap_name(type_name(type)) << " {" << endl;
indent_up();
- indent(out) << "this." << field_name << " = " << field_name << ";" << endl;
+ indent(out) <<
+ "this." << field_name << " = " << field_name << ";" << endl;
generate_isset_set(out, field);
- indent(out) << "return this." << field_name << ";" << endl;
-
+ indent(out) <<
+ "return this." << field_name << ";" << endl;
+
indent_down();
indent(out) << "}" << endl << endl;
-
+
// Unsetter
indent(out) << "public function unset" << cap_name << "() : Void {" << endl;
indent_up();
@@ -1193,10 +1247,9 @@ void t_haxe_generator::generate_property_getters_setters(ofstream& out, t_struct
}
indent_down();
indent(out) << "}" << endl << endl;
-
+
// isSet method
- indent(out) << "// Returns true if field " << field_name
- << " is set (has been assigned a value) and false otherwise" << endl;
+ indent(out) << "// Returns true if field " << field_name << " is set (has been assigned a value) and false otherwise" << endl;
indent(out) << "public function is" << get_cap_name("set") << cap_name << "() : Bool {" << endl;
indent_up();
if (type_can_be_null(type)) {
@@ -1214,12 +1267,13 @@ void t_haxe_generator::generate_property_getters_setters(ofstream& out, t_struct
*
* @param tstruct The struct definition
*/
-void t_haxe_generator::generate_haxe_struct_tostring(ofstream& out, t_struct* tstruct) {
- out << indent() << "public "
- << "function toString() : String {" << endl;
+void t_haxe_generator::generate_haxe_struct_tostring(ofstream& out,
+ t_struct* tstruct) {
+ out << indent() << "public " << "function toString() : String {" << endl;
indent_up();
- out << indent() << "var ret : String = \"" << tstruct->get_name() << "(\";" << endl;
+ out <<
+ indent() << "var ret : String = \"" << tstruct->get_name() << "(\";" << endl;
out << indent() << "var first : Bool = true;" << endl << endl;
const vector<t_field*>& fields = tstruct->get_members();
@@ -1227,7 +1281,7 @@ void t_haxe_generator::generate_haxe_struct_tostring(ofstream& out, t_struct* ts
bool first = true;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
bool could_be_unset = (*f_iter)->get_req() == t_field::T_OPTIONAL;
- if (could_be_unset) {
+ if(could_be_unset) {
indent(out) << "if (" << generate_isset_check(*f_iter) << ") {" << endl;
indent_up();
}
@@ -1245,13 +1299,11 @@ void t_haxe_generator::generate_haxe_struct_tostring(ofstream& out, t_struct* ts
indent(out) << "} else {" << endl;
indent_up();
}
-
+
if (field->get_type()->is_base_type() && ((t_base_type*)(field->get_type()))->is_binary()) {
indent(out) << " ret += \"BINARY\";" << endl;
- } else if (field->get_type()->is_enum()) {
- indent(out) << "var " << field->get_name()
- << "_name : String = " << get_cap_name(get_enum_class_name(field->get_type()))
- << ".VALUES_TO_NAMES[this." << (*f_iter)->get_name() << "];" << endl;
+ } else if(field->get_type()->is_enum()) {
+ indent(out) << "var " << field->get_name() << "_name : String = " << get_cap_name(get_enum_class_name(field->get_type())) << ".VALUES_TO_NAMES[this." << (*f_iter)->get_name() << "];"<< endl;
indent(out) << "if (" << field->get_name() << "_name != null) {" << endl;
indent(out) << " ret += " << field->get_name() << "_name;" << endl;
indent(out) << " ret += \" (\";" << endl;
@@ -1263,23 +1315,26 @@ void t_haxe_generator::generate_haxe_struct_tostring(ofstream& out, t_struct* ts
} else {
indent(out) << "ret += this." << (*f_iter)->get_name() << ";" << endl;
}
-
+
if (can_be_null) {
indent_down();
indent(out) << "}" << endl;
}
indent(out) << "first = false;" << endl;
- if (could_be_unset) {
+ if(could_be_unset) {
indent_down();
indent(out) << "}" << endl;
}
first = false;
}
- out << indent() << "ret += \")\";" << endl << indent() << "return ret;" << endl;
+ out <<
+ indent() << "ret += \")\";" << endl <<
+ indent() << "return ret;" << endl;
indent_down();
- indent(out) << "}" << endl << endl;
+ indent(out) << "}" << endl <<
+ endl;
}
/**
@@ -1288,7 +1343,8 @@ void t_haxe_generator::generate_haxe_struct_tostring(ofstream& out, t_struct* ts
*
* @param tstruct The struct definition
*/
-void t_haxe_generator::generate_haxe_meta_data_map(ofstream& out, t_struct* tstruct) {
+void t_haxe_generator::generate_haxe_meta_data_map(ofstream& out,
+ t_struct* tstruct) {
const vector<t_field*>& fields = tstruct->get_members();
vector<t_field*>::const_iterator f_iter;
@@ -1301,8 +1357,7 @@ void t_haxe_generator::generate_haxe_meta_data_map(ofstream& out, t_struct* tstr
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
t_field* field = *f_iter;
std::string field_name = field->get_name();
- indent(out) << "metaDataMap[" << upcase_string(field_name)
- << "_FIELD_ID] = new FieldMetaData(\"" << field_name << "\", ";
+ indent(out) << "metaDataMap[" << upcase_string(field_name) << "_FIELD_ID] = new FieldMetaData(\"" << field_name << "\", ";
// Set field requirement type (required, optional, etc.)
if (field->get_req() == t_field::T_REQUIRED) {
@@ -1313,20 +1368,20 @@ void t_haxe_generator::generate_haxe_meta_data_map(ofstream& out, t_struct* tstr
out << "TFieldRequirementType.DEFAULT, ";
}
- // Create value meta data
+ // Create value meta data
generate_field_value_meta_data(out, field->get_type());
- out << ");" << endl;
+ out << ");" << endl;
}
scope_down(out);
}
}
-/**
+/**
* Returns a string with the haxe representation of the given thrift type
* (e.g. for the type struct it returns "TType.STRUCT")
*/
std::string t_haxe_generator::get_haxe_type_string(t_type* type) {
- if (type->is_list()) {
+ if (type->is_list()){
return "TType.LIST";
} else if (type->is_map()) {
return "TType.MAP";
@@ -1340,58 +1395,37 @@ std::string t_haxe_generator::get_haxe_type_string(t_type* type) {
return get_haxe_type_string(((t_typedef*)type)->get_type());
} else if (type->is_base_type()) {
switch (((t_base_type*)type)->get_base()) {
- case t_base_type::TYPE_VOID:
- return "TType.VOID";
- break;
- case t_base_type::TYPE_STRING:
- return "TType.STRING";
- break;
- case t_base_type::TYPE_BOOL:
- return "TType.BOOL";
- break;
- case t_base_type::TYPE_BYTE:
- return "TType.BYTE";
- break;
- case t_base_type::TYPE_I16:
- return "TType.I16";
- break;
- case t_base_type::TYPE_I32:
- return "TType.I32";
- break;
- case t_base_type::TYPE_I64:
- return "TType.I64";
- break;
- case t_base_type::TYPE_DOUBLE:
- return "TType.DOUBLE";
- break;
- default:
- throw std::runtime_error("Unknown thrift type \"" + type->get_name()
- + "\" passed to t_haxe_generator::get_haxe_type_string!");
- break; // This should never happen!
+ case t_base_type::TYPE_VOID : return "TType.VOID"; break;
+ case t_base_type::TYPE_STRING : return "TType.STRING"; break;
+ case t_base_type::TYPE_BOOL : return "TType.BOOL"; break;
+ case t_base_type::TYPE_BYTE : return "TType.BYTE"; break;
+ case t_base_type::TYPE_I16 : return "TType.I16"; break;
+ case t_base_type::TYPE_I32 : return "TType.I32"; break;
+ case t_base_type::TYPE_I64 : return "TType.I64"; break;
+ case t_base_type::TYPE_DOUBLE : return "TType.DOUBLE"; break;
+ default : throw std::runtime_error("Unknown thrift type \"" + type->get_name() + "\" passed to t_haxe_generator::get_haxe_type_string!"); break; // This should never happen!
}
} else {
- throw std::runtime_error(
- "Unknown thrift type \"" + type->get_name()
- + "\" passed to t_haxe_generator::get_haxe_type_string!"); // This should never happen!
+ throw std::runtime_error("Unknown thrift type \"" + type->get_name() + "\" passed to t_haxe_generator::get_haxe_type_string!"); // This should never happen!
}
}
-void t_haxe_generator::generate_field_value_meta_data(std::ofstream& out, t_type* type) {
+void t_haxe_generator::generate_field_value_meta_data(std::ofstream& out, t_type* type){
out << endl;
indent_up();
indent_up();
- if (type->is_struct()) {
+ if (type->is_struct()){
indent(out) << "new StructMetaData(TType.STRUCT, " << type_name(type);
- } else if (type->is_container()) {
- if (type->is_list()) {
+ } else if (type->is_container()){
+ if (type->is_list()){
indent(out) << "new ListMetaData(TType.LIST, ";
- t_type* elem_type = ((t_list*)type)->get_elem_type();
- generate_field_value_meta_data(out, elem_type);
- } else if (type->is_set()) {
+ t_type* elem_type = ((t_list*)type)->get_elem_type();
+ generate_field_value_meta_data(out, elem_type);
+ } else if (type->is_set()){
indent(out) << "new SetMetaData(TType.SET, ";
- t_type* elem_type = ((t_list*)type)->get_elem_type();
- generate_field_value_meta_data(out, elem_type);
- } else { // map
+ t_type* elem_type = ((t_list*)type)->get_elem_type();
+ generate_field_value_meta_data(out, elem_type);
+ } else{ // map
indent(out) << "new MapMetaData(TType.MAP, ";
t_type* key_type = ((t_map*)type)->get_key_type();
t_type* val_type = ((t_map*)type)->get_val_type();
@@ -1407,6 +1441,7 @@ void t_haxe_generator::generate_field_value_meta_data(std::ofstream& out, t_type
indent_down();
}
+
/**
* Generates a thrift service. In C++, this comprises an entirely separate
* header and source file. The header file defines the methods and includes
@@ -1420,15 +1455,18 @@ void t_haxe_generator::generate_service(t_service* tservice) {
string f_service_name = package_dir_ + "/" + get_cap_name(service_name_) + ".hx";
f_service_.open(f_service_name.c_str());
- f_service_ << autogen_comment() << haxe_package() << ";" << endl;
+ f_service_ <<
+ autogen_comment() << haxe_package() << ";" << endl;
+
+ f_service_ << endl <<
+ haxe_type_imports() <<
+ haxe_thrift_imports() <<
+ haxe_thrift_gen_imports(tservice);
- f_service_ << endl << haxe_type_imports() << haxe_thrift_imports()
- << haxe_thrift_gen_imports(tservice);
-
- if (tservice->get_extends() != NULL) {
+ if(tservice->get_extends() != NULL) {
t_type* parent = tservice->get_extends();
string parent_namespace = parent->get_program()->get_namespace("haxe");
- if (!parent_namespace.empty() && parent_namespace != package_name_) {
+ if(!parent_namespace.empty() && parent_namespace != package_name_) {
f_service_ << "import " << type_name(parent) << ";" << endl;
}
}
@@ -1438,18 +1476,23 @@ void t_haxe_generator::generate_service(t_service* tservice) {
generate_service_interface(tservice);
f_service_.close();
-
+
// Now make the implementation/client file
- f_service_name = package_dir_ + "/" + get_cap_name(service_name_) + "Impl.hx";
+ f_service_name = package_dir_+"/"+get_cap_name(service_name_)+"Impl.hx";
f_service_.open(f_service_name.c_str());
+
+ f_service_ <<
+ autogen_comment() << haxe_package() << ";" << endl <<
+ endl <<
+ haxe_type_imports() <<
+ haxe_thrift_imports() <<
+ haxe_thrift_gen_imports(tservice) << endl;
- f_service_ << autogen_comment() << haxe_package() << ";" << endl << endl << haxe_type_imports()
- << haxe_thrift_imports() << haxe_thrift_gen_imports(tservice) << endl;
- if (tservice->get_extends() != NULL) {
+ if(tservice->get_extends() != NULL) {
t_type* parent = tservice->get_extends();
string parent_namespace = parent->get_program()->get_namespace("haxe");
- if (!parent_namespace.empty() && parent_namespace != package_name_) {
+ if(!parent_namespace.empty() && parent_namespace != package_name_) {
f_service_ << "import " << type_name(parent) << "Impl;" << endl;
}
}
@@ -1464,22 +1507,26 @@ void t_haxe_generator::generate_service(t_service* tservice) {
generate_service_helpers(tservice);
// Now make the processor/server file
- f_service_name = package_dir_ + "/" + get_cap_name(service_name_) + "Processor.hx";
+ f_service_name = package_dir_+"/"+get_cap_name(service_name_)+"Processor.hx";
f_service_.open(f_service_name.c_str());
-
- f_service_ << autogen_comment() << haxe_package() << ";" << endl << endl << haxe_type_imports()
- << haxe_thrift_imports() << haxe_thrift_gen_imports(tservice) << endl;
-
- if (!package_name_.empty()) {
+
+ f_service_ <<
+ autogen_comment() << haxe_package() << ";" << endl <<
+ endl <<
+ haxe_type_imports() <<
+ haxe_thrift_imports() <<
+ haxe_thrift_gen_imports(tservice) << endl;
+
+ if(!package_name_.empty()) {
f_service_ << "import " << package_name_ << ".*;" << endl;
- f_service_ << "import " << package_name_ << "." << get_cap_name(service_name_).c_str()
- << "Impl;" << endl;
+ f_service_ << "import " << package_name_ << "." << get_cap_name(service_name_).c_str() << "Impl;" << endl;
f_service_ << endl;
}
-
+
generate_service_server(tservice);
-
+
f_service_.close();
+
}
/**
@@ -1487,33 +1534,31 @@ void t_haxe_generator::generate_service(t_service* tservice) {
*
* @param tfunction The service function to generate code for.
*/
-string t_haxe_generator::generate_service_method_onsuccess(t_function* tfunction,
- bool as_type,
- bool omit_name) {
- if (tfunction->is_oneway()) {
+string t_haxe_generator::generate_service_method_onsuccess(t_function* tfunction, bool as_type, bool omit_name) {
+ if( tfunction->is_oneway()) {
return "";
}
-
+
string name = "";
- if (!omit_name) {
+ if( ! omit_name) {
name = "onSuccess";
- if (as_type) {
+ if( as_type) {
name += " : ";
}
}
-
- if (tfunction->get_returntype()->is_void()) {
- if (as_type) {
- return name + "Void->Void = null";
+
+ if( tfunction->get_returntype()->is_void()) {
+ if( as_type) {
+ return name + "Void->Void = null";
} else {
- return name + "() : Void";
+ return name + "() : Void";
}
}
-
- if (as_type) {
+
+ if( as_type) {
return name + type_name(tfunction->get_returntype()) + "->Void = null";
} else {
- return name + "( retval : " + type_name(tfunction->get_returntype()) + ")";
+ return name + "( retval : " + type_name(tfunction->get_returntype()) + ")";
}
}
@@ -1523,11 +1568,11 @@ string t_haxe_generator::generate_service_method_onsuccess(t_function* tfunction
* @param tfunction The service function to generate code for.
*/
void t_haxe_generator::generate_service_method_signature(t_function* tfunction, bool is_interface) {
- if (callbacks_) {
- generate_service_method_signature_callback(tfunction, is_interface);
+ if( callbacks_) {
+ generate_service_method_signature_callback( tfunction, is_interface);
} else {
- generate_service_method_signature_normal(tfunction, is_interface);
- }
+ generate_service_method_signature_normal( tfunction, is_interface);
+ }
}
/**
@@ -1535,12 +1580,12 @@ void t_haxe_generator::generate_service_method_signature(t_function* tfunction,
*
* @param tfunction The service function to generate code for.
*/
-void t_haxe_generator::generate_service_method_signature_normal(t_function* tfunction,
- bool is_interface) {
- if (is_interface) {
+void t_haxe_generator::generate_service_method_signature_normal(t_function* tfunction, bool is_interface) {
+ if( is_interface) {
indent(f_service_) << function_signature_normal(tfunction) << ";" << endl << endl;
} else {
- indent(f_service_) << "public " << function_signature_normal(tfunction) << " {" << endl;
+ indent(f_service_) <<
+ "public " << function_signature_normal(tfunction) << " {" << endl;
}
}
@@ -1549,18 +1594,19 @@ void t_haxe_generator::generate_service_method_signature_normal(t_function* tfun
*
* @param tfunction The service function to generate code for.
*/
-void t_haxe_generator::generate_service_method_signature_callback(t_function* tfunction,
- bool is_interface) {
+void t_haxe_generator::generate_service_method_signature_callback(t_function* tfunction, bool is_interface) {
if (!tfunction->is_oneway()) {
std::string on_success_impl = generate_service_method_onsuccess(tfunction, false, false);
indent(f_service_) << "// function onError(Dynamic) : Void;" << endl;
indent(f_service_) << "// function " << on_success_impl.c_str() << ";" << endl;
}
- if (is_interface) {
- indent(f_service_) << function_signature_callback(tfunction) << ";" << endl << endl;
+ if( is_interface) {
+ indent(f_service_) << function_signature_callback(tfunction) << ";" <<
+ endl << endl;
} else {
- indent(f_service_) << "public " << function_signature_callback(tfunction) << " {" << endl;
+ indent(f_service_) <<
+ "public " << function_signature_callback(tfunction) << " {" << endl;
}
}
@@ -1576,17 +1622,19 @@ void t_haxe_generator::generate_service_interface(t_service* tservice) {
}
generate_haxe_doc(f_service_, tservice);
- f_service_ << indent() << "interface " << get_cap_name(service_name_) << extends_iface << " {"
- << endl << endl;
+ f_service_ << indent() << "interface " << get_cap_name(service_name_) << extends_iface <<
+ " {" << endl << endl;
indent_up();
vector<t_function*> functions = tservice->get_functions();
vector<t_function*>::iterator f_iter;
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
generate_haxe_doc(f_service_, *f_iter);
- generate_service_method_signature(*f_iter, true);
+ generate_service_method_signature(*f_iter,true);
}
indent_down();
- f_service_ << indent() << "}" << endl << endl;
+ f_service_ <<
+ indent() << "}" << endl <<
+ endl;
}
/**
@@ -1605,6 +1653,7 @@ void t_haxe_generator::generate_service_helpers(t_service* tservice) {
}
}
+
/**
* Generates a service client definition.
*
@@ -1618,14 +1667,19 @@ void t_haxe_generator::generate_service_client(t_service* tservice) {
extends_client = " extends " + extends + "Impl";
}
- indent(f_service_) << "class " << get_cap_name(service_name_) << "Impl" << extends_client
- << " implements " << get_cap_name(service_name_) << " {" << endl << endl;
+ indent(f_service_) <<
+ "class " << get_cap_name(service_name_) <<
+ "Impl" << extends_client <<
+ " implements " << get_cap_name(service_name_) <<
+ " {" << endl << endl;
indent_up();
- indent(f_service_) << "public function new( iprot : TProtocol, oprot : TProtocol = null)" << endl;
+ indent(f_service_) <<
+ "public function new( iprot : TProtocol, oprot : TProtocol = null)" << endl;
scope_up(f_service_);
if (extends.empty()) {
- f_service_ << indent() << "iprot_ = iprot;" << endl;
+ f_service_ <<
+ indent() << "iprot_ = iprot;" << endl;
f_service_ << indent() << "if (oprot == null) {" << endl;
indent_up();
f_service_ << indent() << "oprot_ = iprot;" << endl;
@@ -1636,27 +1690,35 @@ void t_haxe_generator::generate_service_client(t_service* tservice) {
indent_down();
f_service_ << indent() << "}" << endl;
} else {
- f_service_ << indent() << "super(iprot, oprot);" << endl;
+ f_service_ <<
+ indent() << "super(iprot, oprot);" << endl;
}
scope_down(f_service_);
f_service_ << endl;
if (extends.empty()) {
- f_service_ << indent() << "private var iprot_ : TProtocol;" << endl << indent()
- << "private var oprot_ : TProtocol;" << endl << indent()
- << "private var seqid_ : Int;" << endl << endl;
-
- indent(f_service_) << "public function getInputProtocol() : TProtocol" << endl;
+ f_service_ <<
+ indent() << "private var iprot_ : TProtocol;" << endl <<
+ indent() << "private var oprot_ : TProtocol;" << endl <<
+ indent() << "private var seqid_ : Int;" << endl <<
+ endl;
+
+ indent(f_service_) <<
+ "public function getInputProtocol() : TProtocol" << endl;
scope_up(f_service_);
- indent(f_service_) << "return this.iprot_;" << endl;
+ indent(f_service_) <<
+ "return this.iprot_;" << endl;
scope_down(f_service_);
f_service_ << endl;
- indent(f_service_) << "public function getOutputProtocol() : TProtocol" << endl;
+ indent(f_service_) <<
+ "public function getOutputProtocol() : TProtocol" << endl;
scope_up(f_service_);
- indent(f_service_) << "return this.oprot_;" << endl;
+ indent(f_service_) <<
+ "return this.oprot_;" << endl;
scope_down(f_service_);
f_service_ << endl;
+
}
// Generate client method implementations
@@ -1666,49 +1728,51 @@ void t_haxe_generator::generate_service_client(t_service* tservice) {
string funname = (*f_iter)->get_name();
// Open function
- generate_service_method_signature(*f_iter, false);
+ generate_service_method_signature(*f_iter,false);
indent_up();
+
// Get the struct of function call params
t_struct* arg_struct = (*f_iter)->get_arglist();
-
- string argsname = get_cap_name((*f_iter)->get_name() + "_args");
+
+ string argsname = get_cap_name( (*f_iter)->get_name() + "_args");
vector<t_field*>::const_iterator fld_iter;
const vector<t_field*>& fields = arg_struct->get_members();
// Serialize the request
string calltype = (*f_iter)->is_oneway() ? "ONEWAY" : "CALL";
- f_service_ << indent() << "oprot_.writeMessageBegin(new TMessage(\"" << funname
- << "\", TMessageType." << calltype << ", seqid_));" << endl << indent()
- << "var args : " << argsname << " = new " << argsname << "();" << endl;
+ f_service_ <<
+ indent() << "oprot_.writeMessageBegin(new TMessage(\"" << funname << "\", TMessageType." << calltype << ", seqid_));" << endl <<
+ indent() << "var args : " << argsname << " = new " << argsname << "();" << endl;
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
- f_service_ << indent() << "args." << (*fld_iter)->get_name() << " = "
- << (*fld_iter)->get_name() << ";" << endl;
+ f_service_ <<
+ indent() << "args." << (*fld_iter)->get_name() << " = " << (*fld_iter)->get_name() << ";" << endl;
}
- f_service_ << indent() << "args.write(oprot_);" << endl << indent()
- << "oprot_.writeMessageEnd();" << endl;
-
- if (!((*f_iter)->is_oneway() || (*f_iter)->get_returntype()->is_void())) {
- f_service_ << indent() << "var retval : " << type_name((*f_iter)->get_returntype()) << ";"
- << endl;
+ f_service_ <<
+ indent() << "args.write(oprot_);" << endl <<
+ indent() << "oprot_.writeMessageEnd();" << endl;
+
+ if( ! ((*f_iter)->is_oneway() || (*f_iter)->get_returntype()->is_void())) {
+ f_service_ << indent() << "var retval : " << type_name((*f_iter)->get_returntype()) <<";" << endl;
}
-
+
if ((*f_iter)->is_oneway()) {
f_service_ << indent() << "oprot_.getTransport().flush();" << endl;
- } else {
+ }
+ else {
indent(f_service_) << "oprot_.getTransport().flush(function(error:Dynamic) : Void {" << endl;
indent_up();
- if (callbacks_) {
+ if( callbacks_) {
indent(f_service_) << "try {" << endl;
indent_up();
}
- string resultname = get_cap_name((*f_iter)->get_name() + "_result");
+ string resultname = get_cap_name( (*f_iter)->get_name() + "_result");
indent(f_service_) << "if (error != null) {" << endl;
indent_up();
- if (callbacks_) {
+ if( callbacks_) {
indent(f_service_) << "if (onError != null) onError(error);" << endl;
indent(f_service_) << "return;" << endl;
} else {
@@ -1721,7 +1785,7 @@ void t_haxe_generator::generate_service_client(t_service* tservice) {
indent_up();
indent(f_service_) << "var x = TApplicationException.read(iprot_);" << endl;
indent(f_service_) << "iprot_.readMessageEnd();" << endl;
- if (callbacks_) {
+ if( callbacks_) {
indent(f_service_) << "if (onError != null) onError(x);" << endl;
indent(f_service_) << "return;" << endl;
} else {
@@ -1729,8 +1793,7 @@ void t_haxe_generator::generate_service_client(t_service* tservice) {
}
indent_down();
indent(f_service_) << "}" << endl;
- indent(f_service_) << "var result : " << resultname << " = new " << resultname << "();"
- << endl;
+ indent(f_service_) << "var result : " << resultname << " = new " << resultname << "();" << endl;
indent(f_service_) << "result.read(iprot_);" << endl;
indent(f_service_) << "iprot_.readMessageEnd();" << endl;
@@ -1738,7 +1801,7 @@ void t_haxe_generator::generate_service_client(t_service* tservice) {
if (!(*f_iter)->get_returntype()->is_void()) {
indent(f_service_) << "if (result." << generate_isset_check("success") << ") {" << endl;
indent_up();
- if (callbacks_) {
+ if( callbacks_) {
indent(f_service_) << "if (onSuccess != null) onSuccess(result.success);" << endl;
indent(f_service_) << "return;" << endl;
} else {
@@ -1755,9 +1818,8 @@ void t_haxe_generator::generate_service_client(t_service* tservice) {
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
indent(f_service_) << "if (result." << (*x_iter)->get_name() << " != null) {" << endl;
indent_up();
- if (callbacks_) {
- indent(f_service_) << "if (onError != null) onError(result." << (*x_iter)->get_name()
- << ");" << endl;
+ if( callbacks_) {
+ indent(f_service_) << "if (onError != null) onError(result." << (*x_iter)->get_name() << ");" << endl;
indent(f_service_) << "return;" << endl;
} else {
indent(f_service_) << "throw result." << (*x_iter)->get_name() << ";" << endl;
@@ -1768,51 +1830,49 @@ void t_haxe_generator::generate_service_client(t_service* tservice) {
// If you get here it's an exception, unless a void function
if ((*f_iter)->get_returntype()->is_void()) {
- if (callbacks_) {
+ if( callbacks_) {
indent(f_service_) << "if (onSuccess != null) onSuccess();" << endl;
}
indent(f_service_) << "return;" << endl;
} else {
- if (callbacks_) {
+ if( callbacks_) {
indent(f_service_) << "if (onError != null)" << endl;
indent_up();
- indent(f_service_)
- << "onError( new TApplicationException(TApplicationException.MISSING_RESULT," << endl;
- indent(f_service_) << " \"" << (*f_iter)->get_name()
- << " failed: unknown result\"));" << endl;
+ indent(f_service_) << "onError( new TApplicationException(TApplicationException.MISSING_RESULT," << endl;
+ indent(f_service_) << " \"" << (*f_iter)->get_name() << " failed: unknown result\"));" << endl;
indent_down();
} else {
- indent(f_service_)
- << "throw new TApplicationException(TApplicationException.MISSING_RESULT," << endl;
- indent(f_service_) << " \"" << (*f_iter)->get_name()
- << " failed: unknown result\");" << endl;
+ indent(f_service_) << "throw new TApplicationException(TApplicationException.MISSING_RESULT," << endl;
+ indent(f_service_) << " \"" << (*f_iter)->get_name() << " failed: unknown result\");" << endl;
}
}
- if (callbacks_) {
+ if( callbacks_) {
indent_down();
indent(f_service_) << "} catch( e : TException) {" << endl;
indent_up();
indent(f_service_) << "if (onError != null) onError(e);" << endl;
indent_down();
indent(f_service_) << "}" << endl;
- }
-
+ }
+
indent_down();
- indent(f_service_) << "});" << endl;
+ indent(f_service_) <<
+ "});" << endl;
}
-
- if (!((*f_iter)->is_oneway() || (*f_iter)->get_returntype()->is_void())) {
+
+ if( ! ((*f_iter)->is_oneway() || (*f_iter)->get_returntype()->is_void())) {
f_service_ << indent() << "return retval;" << endl;
}
-
+
// Close function
scope_down(f_service_);
f_service_ << endl;
}
indent_down();
- indent(f_service_) << "}" << endl;
+ indent(f_service_) <<
+ "}" << endl;
}
/**
@@ -1834,32 +1894,36 @@ void t_haxe_generator::generate_service_server(t_service* tservice) {
}
// Generate the header portion
- indent(f_service_) << "class " << get_cap_name(service_name_) << "Processor" << extends_processor
- << " implements TProcessor {" << endl << endl;
+ indent(f_service_) <<
+ "class " << get_cap_name(service_name_) <<
+ "Processor" << extends_processor <<
+ " implements TProcessor {" <<
+ endl << endl;
indent_up();
- f_service_ << indent() << "private var " << get_cap_name(service_name_)
- << "_iface_ : " << get_cap_name(service_name_) << ";" << endl;
+ f_service_ <<
+ indent() << "private var " << get_cap_name(service_name_) << "_iface_ : " << get_cap_name(service_name_) << ";" << endl;
if (extends.empty()) {
- f_service_ << indent()
- << "private var PROCESS_MAP = new StringMap< Int->TProtocol->TProtocol->Void >();"
- << endl;
+ f_service_ <<
+ indent() << "private var PROCESS_MAP = new StringMap< Int->TProtocol->TProtocol->Void >();" << endl;
}
f_service_ << endl;
- indent(f_service_) << "public function new( iface : " << get_cap_name(service_name_) << ")"
- << endl;
+ indent(f_service_) <<
+ "public function new( iface : " << get_cap_name(service_name_) << ")" << endl;
scope_up(f_service_);
if (!extends.empty()) {
- f_service_ << indent() << "super(iface);" << endl;
+ f_service_ <<
+ indent() << "super(iface);" << endl;
}
- f_service_ << indent() << get_cap_name(service_name_) << "_iface_ = iface;" << endl;
+ f_service_ <<
+ indent() << get_cap_name(service_name_) << "_iface_ = iface;" << endl;
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
- f_service_ << indent() << "PROCESS_MAP.set(\"" << (*f_iter)->get_name() << "\", "
- << (*f_iter)->get_name() << "());" << endl;
+ f_service_ <<
+ indent() << "PROCESS_MAP.set(\"" << (*f_iter)->get_name() << "\", " << (*f_iter)->get_name() << "());" << endl;
}
scope_down(f_service_);
@@ -1868,32 +1932,34 @@ void t_haxe_generator::generate_service_server(t_service* tservice) {
// Generate the server implementation
string override = "";
if (tservice->get_extends() != NULL) {
- override = "override ";
+ override = "override ";
}
- indent(f_service_) << override
- << "public function process( iprot : TProtocol, oprot : TProtocol) : Bool"
- << endl;
+ indent(f_service_) << override << "public function process( iprot : TProtocol, oprot : TProtocol) : Bool" << endl;
scope_up(f_service_);
- f_service_ << indent() << "var msg : TMessage = iprot.readMessageBegin();" << endl;
+ f_service_ <<
+ indent() << "var msg : TMessage = iprot.readMessageBegin();" << endl;
// TODO(mcslee): validate message, was the seqid etc. legit?
// AS- If all method is oneway:
// do you have an oprot?
// do you you need nullcheck?
- f_service_
- << indent() << "var fn = PROCESS_MAP.get(msg.name);" << endl << indent()
- << "if (fn == null) {" << endl << indent() << " TProtocolUtil.skip(iprot, TType.STRUCT);"
- << endl << indent() << " iprot.readMessageEnd();" << endl << indent()
- << " var x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, \"Invalid "
- "method name: '\"+msg.name+\"'\");" << endl << indent()
- << " oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid));"
- << endl << indent() << " x.write(oprot);" << endl << indent() << " oprot.writeMessageEnd();"
- << endl << indent() << " oprot.getTransport().flush();" << endl << indent()
- << " return true;" << endl << indent() << "}" << endl << indent()
- << "fn( msg.seqid, iprot, oprot);" << endl;
-
- f_service_ << indent() << "return true;" << endl;
+ f_service_ <<
+ indent() << "var fn = PROCESS_MAP.get(msg.name);" << endl <<
+ indent() << "if (fn == null) {" << endl <<
+ indent() << " TProtocolUtil.skip(iprot, TType.STRUCT);" << endl <<
+ indent() << " iprot.readMessageEnd();" << endl <<
+ indent() << " var x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, \"Invalid method name: '\"+msg.name+\"'\");" << endl <<
+ indent() << " oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid));" << endl <<
+ indent() << " x.write(oprot);" << endl <<
+ indent() << " oprot.writeMessageEnd();" << endl <<
+ indent() << " oprot.getTransport().flush();" << endl <<
+ indent() << " return true;" << endl <<
+ indent() << "}" << endl <<
+ indent() << "fn( msg.seqid, iprot, oprot);" << endl;
+
+ f_service_ <<
+ indent() << "return true;" << endl;
scope_down(f_service_);
f_service_ << endl;
@@ -1904,7 +1970,9 @@ void t_haxe_generator::generate_service_server(t_service* tservice) {
}
indent_down();
- indent(f_service_) << "}" << endl << endl;
+ indent(f_service_) <<
+ "}" << endl <<
+ endl;
}
/**
@@ -1917,7 +1985,7 @@ void t_haxe_generator::generate_function_helpers(t_function* tfunction) {
return;
}
- string resultname = get_cap_name(tfunction->get_name() + "_result");
+ string resultname = get_cap_name( tfunction->get_name() + "_result");
t_struct result(program_, resultname);
t_field success(tfunction->get_returntype(), "success", 0);
if (!tfunction->get_returntype()->is_void()) {
@@ -1939,24 +2007,27 @@ void t_haxe_generator::generate_function_helpers(t_function* tfunction) {
*
* @param tfunction The function to write a dispatcher for
*/
-void t_haxe_generator::generate_process_function(t_service* tservice, t_function* tfunction) {
- (void)tservice;
+void t_haxe_generator::generate_process_function(t_service* tservice,
+ t_function* tfunction) {
+ (void) tservice;
// Open class
- indent(f_service_) << "private function " << tfunction->get_name()
- << "() : Int->TProtocol->TProtocol->Void {" << endl;
+ indent(f_service_) <<
+ "private function " << tfunction->get_name() << "() : Int->TProtocol->TProtocol->Void {" << endl;
indent_up();
// Open function
- indent(f_service_) << "return function( seqid : Int, iprot : TProtocol, oprot : TProtocol) : Void"
- << endl;
+ indent(f_service_) <<
+ "return function( seqid : Int, iprot : TProtocol, oprot : TProtocol) : Void"
+ << endl;
scope_up(f_service_);
- string argsname = get_cap_name(tfunction->get_name() + "_args");
- string resultname = get_cap_name(tfunction->get_name() + "_result");
+ string argsname = get_cap_name( tfunction->get_name() + "_args");
+ string resultname = get_cap_name( tfunction->get_name() + "_result");
- f_service_ << indent() << "var args : " << argsname << " = new " << argsname << "();" << endl
- << indent() << "args.read(iprot);" << endl << indent() << "iprot.readMessageEnd();"
- << endl;
+ f_service_ <<
+ indent() << "var args : "<< argsname << " = new " << argsname << "();" << endl <<
+ indent() << "args.read(iprot);" << endl <<
+ indent() << "iprot.readMessageEnd();" << endl;
t_struct* xs = tfunction->get_xceptions();
const std::vector<t_field*>& xceptions = xs->get_members();
@@ -1964,51 +2035,53 @@ void t_haxe_generator::generate_process_function(t_service* tservice, t_function
// Declare result for non oneway function
if (!tfunction->is_oneway()) {
- f_service_ << indent() << "var result : " << resultname << " = new " << resultname << "();"
- << endl;
+ f_service_ <<
+ indent() << "var result : " << resultname << " = new " << resultname << "();" << endl;
}
// Try block for any function to catch (defined or undefined) exceptions
- f_service_ << indent() << "try {" << endl;
+ f_service_ <<
+ indent() << "try {" << endl;
indent_up();
- if (callbacks_) {
+ if(callbacks_) {
// callback function style onError/onSuccess
// Generate the function call
t_struct* arg_struct = tfunction->get_arglist();
const std::vector<t_field*>& fields = arg_struct->get_members();
vector<t_field*>::const_iterator f_iter;
-
+
f_service_ << indent();
- f_service_ << get_cap_name(service_name_) << "_iface_." << tfunction->get_name() << "(";
+ f_service_ <<
+ get_cap_name(service_name_) << "_iface_." << tfunction->get_name() << "(";
bool first = true;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
if (first) {
first = false;
} else {
f_service_ << ", ";
- }
+ }
f_service_ << "args." << (*f_iter)->get_name();
}
-
- if (tfunction->is_oneway()) {
+
+ if( tfunction->is_oneway()) {
f_service_ << ");" << endl;
} else {
if (first) {
first = false;
} else {
f_service_ << ", ";
- }
+ }
string on_success = generate_service_method_onsuccess(tfunction, false, true);
indent_up();
f_service_ << endl;
indent(f_service_) << "null, // errors are thrown by the handler" << endl;
- if (tfunction->get_returntype()->is_void()) {
+ if( tfunction->get_returntype()->is_void()) {
indent(f_service_) << "null); // no retval" << endl;
} else {
indent(f_service_) << "function" << on_success.c_str() << " {" << endl;
- if (!tfunction->get_returntype()->is_void()) {
+ if( ! tfunction->get_returntype()->is_void()) {
indent_up();
indent(f_service_) << "result.success = retval;" << endl;
indent_down();
@@ -2020,40 +2093,41 @@ void t_haxe_generator::generate_process_function(t_service* tservice, t_function
} else {
// normal function():result style
-
+
// Generate the function call
t_struct* arg_struct = tfunction->get_arglist();
const std::vector<t_field*>& fields = arg_struct->get_members();
vector<t_field*>::const_iterator f_iter;
-
+
f_service_ << indent();
- if (!(tfunction->is_oneway() || tfunction->get_returntype()->is_void())) {
+ if( ! (tfunction->is_oneway() || tfunction->get_returntype()->is_void())) {
f_service_ << "result.success = ";
}
- f_service_ << get_cap_name(service_name_) << "_iface_." << tfunction->get_name() << "(";
+ f_service_ <<
+ get_cap_name(service_name_) << "_iface_." << tfunction->get_name() << "(";
bool first = true;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
if (first) {
first = false;
} else {
f_service_ << ", ";
- }
+ }
f_service_ << "args." << (*f_iter)->get_name();
}
f_service_ << ");" << endl;
+
}
indent_down();
f_service_ << indent() << "}";
- if (!tfunction->is_oneway()) {
+ if( ! tfunction->is_oneway()) {
// catch exceptions defined in the IDL
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
- f_service_ << " catch (" << (*x_iter)->get_name() << ":"
- << get_cap_n
<TRUNCATED>