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:28 UTC
[36/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_as3_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_as3_generator.cc b/compiler/cpp/src/generate/t_as3_generator.cc
index 2c43430..a8c4889 100644
--- a/compiler/cpp/src/generate/t_as3_generator.cc
+++ b/compiler/cpp/src/generate/t_as3_generator.cc
@@ -37,19 +37,21 @@ 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
/**
* AS3 code generator.
*
*/
class t_as3_generator : public t_oop_generator {
-public:
- t_as3_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_as3_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("bindable");
@@ -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,12 +88,8 @@ public:
void generate_as3_struct(t_struct* tstruct, bool is_exception);
- void generate_as3_struct_definition(std::ofstream& out,
- t_struct* tstruct,
- bool is_xception = false,
- bool in_class = false,
- bool is_result = false);
- // removed -- equality,compare_to
+ void generate_as3_struct_definition(std::ofstream& out, t_struct* tstruct, bool is_xception=false, bool in_class=false, bool is_result=false);
+ //removed -- equality,compare_to
void generate_as3_struct_reader(std::ofstream& out, t_struct* tstruct);
void generate_as3_validator(std::ofstream& out, t_struct* tstruct);
void generate_as3_struct_result_writer(std::ofstream& out, t_struct* tstruct);
@@ -108,14 +98,8 @@ public:
void generate_as3_meta_data_map(std::ofstream& out, t_struct* tstruct);
void generate_field_value_meta_data(std::ofstream& out, t_type* type);
std::string get_as3_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_as3_bean_boilerplate(std::ofstream& out, t_struct* tstruct, bool bindable);
@@ -125,50 +109,72 @@ 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);
+ //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_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);
/**
* 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_as3_doc(std::ofstream& out, t_doc* tdoc);
+ void generate_as3_doc (std::ofstream& out,
+ t_doc* tdoc);
- void generate_as3_doc(std::ofstream& out, t_function* tdoc);
+ void generate_as3_doc (std::ofstream& out,
+ t_function* tdoc);
/**
* Helper rendering functions
@@ -179,10 +185,10 @@ public:
std::string as3_thrift_imports();
std::string as3_thrift_gen_imports(t_struct* tstruct, string& imports);
std::string as3_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(t_function* tfunction, std::string prefix = "");
+ 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(t_function* tfunction, std::string prefix="");
std::string argument_list(t_struct* tstruct);
std::string type_to_enum(t_type* ttype);
std::string get_enum_class_name(t_type* type);
@@ -190,13 +196,17 @@ public:
bool type_can_be_null(t_type* ttype) {
ttype = get_true_type(ttype);
- return ttype->is_container() || ttype->is_struct() || ttype->is_xception()
- || ttype->is_string();
+ return
+ ttype->is_container() ||
+ ttype->is_struct() ||
+ ttype->is_xception() ||
+ ttype->is_string();
}
std::string constant_name(std::string name);
-private:
+ private:
+
/**
* File streams
*/
@@ -208,6 +218,7 @@ private:
bool bindable_;
};
+
/**
* Prepares for file generation by opening up the necessary file output
* streams.
@@ -225,7 +236,7 @@ void t_as3_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;
@@ -253,8 +264,11 @@ string t_as3_generator::as3_package() {
* @return List of imports for As3 types that are used in here
*/
string t_as3_generator::as3_type_imports() {
- return string() + "import org.apache.thrift.Set;\n" + "import flash.utils.ByteArray;\n"
- + "import flash.utils.Dictionary;\n\n";
+ return
+ string() +
+ "import org.apache.thrift.Set;\n" +
+ "import flash.utils.ByteArray;\n" +
+ "import flash.utils.Dictionary;\n\n";
}
/**
@@ -263,8 +277,11 @@ string t_as3_generator::as3_type_imports() {
* @return List of imports necessary for thrift
*/
string t_as3_generator::as3_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";
}
/**
@@ -277,7 +294,7 @@ string t_as3_generator::as3_thrift_gen_imports(t_struct* tstruct, string& import
const vector<t_field*>& members = tstruct->get_members();
vector<t_field*>::const_iterator m_iter;
- // For each type check if it is from a differnet namespace
+ //For each type check if it is from a differnet 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_) {
@@ -292,6 +309,7 @@ string t_as3_generator::as3_thrift_gen_imports(t_struct* tstruct, string& import
return imports;
}
+
/**
* Prints imports needed for a given type
*
@@ -302,31 +320,31 @@ string t_as3_generator::as3_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 differnet namespace
+ //For each type check if it is from a differnet 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("as3");
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");
}
}
}
as3_thrift_gen_imports((*f_iter)->get_arglist(), imports);
as3_thrift_gen_imports((*f_iter)->get_xceptions(), imports);
+
}
return imports;
+
}
/**
* Nothing in As3
*/
-void t_as3_generator::close_generator() {
-}
+void t_as3_generator::close_generator() {}
/**
* Generates a typedef. This is not done in As3, since it does
@@ -336,7 +354,7 @@ void t_as3_generator::close_generator() {
* @param ttypedef The type definition
*/
void t_as3_generator::generate_typedef(t_typedef* ttypedef) {
- (void)ttypedef;
+ (void) ttypedef;
}
/**
@@ -346,27 +364,32 @@ void t_as3_generator::generate_typedef(t_typedef* ttypedef) {
*/
void t_as3_generator::generate_enum(t_enum* tenum) {
// Make output file
- string f_enum_name = package_dir_ + "/" + (tenum->get_name()) + ".as";
+ string f_enum_name = package_dir_+"/"+(tenum->get_name())+".as";
ofstream f_enum;
f_enum.open(f_enum_name.c_str());
// Comment and package it
- f_enum << autogen_comment() << as3_package() << endl;
+ f_enum <<
+ autogen_comment() <<
+ as3_package() << endl;
scope_up(f_enum);
// Add as3 imports
- f_enum << string() + "import org.apache.thrift.Set;" << endl << "import flash.utils.Dictionary;"
- << endl;
+ f_enum << string() +
+ "import org.apache.thrift.Set;" << endl <<
+ "import flash.utils.Dictionary;" << endl;
- indent(f_enum) << "public class " << tenum->get_name() << " ";
+ indent(f_enum) <<
+ "public class " << 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 const " << (*c_iter)->get_name() << ":int = " << value << ";"
- << endl;
+ indent(f_enum) <<
+ "public static const " << (*c_iter)->get_name() <<
+ ":int = " << value << ";" << endl;
}
// Create a static Set with all valid values for this enum
@@ -387,8 +410,7 @@ void t_as3_generator::generate_enum(t_enum* tenum) {
scope_up(f_enum);
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- indent(f_enum) << "VALUES_TO_NAMES[" << (*c_iter)->get_name() << "] = \""
- << (*c_iter)->get_name() << "\";" << endl;
+ indent(f_enum) << "VALUES_TO_NAMES[" << (*c_iter)->get_name() << "] = \"" << (*c_iter)->get_name() << "\";" << endl;
}
f_enum << endl;
@@ -409,19 +431,24 @@ void t_as3_generator::generate_consts(std::vector<t_const*> consts) {
return;
}
- string f_consts_name = package_dir_ + "/" + program_name_ + "Constants.as";
+ string f_consts_name = package_dir_+ "/" + program_name_ + "Constants.as";
ofstream f_consts;
f_consts.open(f_consts_name.c_str());
// Print header
- f_consts << autogen_comment() << as3_package();
+ f_consts <<
+ autogen_comment() << as3_package();
scope_up(f_consts);
f_consts << endl;
f_consts << as3_type_imports();
- indent(f_consts) << "public class " << program_name_ << "Constants {" << endl << endl;
+
+
+ indent(f_consts) <<
+ "public class " << program_name_ << "Constants {" << endl <<
+ endl;
indent_up();
vector<t_const*>::iterator c_iter;
for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
@@ -432,22 +459,19 @@ void t_as3_generator::generate_consts(std::vector<t_const*> consts) {
false);
}
indent_down();
- indent(f_consts) << "}" << endl;
+ indent(f_consts) <<
+ "}" << endl;
scope_down(f_consts);
f_consts.close();
}
-void t_as3_generator::print_const_value(std::ofstream& out,
- string name,
- t_type* type,
- t_const_value* value,
- bool in_static,
- bool defval) {
+void t_as3_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 const ");
+ out <<
+ (in_static ? "var " : "public static const ");
}
if (type->is_base_type()) {
string v2 = render_const_value(out, name, type, value);
@@ -458,7 +482,7 @@ void t_as3_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;
@@ -467,8 +491,7 @@ void t_as3_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();
@@ -498,7 +521,7 @@ void t_as3_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;
@@ -526,7 +549,7 @@ void t_as3_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;
@@ -546,8 +569,7 @@ void t_as3_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();
@@ -561,44 +583,41 @@ void t_as3_generator::print_const_value(std::ofstream& out,
}
}
-string t_as3_generator::render_const_value(ofstream& out,
- string name,
- t_type* type,
- t_const_value* value) {
- (void)name;
+string t_as3_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();
@@ -611,6 +630,7 @@ string t_as3_generator::render_const_value(ofstream& out,
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.
@@ -630,33 +650,42 @@ void t_as3_generator::generate_xception(t_struct* txception) {
generate_as3_struct(txception, true);
}
+
/**
* As3 struct definition.
*
* @param tstruct The struct definition
*/
-void t_as3_generator::generate_as3_struct(t_struct* tstruct, bool is_exception) {
+void t_as3_generator::generate_as3_struct(t_struct* tstruct,
+ bool is_exception) {
// Make output file
- string f_struct_name = package_dir_ + "/" + (tstruct->get_name()) + ".as";
+ string f_struct_name = package_dir_+"/"+(tstruct->get_name())+".as";
ofstream f_struct;
f_struct.open(f_struct_name.c_str());
- f_struct << autogen_comment() << as3_package();
+ f_struct <<
+ autogen_comment() <<
+ as3_package();
scope_up(f_struct);
f_struct << endl;
string imports;
- f_struct << as3_type_imports() << as3_thrift_imports() << as3_thrift_gen_imports(tstruct, imports)
- << endl;
+ f_struct <<
+ as3_type_imports() <<
+ as3_thrift_imports() <<
+ as3_thrift_gen_imports(tstruct, imports) << endl;
- if (bindable_ && !is_exception) {
- f_struct << "import flash.events.Event;" << endl << "import flash.events.EventDispatcher;"
- << endl << "import mx.events.PropertyChangeEvent;" << endl;
+ if (bindable_ && ! is_exception) {
+ f_struct << "import flash.events.Event;" << endl <<
+ "import flash.events.EventDispatcher;" << endl <<
+ "import mx.events.PropertyChangeEvent;" << endl;
}
- generate_as3_struct_definition(f_struct, tstruct, is_exception);
+ generate_as3_struct_definition(f_struct,
+ tstruct,
+ is_exception);
scope_down(f_struct); // end of package
f_struct.close();
@@ -672,51 +701,51 @@ void t_as3_generator::generate_as3_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_as3_generator::generate_as3_struct_definition(ofstream& out,
- t_struct* tstruct,
- bool is_exception,
- bool in_class,
- bool is_result) {
+void t_as3_generator::generate_as3_struct_definition(ofstream &out,
+ t_struct* tstruct,
+ bool is_exception,
+ bool in_class,
+ bool is_result) {
generate_as3_doc(out, tstruct);
bool is_final = (tstruct->annotations_.find("final") != tstruct->annotations_.end());
- bool bindable = !is_exception && !in_class && bindable_;
+ bool bindable = ! is_exception && ! in_class && bindable_;
- indent(out) << (in_class ? "" : "public ") << (is_final ? "final " : "") << "class "
- << tstruct->get_name() << " ";
+ indent(out) << (in_class ? "" : "public ") << (is_final ? "final " : "") <<
+ "class " << tstruct->get_name() << " ";
if (is_exception) {
out << "extends Error ";
- } else if (bindable) {
+ }
+ else if (bindable) {
out << "extends EventDispatcher ";
}
out << "implements TBase ";
scope_up(out);
- indent(out) << "private static const STRUCT_DESC:TStruct = new TStruct(\"" << tstruct->get_name()
- << "\");" << endl;
+ indent(out) <<
+ "private static const STRUCT_DESC:TStruct = new TStruct(\"" << tstruct->get_name() << "\");" << endl;
// Members are public for -as3, private for -as3bean
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) << "private static const " << constant_name((*m_iter)->get_name())
- << "_FIELD_DESC:TField = new TField(\"" << (*m_iter)->get_name() << "\", "
- << type_to_enum((*m_iter)->get_type()) << ", " << (*m_iter)->get_key() << ");"
- << endl;
+ indent(out) <<
+ "private static const " << constant_name((*m_iter)->get_name()) <<
+ "_FIELD_DESC:TField = 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_as3_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) << "public static const " << upcase_string((*m_iter)->get_name())
- << ":int = " << (*m_iter)->get_key() << ";" << endl;
+ indent(out) << "public static const " << upcase_string((*m_iter)->get_name()) << ":int = " << (*m_iter)->get_key() << ";" << endl;
}
out << endl;
@@ -724,11 +753,11 @@ void t_as3_generator::generate_as3_struct_definition(ofstream& out,
// 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() << ":Boolean = false;"
- << endl;
+ if (!type_can_be_null((*m_iter)->get_type())){
+ indent(out) <<
+ "private var __isset_" << (*m_iter)->get_name() << ":Boolean = false;" << endl;
+ }
}
- }
}
out << endl;
@@ -738,18 +767,18 @@ void t_as3_generator::generate_as3_struct_definition(ofstream& out,
// Static initializer to populate global class to struct metadata map
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 << endl;
// Default constructor
- indent(out) << "public function " << tstruct->get_name() << "() {" << endl;
+ indent(out) <<
+ "public function " << tstruct->get_name() << "() {" << endl;
indent_up();
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();
@@ -776,87 +805,107 @@ void t_as3_generator::generate_as3_struct_definition(ofstream& out,
*
* @param tstruct The struct definition
*/
-void t_as3_generator::generate_as3_struct_reader(ofstream& out, t_struct* tstruct) {
- out << indent() << "public function read(iprot:TProtocol):void {" << endl;
+void t_as3_generator::generate_as3_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);
+ indent(out) <<
+ "while (true)" << endl;
+ scope_up(out);
- // Read beginning field marker
- indent(out) << "field = iprot.readFieldBegin();" << endl;
+ // Read beginning field marker
+ indent(out) <<
+ "field = iprot.readFieldBegin();" << 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;
+ // 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;
- // Switch statement on the field we are reading
- indent(out) << "switch (field.id)" << endl;
+ // Switch statement on the field we are reading
+ indent(out) <<
+ "switch (field.id)" << endl;
- scope_up(out);
+ scope_up(out);
- // 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()) << ":" << endl;
- indent_up();
- indent(out) << "if (field.type == " << type_to_enum((*f_iter)->get_type()) << ") {" << endl;
- indent_up();
+ // 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()) << ":" << endl;
+ indent_up();
+ indent(out) <<
+ "if (field.type == " << type_to_enum((*f_iter)->get_type()) << ") {" << endl;
+ indent_up();
- 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() << "break;" << endl;
- indent_down();
- }
+ 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() << "break;" << endl;
+ indent_down();
+ }
- // In the default case we skip the field
- out << indent() << "default:" << endl << indent() << " TProtocolUtil.skip(iprot, field.type);"
- << endl << indent() << " break;" << endl;
+ // In the default case we skip the field
+ out <<
+ indent() << "default:" << endl <<
+ indent() << " TProtocolUtil.skip(iprot, field.type);" << endl <<
+ indent() << " break;" << endl;
- scope_down(out);
+ scope_down(out);
- // Read field end marker
- indent(out) << "iprot.readFieldEnd();" << endl;
+ // Read field end marker
+ indent(out) <<
+ "iprot.readFieldEnd();" << endl;
- scope_down(out);
+ scope_down(out);
- out << indent() << "iprot.readStructEnd();" << endl << endl;
+ out <<
+ indent() << "iprot.readStructEnd();" << endl << endl;
- // in non-beans style, 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 TProtocolError(TProtocolError.UNKNOWN, \"Required field '"
- << (*f_iter)->get_name()
- << "' was not found in serialized data! Struct: \" + toString());" << endl << indent()
- << "}" << endl;
+ // in non-beans style, 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 TProtocolError(TProtocolError.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 as3 method to perform various checks
// (e.g. check that all required fields are set)
-void t_as3_generator::generate_as3_validator(ofstream& out, t_struct* tstruct) {
+void t_as3_generator::generate_as3_validator(ofstream& out,
+ t_struct* tstruct){
indent(out) << "public function validate():void {" << endl;
indent_up();
@@ -868,13 +917,10 @@ void t_as3_generator::generate_as3_validator(ofstream& out, t_struct* tstruct) {
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 TProtocolError(TProtocolError.UNKNOWN, \"Required field '"
- << (*f_iter)->get_name() << "' was not present! Struct: \" + toString());"
- << endl;
+ indent(out) << " throw new TProtocolError(TProtocolError.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 and you chose the non-beans generator." << endl;
+ indent(out) << "// alas, we cannot check '" << (*f_iter)->get_name() << "' because it's a primitive and you chose the non-beans generator." << endl;
}
}
}
@@ -885,13 +931,10 @@ void t_as3_generator::generate_as3_validator(ofstream& out, t_struct* tstruct) {
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_enum_class_name(type)
- << ".VALID_VALUES.contains(" << field->get_name() << ")){" << endl;
+ if (type->is_enum()){
+ indent(out) << "if (" << generate_isset_check(field) << " && !" << get_enum_class_name(type) << ".VALID_VALUES.contains(" << field->get_name() << ")){" << endl;
indent_up();
- indent(out) << "throw new TProtocolError(TProtocolError.UNKNOWN, \"The field '"
- << field->get_name() << "' has been assigned the invalid value \" + "
- << field->get_name() << ");" << endl;
+ indent(out) << "throw new TProtocolError(TProtocolError.UNKNOWN, \"The field '" << field->get_name() << "' has been assigned the invalid value \" + " << field->get_name() << ");" << endl;
indent_down();
indent(out) << "}" << endl;
}
@@ -906,8 +949,10 @@ void t_as3_generator::generate_as3_validator(ofstream& out, t_struct* tstruct) {
*
* @param tstruct The struct definition
*/
-void t_as3_generator::generate_as3_struct_writer(ofstream& out, t_struct* tstruct) {
- out << indent() << "public function write(oprot:TProtocol):void {" << endl;
+void t_as3_generator::generate_as3_struct_writer(ofstream& out,
+ t_struct* tstruct) {
+ out <<
+ indent() << "public function write(oprot:TProtocol):void {" << endl;
indent_up();
string name = tstruct->get_name();
@@ -922,18 +967,19 @@ void t_as3_generator::generate_as3_struct_writer(ofstream& out, t_struct* tstruc
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();
@@ -941,11 +987,14 @@ void t_as3_generator::generate_as3_struct_writer(ofstream& out, t_struct* tstruc
}
}
// 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;
}
/**
@@ -956,8 +1005,10 @@ void t_as3_generator::generate_as3_struct_writer(ofstream& out, t_struct* tstruc
*
* @param tstruct The struct definition
*/
-void t_as3_generator::generate_as3_struct_result_writer(ofstream& out, t_struct* tstruct) {
- out << indent() << "public function write(oprot:TProtocol):void {" << endl;
+void t_as3_generator::generate_as3_struct_result_writer(ofstream& out,
+ t_struct* tstruct) {
+ out <<
+ indent() << "public function write(oprot:TProtocol):void {" << endl;
indent_up();
string name = tstruct->get_name();
@@ -970,7 +1021,9 @@ void t_as3_generator::generate_as3_struct_result_writer(ofstream& out, t_struct*
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 ";
}
@@ -979,44 +1032,42 @@ void t_as3_generator::generate_as3_struct_result_writer(ofstream& out, t_struct*
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_as3_generator::generate_reflection_getters(ostringstream& out,
- t_type* type,
- string field_name,
- string cap_name) {
- (void)type;
- (void)cap_name;
+void t_as3_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) << ":" << endl;
indent_up();
indent(out) << "return this." << field_name << ";" << endl;
indent_down();
}
-void t_as3_generator::generate_reflection_setters(ostringstream& out,
- t_type* type,
- string field_name,
- string cap_name) {
- (void)type;
- (void)cap_name;
+void t_as3_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) << ":" << endl;
indent_up();
indent(out) << "if (value == null) {" << endl;
@@ -1029,8 +1080,7 @@ void t_as3_generator::generate_reflection_setters(ostringstream& out,
indent_down();
}
-void t_as3_generator::generate_generic_field_getters_setters(std::ofstream& out,
- t_struct* tstruct) {
+void t_as3_generator::generate_generic_field_getters_setters(std::ofstream& out, t_struct* tstruct) {
std::ostringstream getter_stream;
std::ostringstream setter_stream;
@@ -1050,6 +1100,7 @@ void t_as3_generator::generate_generic_field_getters_setters(std::ofstream& out,
indent_down();
}
+
// create the setter
indent(out) << "public function setFieldValue(fieldID:int, value:*):void {" << endl;
indent_up();
@@ -1085,13 +1136,12 @@ void t_as3_generator::generate_generic_field_getters_setters(std::ofstream& out,
}
// Creates a generic isSet method that takes the field number as argument
-void t_as3_generator::generate_generic_isset_method(std::ofstream& out, t_struct* tstruct) {
+void t_as3_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):Boolean {" << endl;
indent_up();
indent(out) << "switch (fieldID) {" << endl;
@@ -1120,8 +1170,7 @@ void t_as3_generator::generate_generic_isset_method(std::ofstream& out, t_struct
* @param tstruct The struct definition
*/
void t_as3_generator::generate_as3_bean_boilerplate(ofstream& out,
- t_struct* tstruct,
- bool bindable) {
+ t_struct* tstruct, bool bindable) {
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) {
@@ -1132,7 +1181,8 @@ void t_as3_generator::generate_as3_bean_boilerplate(ofstream& out,
// Simple getter
generate_as3_doc(out, field);
- indent(out) << "public function get " << field_name << "():" << type_name(type) << " {" << endl;
+ indent(out) << "public function get " << field_name << "():" <<
+ type_name(type) << " {" << endl;
indent_up();
indent(out) << "return this._" << field_name << ";" << endl;
indent_down();
@@ -1144,27 +1194,23 @@ void t_as3_generator::generate_as3_bean_boilerplate(ofstream& out,
if (bindable) {
indent(out) << "[Bindable(event=\"" << propName << "\")]" << endl;
}
- indent(out) << "public function set " << field_name << "(" << field_name << ":"
- << type_name(type) << "):void {" << endl;
+ indent(out) << "public function set " << field_name << "(" << field_name
+ << ":" << type_name(type) << "):void {" << endl;
indent_up();
- indent(out) << "this._" << field_name << " = " << field_name << ";" << endl;
+ indent(out) << "this._" << field_name << " = " << field_name << ";" <<
+ endl;
generate_isset_set(out, field);
if (bindable) {
// We have to use a custom event rather than the default, because if you use the default,
- // the setter only gets called if the value has changed - this means calling
- // foo.setIntValue(0)
- // will not cause foo.isIntValueSet() to return true since the value of foo._intValue wasn't
- // changed
+ // the setter only gets called if the value has changed - this means calling foo.setIntValue(0)
+ // will not cause foo.isIntValueSet() to return true since the value of foo._intValue wasn't changed
// so the setter was never called.
indent(out) << "dispatchEvent(new Event(\"" << propName << "\"));" << endl;
- // However, if you just use a custom event, then collections won't be able to detect when
- // elements
- // in the collections have changed since they listed for PropertyChangeEvents. So, we
- // dispatch both.
- indent(out) << "dispatchEvent(new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE));"
- << endl;
+ // However, if you just use a custom event, then collections won't be able to detect when elements
+ // in the collections have changed since they listed for PropertyChangeEvents. So, we dispatch both.
+ indent(out) << "dispatchEvent(new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE));" << endl;
}
indent_down();
indent(out) << "}" << endl << endl;
@@ -1181,10 +1227,8 @@ void t_as3_generator::generate_as3_bean_boilerplate(ofstream& out,
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) << "public function is" << get_cap_name("set") << cap_name << "():Boolean {"
- << 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 << "():Boolean {" << endl;
indent_up();
if (type_can_be_null(type)) {
indent(out) << "return this." << field_name << " != null;" << endl;
@@ -1202,14 +1246,13 @@ void t_as3_generator::generate_as3_bean_boilerplate(ofstream& out,
* @param tstruct The struct definition
*/
void t_as3_generator::generate_as3_struct_tostring(ofstream& out,
- t_struct* tstruct,
- bool bindable) {
+ t_struct* tstruct, bool bindable) {
// If it's bindable, it extends EventDispatcher so toString is an override.
- out << indent() << "public " << (bindable ? "override " : "") << "function toString():String {"
- << endl;
+ out << indent() << "public " << (bindable ? "override " : "") << "function toString():String {" << endl;
indent_up();
- out << indent() << "var ret:String = new String(\"" << tstruct->get_name() << "(\");" << endl;
+ out <<
+ indent() << "var ret:String = new String(\"" << tstruct->get_name() << "(\");" << endl;
out << indent() << "var first:Boolean = true;" << endl << endl;
const vector<t_field*>& fields = tstruct->get_members();
@@ -1217,7 +1260,7 @@ void t_as3_generator::generate_as3_struct_tostring(ofstream& out,
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();
}
@@ -1238,10 +1281,8 @@ void t_as3_generator::generate_as3_struct_tostring(ofstream& out,
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_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_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;
@@ -1260,16 +1301,19 @@ void t_as3_generator::generate_as3_struct_tostring(ofstream& out,
}
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;
}
/**
@@ -1278,7 +1322,8 @@ void t_as3_generator::generate_as3_struct_tostring(ofstream& out,
*
* @param tstruct The struct definition
*/
-void t_as3_generator::generate_as3_meta_data_map(ofstream& out, t_struct* tstruct) {
+void t_as3_generator::generate_as3_meta_data_map(ofstream& out,
+ t_struct* tstruct) {
const vector<t_field*>& fields = tstruct->get_members();
vector<t_field*>::const_iterator f_iter;
@@ -1291,8 +1336,7 @@ void t_as3_generator::generate_as3_meta_data_map(ofstream& out, t_struct* tstruc
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) << "] = new FieldMetaData(\""
- << field_name << "\", ";
+ indent(out) << "metaDataMap[" << upcase_string(field_name) << "] = new FieldMetaData(\"" << field_name << "\", ";
// Set field requirement type (required, optional, etc.)
if (field->get_req() == t_field::T_REQUIRED) {
@@ -1305,7 +1349,7 @@ void t_as3_generator::generate_as3_meta_data_map(ofstream& out, t_struct* tstruc
// Create value meta data
generate_field_value_meta_data(out, field->get_type());
- out << ");" << endl;
+ out << ");" << endl;
}
scope_down(out);
}
@@ -1316,7 +1360,7 @@ void t_as3_generator::generate_as3_meta_data_map(ofstream& out, t_struct* tstruc
* (e.g. for the type struct it returns "TType.STRUCT")
*/
std::string t_as3_generator::get_as3_type_string(t_type* type) {
- if (type->is_list()) {
+ if (type->is_list()){
return "TType.LIST";
} else if (type->is_map()) {
return "TType.MAP";
@@ -1330,58 +1374,37 @@ std::string t_as3_generator::get_as3_type_string(t_type* type) {
return get_as3_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_as3_generator::get_as3_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_as3_generator::get_as3_type_string!"); break; // This should never happen!
}
} else {
- throw std::runtime_error(
- "Unknown thrift type \"" + type->get_name()
- + "\" passed to t_as3_generator::get_as3_type_string!"); // This should never happen!
+ throw std::runtime_error("Unknown thrift type \"" + type->get_name() + "\" passed to t_as3_generator::get_as3_type_string!"); // This should never happen!
}
}
-void t_as3_generator::generate_field_value_meta_data(std::ofstream& out, t_type* type) {
+void t_as3_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()) {
+ } 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
+ } 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();
@@ -1397,6 +1420,7 @@ void t_as3_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
@@ -1407,20 +1431,23 @@ void t_as3_generator::generate_field_value_meta_data(std::ofstream& out, t_type*
*/
void t_as3_generator::generate_service(t_service* tservice) {
// Make interface file
- string f_service_name = package_dir_ + "/" + service_name_ + ".as";
+ string f_service_name = package_dir_+"/"+service_name_+".as";
f_service_.open(f_service_name.c_str());
- f_service_ << autogen_comment() << as3_package();
+ f_service_ <<
+ autogen_comment() << as3_package();
scope_up(f_service_);
- f_service_ << endl << as3_type_imports() << as3_thrift_imports()
- << as3_thrift_gen_imports(tservice);
+ f_service_ << endl <<
+ as3_type_imports() <<
+ as3_thrift_imports() <<
+ as3_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("as3");
- if (!parent_namespace.empty() && parent_namespace != package_name_) {
+ if(!parent_namespace.empty() && parent_namespace != package_name_) {
f_service_ << "import " << type_name(parent) << ";" << endl;
}
}
@@ -1433,20 +1460,24 @@ void t_as3_generator::generate_service(t_service* tservice) {
f_service_.close();
// Now make the implementation/client file
- f_service_name = package_dir_ + "/" + service_name_ + "Impl.as";
+ f_service_name = package_dir_+"/"+service_name_+"Impl.as";
f_service_.open(f_service_name.c_str());
- f_service_ << autogen_comment() << as3_package();
+ f_service_ <<
+ autogen_comment() << as3_package();
scope_up(f_service_);
- f_service_ << endl << as3_type_imports() << as3_thrift_imports()
- << as3_thrift_gen_imports(tservice);
+ f_service_ << endl <<
+ as3_type_imports() <<
+ as3_thrift_imports() <<
+ as3_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("as3");
- if (!parent_namespace.empty() && parent_namespace != package_name_) {
+ if(!parent_namespace.empty() && parent_namespace != package_name_) {
f_service_ << "import " << type_name(parent) << "Impl;" << endl;
}
}
@@ -1459,7 +1490,7 @@ void t_as3_generator::generate_service(t_service* tservice) {
f_service_ << as3_type_imports();
f_service_ << as3_thrift_imports();
f_service_ << as3_thrift_gen_imports(tservice);
- if (!package_name_.empty()) {
+ if(!package_name_.empty()) {
f_service_ << "import " << package_name_ << ".*;" << endl;
}
@@ -1468,29 +1499,33 @@ void t_as3_generator::generate_service(t_service* tservice) {
f_service_.close();
// Now make the processor/server file
- f_service_name = package_dir_ + "/" + service_name_ + "Processor.as";
+ f_service_name = package_dir_+"/"+service_name_+"Processor.as";
f_service_.open(f_service_name.c_str());
- f_service_ << autogen_comment() << as3_package();
+ f_service_ <<
+ autogen_comment() << as3_package();
scope_up(f_service_);
- f_service_ << endl << as3_type_imports() << as3_thrift_imports()
- << as3_thrift_gen_imports(tservice) << endl;
+ f_service_ << endl <<
+ as3_type_imports() <<
+ as3_thrift_imports() <<
+ as3_thrift_gen_imports(tservice) << endl;
generate_service_server(tservice);
scope_down(f_service_);
f_service_ << as3_type_imports();
f_service_ << as3_thrift_imports();
- f_service_ << as3_thrift_gen_imports(tservice) << endl;
- if (!package_name_.empty()) {
+ f_service_ << as3_thrift_gen_imports(tservice) <<endl;
+ if(!package_name_.empty()) {
f_service_ << "import " << package_name_ << ".*;" << endl;
}
generate_service_helpers(tservice);
f_service_.close();
+
}
/**
@@ -1505,8 +1540,8 @@ void t_as3_generator::generate_service_interface(t_service* tservice) {
}
generate_as3_doc(f_service_, tservice);
- f_service_ << indent() << "public interface " << service_name_ << extends_iface << " {" << endl
- << endl;
+ f_service_ << indent() << "public interface " << service_name_ << extends_iface <<
+ " {" << endl << endl;
indent_up();
vector<t_function*> functions = tservice->get_functions();
vector<t_function*>::iterator f_iter;
@@ -1516,16 +1551,19 @@ void t_as3_generator::generate_service_interface(t_service* tservice) {
if ((*f_iter)->get_returntype()->is_void()) {
indent(f_service_) << "//function onError(Error):void;" << endl;
indent(f_service_) << "//function onSuccess():void;" << endl;
- } else {
+ }
+ else {
indent(f_service_) << "//function onError(Error):void;" << endl;
- indent(f_service_) << "//function onSuccess(" << type_name((*f_iter)->get_returntype())
- << "):void;" << endl;
+ indent(f_service_) << "//function onSuccess(" << type_name((*f_iter)->get_returntype()) << "):void;" << endl;
}
}
- indent(f_service_) << function_signature(*f_iter) << ";" << endl << endl;
+ indent(f_service_) << function_signature(*f_iter) << ";" <<
+ endl << endl;
}
indent_down();
- f_service_ << indent() << "}" << endl << endl;
+ f_service_ <<
+ indent() << "}" << endl <<
+ endl;
}
/**
@@ -1556,15 +1594,16 @@ void t_as3_generator::generate_service_client(t_service* tservice) {
extends_client = " extends " + extends + "Impl";
}
- indent(f_service_) << "public class " << service_name_ << "Impl" << extends_client
- << " implements " << service_name_ << " {" << endl;
+ indent(f_service_) <<
+ "public class " << service_name_ << "Impl" << extends_client << " implements " << service_name_ << " {" << endl;
indent_up();
- indent(f_service_) << "public function " << service_name_ << "Impl"
- << "(iprot:TProtocol, oprot:TProtocol=null)" << endl;
+ indent(f_service_) <<
+ "public function " << service_name_ << "Impl" << "(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;
@@ -1575,27 +1614,36 @@ void t_as3_generator::generate_service_client(t_service* tservice) {
indent_down();
f_service_ << indent() << "}";
} 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() << "protected var iprot_:TProtocol;" << endl << indent()
- << "protected var oprot_:TProtocol;" << endl << endl << indent()
- << "protected var seqid_:int;" << endl << endl;
-
- indent(f_service_) << "public function getInputProtocol():TProtocol" << endl;
+ f_service_ <<
+ indent() << "protected var iprot_:TProtocol;" << endl <<
+ indent() << "protected var oprot_:TProtocol;" << endl <<
+ endl <<
+ indent() << "protected 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
@@ -1609,15 +1657,17 @@ void t_as3_generator::generate_service_client(t_service* tservice) {
if ((*f_iter)->get_returntype()->is_void()) {
indent(f_service_) << "//function onError(Error):void;" << endl;
indent(f_service_) << "//function onSuccess():void;" << endl;
- } else {
+ }
+ else {
indent(f_service_) << "//function onError(Error):void;" << endl;
- indent(f_service_) << "//function onSuccess(" << type_name((*f_iter)->get_returntype())
- << "):void;" << endl;
+ indent(f_service_) << "//function onSuccess(" << type_name((*f_iter)->get_returntype()) << "):void;" << endl;
}
}
- indent(f_service_) << "public " << function_signature(*f_iter) << endl;
+ indent(f_service_) <<
+ "public " << function_signature(*f_iter) << endl;
scope_up(f_service_);
+
// Get the struct of function call params
t_struct* arg_struct = (*f_iter)->get_arglist();
@@ -1626,71 +1676,85 @@ void t_as3_generator::generate_service_client(t_service* tservice) {
const vector<t_field*>& fields = arg_struct->get_members();
// Serialize the request
- f_service_ << indent() << "oprot_.writeMessageBegin(new TMessage(\"" << funname << "\", "
- << ((*f_iter)->is_oneway() ? "TMessageType.ONEWAY" : "TMessageType.CALL")
- << ", seqid_));" << endl << indent() << "var args:" << argsname << " = new "
- << argsname << "();" << endl;
+ f_service_ <<
+ indent() << "oprot_.writeMessageBegin(new TMessage(\"" << funname << "\", " <<
+ ((*f_iter)->is_oneway() ? "TMessageType.ONEWAY" : "TMessageType.CALL") <<
+ ", 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;
+ f_service_ <<
+ indent() << "args.write(oprot_);" << endl <<
+ indent() << "oprot_.writeMessageEnd();" << endl;
if ((*f_iter)->is_oneway()) {
f_service_ << indent() << "oprot_.getTransport().flush();" << endl;
- } else {
+ }
+ else {
f_service_ << indent() << "oprot_.getTransport().flush(function(error:Error):void {" << endl;
indent_up();
f_service_ << indent() << "try {" << endl;
indent_up();
string resultname = (*f_iter)->get_name() + "_result";
- f_service_ << indent() << "if (error != null) {" << endl << indent()
- << " if (onError != null) onError(error);" << endl << indent() << " return;"
- << endl << indent() << "}" << endl << indent()
- << "var msg:TMessage = iprot_.readMessageBegin();" << endl << indent()
- << "if (msg.type == TMessageType.EXCEPTION) {" << endl << indent()
- << " var x:TApplicationError = TApplicationError.read(iprot_);" << endl
- << indent() << " iprot_.readMessageEnd();" << endl << indent()
- << " if (onError != null) onError(x);" << endl << indent() << " return;" << endl
- << indent() << "}" << endl << indent() << "var result :" << resultname << " = new "
- << resultname << "();" << endl << indent() << "result.read(iprot_);" << endl
- << indent() << "iprot_.readMessageEnd();" << endl;
+ f_service_ <<
+ indent() << "if (error != null) {" << endl <<
+ indent() << " if (onError != null) onError(error);" << endl <<
+ indent() << " return;" << endl <<
+ indent() << "}" << endl <<
+ indent() << "var msg:TMessage = iprot_.readMessageBegin();" << endl <<
+ indent() << "if (msg.type == TMessageType.EXCEPTION) {" << endl <<
+ indent() << " var x:TApplicationError = TApplicationError.read(iprot_);" << endl <<
+ indent() << " iprot_.readMessageEnd();" << endl <<
+ indent() << " if (onError != null) onError(x);" << endl <<
+ indent() << " return;" << endl <<
+ indent() << "}" << endl <<
+ indent() << "var result :" << resultname << " = new " << resultname << "();" << endl <<
+ indent() << "result.read(iprot_);" << endl <<
+ indent() << "iprot_.readMessageEnd();" << endl;
// Careful, only return _result if not a void function
if (!(*f_iter)->get_returntype()->is_void()) {
- f_service_ << indent() << "if (result." << generate_isset_check("success") << ") {" << endl
- << indent() << " if (onSuccess != null) onSuccess(result.success);" << endl
- << indent() << " return;" << endl << indent() << "}" << endl;
+ f_service_ <<
+ indent() << "if (result." << generate_isset_check("success") << ") {" << endl <<
+ indent() << " if (onSuccess != null) onSuccess(result.success);" << endl <<
+ indent() << " return;" << endl <<
+ indent() << "}" << endl;
}
t_struct* xs = (*f_iter)->get_xceptions();
const std::vector<t_field*>& xceptions = xs->get_members();
vector<t_field*>::const_iterator x_iter;
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
- f_service_ << indent() << "if (result." << (*x_iter)->get_name() << " != null) {" << endl
- << indent() << " if (onError != null) onError(result." << (*x_iter)->get_name()
- << ");" << endl << indent() << " return;" << endl << indent() << "}" << endl;
+ f_service_ <<
+ indent() << "if (result." << (*x_iter)->get_name() << " != null) {" << endl <<
+ indent() << " if (onError != null) onError(result." << (*x_iter)->get_name() << ");" << endl <<
+ indent() << " return;" << endl <<
+ indent() << "}" << endl;
}
// If you get here it's an exception, unless a void function
if ((*f_iter)->get_returntype()->is_void()) {
- f_service_ << indent() << "if (onSuccess != null) onSuccess();" << endl << indent()
- << "return;" << endl;
+ f_service_ <<
+ indent() << "if (onSuccess != null) onSuccess();" << endl <<
+ indent() << "return;" << endl;
} else {
- f_service_ << indent() << "if (onError != null) onError(new "
- "TApplicationError(TApplicationError.MISSING_RESULT, \""
- << (*f_iter)->get_name() << " failed: unknown result\"));" << endl;
+ f_service_ <<
+ indent() << "if (onError != null) onError(new TApplicationError(TApplicationError.MISSING_RESULT, \"" << (*f_iter)->get_name() << " failed: unknown result\"));" << endl;
}
indent_down();
- f_service_ << indent() << "} catch (e:TError) {" << endl << indent()
- << " if (onError != null) onError(e);" << endl << indent() << "}" << endl;
+ f_service_ << indent() << "} catch (e:TError) {" << endl <<
+ indent() << " if (onError != null) onError(e);" << endl <<
+ indent() << "}" << endl;
+
indent_down();
- indent(f_service_) << "});" << endl;
+ indent(f_service_) <<
+ "});" << endl;
}
// Close function
scope_down(f_service_);
@@ -1698,7 +1762,8 @@ void t_as3_generator::generate_service_client(t_service* tservice) {
}
indent_down();
- indent(f_service_) << "}" << endl;
+ indent(f_service_) <<
+ "}" << endl;
}
/**
@@ -1720,30 +1785,34 @@ void t_as3_generator::generate_service_server(t_service* tservice) {
}
// Generate the header portion
- indent(f_service_) << "public class " << service_name_ << "Processor" << extends_processor
- << " implements TProcessor {" << endl;
+ indent(f_service_) <<
+ "public class " << service_name_ << "Processor" << extends_processor << " implements TProcessor {" << endl;
indent_up();
- indent(f_service_) << "public function " << service_name_ << "Processor(iface:" << service_name_
- << ")" << endl;
+ indent(f_service_) <<
+ "public function " << service_name_ << "Processor(iface:" << 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() << "iface_ = iface;" << endl;
+ f_service_ <<
+ indent() << "iface_ = iface;" << endl;
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
- f_service_ << indent() << "PROCESS_MAP[\"" << (*f_iter)->get_name()
- << "\"] = " << (*f_iter)->get_name() << "();" << endl;
+ f_service_ <<
+ indent() << "PROCESS_MAP[\"" << (*f_iter)->get_name() << "\"] = " << (*f_iter)->get_name() << "();" << endl;
}
scope_down(f_service_);
f_service_ << endl;
- f_service_ << indent() << "private var iface_:" << service_name_ << ";" << endl;
+ f_service_ <<
+ indent() << "private var iface_:" << service_name_ << ";" << endl;
if (extends.empty()) {
- f_service_ << indent() << "protected const PROCESS_MAP:Dictionary = new Dictionary();" << endl;
+ f_service_ <<
+ indent() << "protected const PROCESS_MAP:Dictionary = new Dictionary();" << endl;
}
f_service_ << endl;
@@ -1751,31 +1820,34 @@ void t_as3_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):Boolean" << endl;
+ indent(f_service_) << override << "public function process(iprot:TProtocol, oprot:TProtocol):Boolean" << 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:Function = PROCESS_MAP[msg.name];" << endl << indent()
- << "if (fn == null) {" << endl << indent() << " TProtocolUtil.skip(iprot, TType.STRUCT);"
- << endl << indent() << " iprot.readMessageEnd();" << endl << indent()
- << " var x:TApplicationError = new TApplicationError(TApplicationError.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.call(this,msg.seqid, iprot, oprot);" << endl;
-
- f_service_ << indent() << "return true;" << endl;
+ f_service_ <<
+ indent() << "var fn:Function = PROCESS_MAP[msg.name];" << endl <<
+ indent() << "if (fn == null) {" << endl <<
+ indent() << " TProtocolUtil.skip(iprot, TType.STRUCT);" << endl <<
+ indent() << " iprot.readMessageEnd();" << endl <<
+ indent() << " var x:TApplicationError = new TApplicationError(TApplicationError.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.call(this,msg.seqid, iprot, oprot);" << endl;
+
+ f_service_ <<
+ indent() << "return true;" << endl;
scope_down(f_service_);
f_service_ << endl;
@@ -1786,7 +1858,9 @@ void t_as3_generator::generate_service_server(t_service* tservice) {
}
indent_down();
- indent(f_service_) << "}" << endl << endl;
+ indent(f_service_) <<
+ "}" << endl <<
+ endl;
}
/**
@@ -1820,22 +1894,27 @@ void t_as3_generator::generate_function_helpers(t_function* tfunction) {
*
* @param tfunction The function to write a dispatcher for
*/
-void t_as3_generator::generate_process_function(t_service* tservice, t_function* tfunction) {
- (void)tservice;
+void t_as3_generator::generate_process_function(t_service* tservice,
+ t_function* tfunction) {
+ (void) tservice;
// Open class
- indent(f_service_) << "private function " << tfunction->get_name() << "():Function {" << endl;
+ indent(f_service_) <<
+ "private function " << tfunction->get_name() << "():Function {" << 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 = tfunction->get_name() + "_args";
string resultname = 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();
@@ -1843,13 +1922,14 @@ void t_as3_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 a function with exceptions
if (xceptions.size() > 0) {
- f_service_ << indent() << "try {" << endl;
+ f_service_ <<
+ indent() << "try {" << endl;
indent_up();
}
@@ -1859,8 +1939,9 @@ void t_as3_generator::generate_process_function(t_service* tservice, t_function*
vector<t_field*>::const_iterator f_iter;
f_service_ << indent();
- if (tfunction->is_oneway()) {
- f_service_ << "iface_." << tfunction->get_name() << "(";
+ if (tfunction->is_oneway()){
+ f_service_ <<
+ "iface_." << tfunction->get_name() << "(";
bool first = true;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
if (first) {
@@ -1877,22 +1958,20 @@ void t_as3_generator::generate_process_function(t_service* tservice, t_function*
}
// Set isset on success field
- if (!tfunction->is_oneway() && !tfunction->get_returntype()->is_void()
- && !type_can_be_null(tfunction->get_returntype())) {
- f_service_ << indent() << "result.set" << get_cap_name("success") << get_cap_name("isSet")
- << "(true);" << endl;
+ if (!tfunction->is_oneway() && !tfunction->get_returntype()->is_void() && !type_can_be_null(tfunction->get_returntype())) {
+ f_service_ <<
+ indent() << "result.set" << get_cap_name("success") << get_cap_name("isSet") << "(true);" << endl;
}
if (!tfunction->is_oneway() && xceptions.size() > 0) {
indent_down();
f_service_ << indent() << "}";
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
- f_service_ << " catch (" << (*x_iter)->get_name() << ":"
- << type_name((*x_iter)->get_type(), false, false) << ") {" << endl;
+ f_service_ << " catch (" << (*x_iter)->get_name() << ":" << type_name((*x_iter)->get_type(), false, false) << ") {" << endl;
if (!tfunction->is_oneway()) {
indent_up();
- f_service_ << indent() << "result." << (*x_iter)->get_name() << " = "
- << (*x_iter)->get_name() << ";" << endl;
+ f_service_ <<
+ indent() << "result." << (*x_iter)->get_name() << " = " << (*x_iter)->get_name() << ";" << endl;
indent_down();
f_service_ << indent() << "}";
} else {
@@ -1901,34 +1980,37 @@ void t_as3_generator::generate_process_function(t_service* tservice, t_function*
}
f_service_ << " catch (th:Error) {" << endl;
indent_up();
- f_service_ << indent() << "trace(\"Internal error processing " << tfunction->get_name()
- << "\", th);" << endl << indent()
- << "var x:TApplicationError = new "
- "TApplicationError(TApplicationError.INTERNAL_ERROR, \"Internal error processing "
- << tfunction->get_name() << "\");" << endl << indent()
- << "oprot.writeMessageBegin(new TMessage(\"" << tfunction->get_name()
- << "\", TMessageType.EXCEPTION, seqid));" << endl << indent() << "x.write(oprot);"
- << endl << indent() << "oprot.writeMessageEnd();" << endl << indent()
- << "oprot.getTransport().flush();" << endl << indent() << "return;" << endl;
+ f_service_ <<
+ indent() << "trace(\"Internal error processing " << tfunction->get_name() << "\", th);" << endl <<
+ indent() << "var x:TApplicationError = new TApplicationError(TApplicationError.INTERNAL_ERROR, \"Internal error processing " << tfunction->get_name() << "\");" << endl <<
+ indent() << "oprot.writeMessageBegin(new TMessage(\"" << tfunction->get_name() << "\", TMessageType.EXCEPTION, seqid));" << endl <<
+ indent() << "x.write(oprot);" << endl <<
+ indent() << "oprot.writeMessageEnd();" << endl <<
+ indent() << "oprot.getTransport().flush();" << endl <<
+ indent() << "return;" << endl;
indent_down();
f_service_ << indent() << "}" << endl;
}
// Shortcut out here for oneway functions
if (tfunction->is_oneway()) {
- f_service_ << indent() << "return;" << endl;
+ f_service_ <<
+ indent() << "return;" << endl;
scope_down(f_service_);
// Close class
indent_down();
- f_service_ << indent() << "}" << endl << endl;
+ f_service_ <<
+ indent() << "}" << endl <<
+ endl;
return;
}
- f_service_ << indent() << "oprot.writeMessageBegin(new TMessage(\"" << tfunction->get_name()
- << "\", TMessageType.REPLY, seqid));" << endl << indent() << "result.write(oprot);"
- << endl << indent() << "oprot.writeMessageEnd();" << endl << indent()
- << "oprot.getTransport().flush();" << endl;
+ f_service_ <<
+ indent() << "oprot.writeMessageBegin(new TMessage(\"" << tfunction->get_name() << "\", TMessageType.REPLY, seqid));" << endl <<
+ indent() << "result.write(oprot);" << endl <<
+ indent() << "oprot.writeMessageEnd();" << endl <<
+ indent() << "oprot.getTransport().flush();" << endl;
// Close function
scope_down(f_service_);
@@ -1936,7 +2018,9 @@ void t_as3_generator::generate_process_function(t_service* tservice, t_function*
// Close class
indent_down();
- f_service_ << indent() << "}" << endl << endl;
+ f_service_ <<
+ indent() << "}" << endl <<
+ endl;
}
/**
@@ -1945,28 +2029,35 @@ void t_as3_generator::generate_process_function(t_service* tservice, t_function*
* @param tfield The field
* @param prefix The variable name or container for this field
*/
-void t_as3_generator::generate_deserialize_field(ofstream& out, t_field* tfield, string prefix) {
+void t_as3_generator::generate_deserialize_field(ofstream& out,
+ t_field* tfield,
+ string prefix) {
t_type* type = get_true_type(tfield->get_type());
if (type->is_void()) {
- throw "CANNOT GENERATE DESERIALIZE CODE FOR void TYPE: " + prefix + tfield->get_name();
+ throw "CANNOT GENERATE DESERIALIZE CODE FOR void TYPE: " +
+ prefix + tfield->get_name();
}
string name = prefix + tfield->get_name();
if (type->is_struct() || type->is_xception()) {
- generate_deserialize_struct(out, (t_struct*)type, name);
+ generate_deserialize_struct(out,
+ (t_struct*)type,
+ name);
} else if (type->is_container()) {
generate_deserialize_container(out, type, name);
} else if (type->is_base_type() || type->is_enum()) {
- indent(out) << name << " = iprot.";
+ indent(out) <<
+ name << " = iprot.";
if (type->is_base_type()) {
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
switch (tbase) {
case t_base_type::TYPE_VOID:
- throw "compiler error: cannot serialize void field in a struct: " + name;
+ throw "compiler error: cannot serialize void field in a struct: " +
+ name;
break;
case t_base_type::TYPE_STRING:
if (((t_base_type*)type)->is_binary()) {
@@ -1999,26 +2090,31 @@ void t_as3_generator::generate_deserialize_field(ofstream& out, t_field* tfield,
} else if (type->is_enum()) {
out << "readI32();";
}
- out << endl;
+ out <<
+ endl;
} else {
printf("DO NOT KNOW HOW TO DESERIALIZE FIELD '%s' TYPE '%s'\n",
- tfield->get_name().c_str(),
- type_name(type).c_str());
+ tfield->get_name().c_str(), type_name(type).c_str());
}
}
/**
* Generates an unserializer for a struct, invokes read()
*/
-void t_as3_generator::generate_deserialize_struct(ofstream& out, t_struct* tstruct, stri
<TRUNCATED>