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:07 UTC
[15/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_rb_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_rb_generator.cc b/compiler/cpp/src/generate/t_rb_generator.cc
index 49708c7..0a15500 100644
--- a/compiler/cpp/src/generate/t_rb_generator.cc
+++ b/compiler/cpp/src/generate/t_rb_generator.cc
@@ -43,26 +43,22 @@ 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
/**
* A subclass of std::ofstream that includes indenting functionality.
*/
class t_rb_ofstream : public std::ofstream {
-private:
- int indent_;
+ private:
+ int indent_;
-public:
- t_rb_ofstream() : std::ofstream(), indent_(0) {}
- explicit t_rb_ofstream(const char* filename,
- ios_base::openmode mode = ios_base::out,
- int indent = 0)
- : std::ofstream(filename, mode), indent_(indent) {}
+ public:
+ t_rb_ofstream() : std::ofstream(), indent_(0) { }
+ explicit t_rb_ofstream(const char* filename, ios_base::openmode mode = ios_base::out, int indent = 0) :
+ std::ofstream(filename, mode), indent_(indent) { }
t_rb_ofstream& indent() {
- for (int i = 0; i < indent_; ++i) {
- *this << " ";
- }
+ for (int i = 0; i < indent_; ++i) { *this << " "; }
return *this;
}
@@ -75,12 +71,14 @@ public:
*
*/
class t_rb_generator : public t_oop_generator {
-public:
- t_rb_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_rb_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;
out_dir_base_ = "gen-rb";
require_rubygems_ = (parsed_options.find("rubygems") != parsed_options.end());
@@ -98,13 +96,13 @@ public:
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_union(t_struct* tunion);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef (t_typedef* ttypedef);
+ void generate_enum (t_enum* tenum);
+ void generate_const (t_const* tconst);
+ void generate_struct (t_struct* tstruct);
+ void generate_union (t_struct* tunion);
+ void generate_xception (t_struct* txception);
+ void generate_service (t_service* tservice);
t_rb_ofstream& render_const_value(t_rb_ofstream& out, t_type* type, t_const_value* value);
@@ -119,62 +117,77 @@ public:
void generate_rb_function_helpers(t_function* tfunction);
void generate_rb_simple_constructor(t_rb_ofstream& out, t_struct* tstruct);
void generate_rb_simple_exception_constructor(t_rb_ofstream& out, t_struct* tstruct);
- void generate_field_constants(t_rb_ofstream& out, t_struct* tstruct);
- void generate_field_constructors(t_rb_ofstream& out, t_struct* tstruct);
- void generate_field_defns(t_rb_ofstream& out, t_struct* tstruct);
- void generate_field_data(t_rb_ofstream& out,
- t_type* field_type,
- const std::string& field_name,
- t_const_value* field_value,
- bool optional);
+ void generate_field_constants (t_rb_ofstream& out, t_struct* tstruct);
+ void generate_field_constructors (t_rb_ofstream& out, t_struct* tstruct);
+ void generate_field_defns (t_rb_ofstream& out, t_struct* tstruct);
+ void generate_field_data (t_rb_ofstream& out, t_type* field_type, const std::string& field_name, t_const_value* field_value, bool optional);
/**
* Service-level generation functions
*/
- void generate_service_helpers(t_service* tservice);
- void generate_service_interface(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_helpers (t_service* tservice);
+ void generate_service_interface (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(t_rb_ofstream& out,
- t_field* tfield,
- std::string prefix = "",
- bool inclass = false);
+ void generate_deserialize_field (t_rb_ofstream &out,
+ t_field* tfield,
+ std::string prefix="",
+ bool inclass=false);
- void generate_deserialize_struct(t_rb_ofstream& out, t_struct* tstruct, std::string prefix = "");
+ void generate_deserialize_struct (t_rb_ofstream &out,
+ t_struct* tstruct,
+ std::string prefix="");
- void generate_deserialize_container(t_rb_ofstream& out, t_type* ttype, std::string prefix = "");
+ void generate_deserialize_container (t_rb_ofstream &out,
+ t_type* ttype,
+ std::string prefix="");
- void generate_deserialize_set_element(t_rb_ofstream& out, t_set* tset, std::string prefix = "");
+ void generate_deserialize_set_element (t_rb_ofstream &out,
+ t_set* tset,
+ std::string prefix="");
- void generate_deserialize_map_element(t_rb_ofstream& out, t_map* tmap, std::string prefix = "");
+ void generate_deserialize_map_element (t_rb_ofstream &out,
+ t_map* tmap,
+ std::string prefix="");
- void generate_deserialize_list_element(t_rb_ofstream& out,
- t_list* tlist,
- std::string prefix = "");
+ void generate_deserialize_list_element (t_rb_ofstream &out,
+ t_list* tlist,
+ std::string prefix="");
- void generate_serialize_field(t_rb_ofstream& out, t_field* tfield, std::string prefix = "");
+ void generate_serialize_field (t_rb_ofstream &out,
+ t_field* tfield,
+ std::string prefix="");
- void generate_serialize_struct(t_rb_ofstream& out, t_struct* tstruct, std::string prefix = "");
+ void generate_serialize_struct (t_rb_ofstream &out,
+ t_struct* tstruct,
+ std::string prefix="");
- void generate_serialize_container(t_rb_ofstream& out, t_type* ttype, std::string prefix = "");
+ void generate_serialize_container (t_rb_ofstream &out,
+ t_type* ttype,
+ std::string prefix="");
- void generate_serialize_map_element(t_rb_ofstream& out,
- t_map* tmap,
- std::string kiter,
- std::string viter);
+ void generate_serialize_map_element (t_rb_ofstream &out,
+ t_map* tmap,
+ std::string kiter,
+ std::string viter);
- void generate_serialize_set_element(t_rb_ofstream& out, t_set* tmap, std::string iter);
+ void generate_serialize_set_element (t_rb_ofstream &out,
+ t_set* tmap,
+ std::string iter);
- void generate_serialize_list_element(t_rb_ofstream& out, t_list* tlist, std::string iter);
+ void generate_serialize_list_element (t_rb_ofstream &out,
+ t_list* tlist,
+ std::string iter);
- void generate_rdoc(t_rb_ofstream& out, t_doc* tdoc);
+ void generate_rdoc (t_rb_ofstream& out,
+ t_doc* tdoc);
/**
* Helper rendering functions
@@ -186,11 +199,12 @@ public:
std::string declare_field(t_field* tfield);
std::string type_name(t_type* ttype);
std::string full_type_name(t_type* ttype);
- std::string function_signature(t_function* tfunction, std::string prefix = "");
+ 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 rb_namespace_to_path_prefix(std::string rb_namespace);
+
std::vector<std::string> ruby_modules(t_program* p) {
std::string ns = p->get_namespace("rb");
std::vector<std::string> modules;
@@ -215,7 +229,8 @@ public:
void begin_namespace(t_rb_ofstream&, std::vector<std::string>);
void end_namespace(t_rb_ofstream&, std::vector<std::string>);
-private:
+ private:
+
/**
* File streams
*/
@@ -234,6 +249,7 @@ private:
bool namespaced_;
};
+
/**
* Prepares for file generation by opening up the necessary file output
* streams.
@@ -255,26 +271,31 @@ void t_rb_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);
}
}
namespace_dir_ = subdir;
// Make output file
- string f_types_name = namespace_dir_ + underscore(program_name_) + "_types.rb";
+ string f_types_name = namespace_dir_+underscore(program_name_)+"_types.rb";
f_types_.open(f_types_name.c_str());
- string f_consts_name = namespace_dir_ + underscore(program_name_) + "_constants.rb";
+ string f_consts_name = namespace_dir_+underscore(program_name_)+"_constants.rb";
f_consts_.open(f_consts_name.c_str());
// Print header
- f_types_ << rb_autogen_comment() << endl << render_require_thrift() << render_includes() << endl;
- begin_namespace(f_types_, ruby_modules(program_));
+ f_types_ <<
+ rb_autogen_comment() << endl << render_require_thrift() <<
+ render_includes() << endl;
+ begin_namespace(f_types_, ruby_modules(program_));
+
+ f_consts_ <<
+ rb_autogen_comment() << endl << render_require_thrift() <<
+ "require '" << require_prefix_ << underscore(program_name_) << "_types'" << endl <<
+ endl;
+ begin_namespace(f_consts_, ruby_modules(program_));
- f_consts_ << rb_autogen_comment() << endl << render_require_thrift() << "require '"
- << require_prefix_ << underscore(program_name_) << "_types'" << endl << endl;
- begin_namespace(f_consts_, ruby_modules(program_));
}
/**
@@ -296,8 +317,7 @@ string t_rb_generator::render_includes() {
string result = "";
for (size_t i = 0; i < includes.size(); ++i) {
t_program* included = includes[i];
- std::string included_require_prefix
- = rb_namespace_to_path_prefix(included->get_namespace("rb"));
+ std::string included_require_prefix = rb_namespace_to_path_prefix(included->get_namespace("rb"));
std::string included_name = included->get_name();
result += "require '" + included_require_prefix + underscore(included_name) + "_types'\n";
}
@@ -311,8 +331,12 @@ string t_rb_generator::render_includes() {
* Autogen'd comment
*/
string t_rb_generator::rb_autogen_comment() {
- return std::string("#\n") + "# Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n"
- + "#\n" + "# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n" + "#\n";
+ return
+ std::string("#\n") +
+ "# Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n" +
+ "#\n" +
+ "# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n" +
+ "#\n";
}
/**
@@ -332,7 +356,7 @@ void t_rb_generator::close_generator() {
* @param ttypedef The type definition
*/
void t_rb_generator::generate_typedef(t_typedef* ttypedef) {
- (void)ttypedef;
+ (void) ttypedef;
}
/**
@@ -342,7 +366,8 @@ void t_rb_generator::generate_typedef(t_typedef* ttypedef) {
* @param tenum The enumeration
*/
void t_rb_generator::generate_enum(t_enum* tenum) {
- f_types_.indent() << "module " << capitalize(tenum->get_name()) << endl;
+ f_types_.indent() <<
+ "module " << capitalize(tenum->get_name()) << endl;
f_types_.indent_up();
vector<t_enum_value*> constants = tenum->get_constants();
@@ -359,14 +384,12 @@ void t_rb_generator::generate_enum(t_enum* tenum) {
f_types_.indent() << name << " = " << value << endl;
}
- // Create a hash mapping values back to their names (as strings) since ruby has no native enum
- // type
+ // Create a hash mapping values back to their names (as strings) since ruby has no native enum type
f_types_.indent() << "VALUE_MAP = {";
- for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
+ for(c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
// Populate the hash
int value = (*c_iter)->get_value();
- if (c_iter != constants.begin())
- f_types_ << ", ";
+ if (c_iter != constants.begin()) f_types_ << ", ";
f_types_ << value << " => \"" << capitalize((*c_iter)->get_name()) << "\"";
}
f_types_ << "}" << endl;
@@ -375,14 +398,14 @@ void t_rb_generator::generate_enum(t_enum* tenum) {
f_types_.indent() << "VALID_VALUES = Set.new([";
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
// Populate the set
- if (c_iter != constants.begin())
- f_types_ << ", ";
+ if (c_iter != constants.begin()) f_types_ << ", ";
f_types_ << capitalize((*c_iter)->get_name());
}
f_types_ << "]).freeze" << endl;
f_types_.indent_down();
- f_types_.indent() << "end" << endl << endl;
+ f_types_.indent() <<
+ "end" << endl << endl;
}
/**
@@ -404,9 +427,7 @@ void t_rb_generator::generate_const(t_const* tconst) {
* is NOT performed in this function as it is always run beforehand using the
* validate_types method in main.cc
*/
-t_rb_ofstream& t_rb_generator::render_const_value(t_rb_ofstream& out,
- t_type* type,
- t_const_value* value) {
+t_rb_ofstream& t_rb_generator::render_const_value(t_rb_ofstream& out, t_type* type, t_const_value* value) {
type = get_true_type(type);
if (type->is_base_type()) {
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
@@ -527,9 +548,7 @@ void t_rb_generator::generate_xception(t_struct* txception) {
/**
* Generates a ruby struct
*/
-void t_rb_generator::generate_rb_struct(t_rb_ofstream& out,
- t_struct* tstruct,
- bool is_exception = false) {
+void t_rb_generator::generate_rb_struct(t_rb_ofstream& out, t_struct* tstruct, bool is_exception = false) {
generate_rdoc(out, tstruct);
out.indent() << "class " << type_name(tstruct);
if (is_exception) {
@@ -554,13 +573,12 @@ void t_rb_generator::generate_rb_struct(t_rb_ofstream& out,
out.indent() << "end" << endl << endl;
}
+
/**
* Generates a ruby union
*/
-void t_rb_generator::generate_rb_union(t_rb_ofstream& out,
- t_struct* tstruct,
- bool is_exception = false) {
- (void)is_exception;
+void t_rb_generator::generate_rb_union(t_rb_ofstream& out, t_struct* tstruct, bool is_exception = false) {
+ (void) is_exception;
generate_rdoc(out, tstruct);
out.indent() << "class " << type_name(tstruct) << " < ::Thrift::Union" << endl;
@@ -604,8 +622,7 @@ void t_rb_generator::generate_field_constructors(t_rb_ofstream& out, t_struct* t
out << endl;
}
-void t_rb_generator::generate_rb_simple_exception_constructor(t_rb_ofstream& out,
- t_struct* tstruct) {
+void t_rb_generator::generate_rb_simple_exception_constructor(t_rb_ofstream& out, t_struct* tstruct) {
const vector<t_field*>& members = tstruct->get_members();
if (members.size() == 1) {
@@ -657,24 +674,19 @@ void t_rb_generator::generate_field_defns(t_rb_ofstream& out, t_struct* tstruct)
out.indent() << upcase_string((*f_iter)->get_name()) << " => ";
- generate_field_data(out,
- (*f_iter)->get_type(),
- (*f_iter)->get_name(),
- (*f_iter)->get_value(),
- (*f_iter)->get_req() == t_field::T_OPTIONAL);
+ generate_field_data(out, (*f_iter)->get_type(), (*f_iter)->get_name(), (*f_iter)->get_value(),
+ (*f_iter)->get_req() == t_field::T_OPTIONAL);
}
out.indent_down();
out << endl;
out.indent() << "}" << endl << endl;
out.indent() << "def struct_fields; FIELDS; end" << endl << endl;
+
}
-void t_rb_generator::generate_field_data(t_rb_ofstream& out,
- t_type* field_type,
- const std::string& field_name = "",
- t_const_value* field_value = NULL,
- bool optional = false) {
+void t_rb_generator::generate_field_data(t_rb_ofstream& out, t_type* field_type,
+ const std::string& field_name = "", t_const_value* field_value = NULL, bool optional = false) {
field_type = get_true_type(field_type);
// Begin this field's defn
@@ -710,7 +722,7 @@ void t_rb_generator::generate_field_data(t_rb_ofstream& out,
}
}
- if (optional) {
+ if(optional) {
out << ", :optional => true";
}
@@ -730,31 +742,33 @@ void t_rb_generator::begin_namespace(t_rb_ofstream& out, vector<std::string> mod
}
void t_rb_generator::end_namespace(t_rb_ofstream& out, vector<std::string> modules) {
- for (vector<std::string>::reverse_iterator m_iter = modules.rbegin(); m_iter != modules.rend();
- ++m_iter) {
+ for (vector<std::string>::reverse_iterator m_iter = modules.rbegin(); m_iter != modules.rend(); ++m_iter) {
out.indent_down();
out.indent() << "end" << endl;
}
}
+
/**
* Generates a thrift service.
*
* @param tservice The service definition
*/
void t_rb_generator::generate_service(t_service* tservice) {
- string f_service_name = namespace_dir_ + underscore(service_name_) + ".rb";
+ string f_service_name = namespace_dir_+underscore(service_name_)+".rb";
f_service_.open(f_service_name.c_str());
- f_service_ << rb_autogen_comment() << endl << render_require_thrift();
+ f_service_ <<
+ rb_autogen_comment() << endl << render_require_thrift();
if (tservice->get_extends() != NULL) {
- f_service_ << "require '" << require_prefix_ << underscore(tservice->get_extends()->get_name())
- << "'" << endl;
+ f_service_ <<
+ "require '" << require_prefix_ << underscore(tservice->get_extends()->get_name()) << "'" << endl;
}
- f_service_ << "require '" << require_prefix_ << underscore(program_name_) << "_types'" << endl
- << endl;
+ f_service_ <<
+ "require '" << require_prefix_ << underscore(program_name_) << "_types'" << endl <<
+ endl;
begin_namespace(f_service_, ruby_modules(tservice->get_program()));
@@ -844,43 +858,46 @@ void t_rb_generator::generate_service_client(t_service* tservice) {
// Open function
f_service_.indent() << "def " << function_signature(*f_iter) << endl;
f_service_.indent_up();
- f_service_.indent() << "send_" << funname << "(";
-
- bool first = true;
- for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
- if (first) {
- first = false;
- } else {
- f_service_ << ", ";
+ f_service_.indent() <<
+ "send_" << funname << "(";
+
+ bool first = true;
+ for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
+ if (first) {
+ first = false;
+ } else {
+ f_service_ << ", ";
+ }
+ f_service_ << (*fld_iter)->get_name();
}
- f_service_ << (*fld_iter)->get_name();
- }
- f_service_ << ")" << endl;
+ f_service_ << ")" << endl;
- if (!(*f_iter)->is_oneway()) {
- f_service_.indent();
- if (!(*f_iter)->get_returntype()->is_void()) {
- f_service_ << "return ";
+ if (!(*f_iter)->is_oneway()) {
+ f_service_.indent();
+ if (!(*f_iter)->get_returntype()->is_void()) {
+ f_service_ << "return ";
+ }
+ f_service_ <<
+ "recv_" << funname << "()" << endl;
}
- f_service_ << "recv_" << funname << "()" << endl;
- }
f_service_.indent_down();
f_service_.indent() << "end" << endl;
f_service_ << endl;
- f_service_.indent() << "def send_" << function_signature(*f_iter) << endl;
+ f_service_.indent() <<
+ "def send_" << function_signature(*f_iter) << endl;
f_service_.indent_up();
- std::string argsname = capitalize((*f_iter)->get_name() + "_args");
- std::string messageSendProc = (*f_iter)->is_oneway() ? "send_oneway_message" : "send_message";
+ std::string argsname = capitalize((*f_iter)->get_name() + "_args");
+ std::string messageSendProc = (*f_iter)->is_oneway() ? "send_oneway_message" : "send_message";
- f_service_.indent() << messageSendProc << "('" << funname << "', " << argsname;
+ f_service_.indent() << messageSendProc << "('" << funname << "', " << argsname;
- for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
- f_service_ << ", :" << (*fld_iter)->get_name() << " => " << (*fld_iter)->get_name();
- }
+ for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
+ f_service_ << ", :" << (*fld_iter)->get_name() << " => " << (*fld_iter)->get_name();
+ }
- f_service_ << ")" << endl;
+ f_service_ << ")" << endl;
f_service_.indent_down();
f_service_.indent() << "end" << endl;
@@ -910,18 +927,19 @@ void t_rb_generator::generate_service_client(t_service* tservice) {
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() << "raise result." << (*x_iter)->get_name() << " unless result."
- << (*x_iter)->get_name() << ".nil?" << endl;
+ f_service_.indent() <<
+ "raise result." << (*x_iter)->get_name() <<
+ " unless result." << (*x_iter)->get_name() << ".nil?" << endl;
}
// Careful, only return _result if not a void function
if ((*f_iter)->get_returntype()->is_void()) {
- f_service_.indent() << "return" << endl;
+ f_service_.indent() <<
+ "return" << endl;
} else {
- f_service_.indent() << "raise "
- "::Thrift::ApplicationException.new(::Thrift::ApplicationException::"
- "MISSING_RESULT, '" << (*f_iter)->get_name()
- << " failed: unknown result')" << endl;
+ f_service_.indent() <<
+ "raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, '" <<
+ (*f_iter)->get_name() << " failed: unknown result')" << endl;
}
// Close function
@@ -952,7 +970,8 @@ void t_rb_generator::generate_service_server(t_service* tservice) {
}
// Generate the header portion
- f_service_.indent() << "class Processor" << extends_processor << endl;
+ f_service_.indent() <<
+ "class Processor" << extends_processor << endl;
f_service_.indent_up();
f_service_.indent() << "include ::Thrift::Processor" << endl << endl;
@@ -971,10 +990,13 @@ void t_rb_generator::generate_service_server(t_service* tservice) {
*
* @param tfunction The function to write a dispatcher for
*/
-void t_rb_generator::generate_process_function(t_service* tservice, t_function* tfunction) {
- (void)tservice;
+void t_rb_generator::generate_process_function(t_service* tservice,
+ t_function* tfunction) {
+ (void) tservice;
// Open function
- f_service_.indent() << "def process_" << tfunction->get_name() << "(seqid, iprot, oprot)" << endl;
+ f_service_.indent() <<
+ "def process_" << tfunction->get_name() <<
+ "(seqid, iprot, oprot)" << endl;
f_service_.indent_up();
string argsname = capitalize(tfunction->get_name()) + "_args";
@@ -1006,7 +1028,8 @@ void t_rb_generator::generate_process_function(t_service* tservice, t_function*
if (!tfunction->is_oneway() && !tfunction->get_returntype()->is_void()) {
f_service_ << "result.success = ";
}
- f_service_ << "@handler." << tfunction->get_name() << "(";
+ f_service_ <<
+ "@handler." << tfunction->get_name() << "(";
bool first = true;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
if (first) {
@@ -1021,12 +1044,11 @@ void t_rb_generator::generate_process_function(t_service* tservice, t_function*
if (!tfunction->is_oneway() && xceptions.size() > 0) {
f_service_.indent_down();
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
- f_service_.indent() << "rescue " << full_type_name((*x_iter)->get_type()) << " => "
- << (*x_iter)->get_name() << endl;
+ f_service_.indent() << "rescue " << full_type_name((*x_iter)->get_type()) << " => " <<
+ (*x_iter)->get_name() << endl;
if (!tfunction->is_oneway()) {
f_service_.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;
f_service_.indent_down();
}
}
@@ -1041,8 +1063,7 @@ void t_rb_generator::generate_process_function(t_service* tservice, t_function*
return;
}
- f_service_.indent() << "write_result(result, oprot, '" << tfunction->get_name() << "', seqid)"
- << endl;
+ f_service_.indent() << "write_result(result, oprot, '" << tfunction->get_name() << "', seqid)" << endl;
// Close function
f_service_.indent_down();
@@ -1055,9 +1076,12 @@ void t_rb_generator::generate_process_function(t_service* tservice, t_function*
* @param tfunction Function definition
* @return String of rendered function definition
*/
-string t_rb_generator::function_signature(t_function* tfunction, string prefix) {
+string t_rb_generator::function_signature(t_function* tfunction,
+ string prefix) {
// TODO(mcslee): Nitpicky, no ',' if argument_list is empty
- return prefix + tfunction->get_name() + "(" + argument_list(tfunction->get_arglist()) + ")";
+ return
+ prefix + tfunction->get_name() +
+ "(" + argument_list(tfunction->get_arglist()) + ")";
}
/**
@@ -1094,7 +1118,8 @@ string t_rb_generator::type_name(t_type* ttype) {
string t_rb_generator::full_type_name(t_type* ttype) {
string prefix = "::";
vector<std::string> modules = ruby_modules(ttype->get_program());
- for (vector<std::string>::iterator m_iter = modules.begin(); m_iter != modules.end(); ++m_iter) {
+ for (vector<std::string>::iterator m_iter = modules.begin();
+ m_iter != modules.end(); ++m_iter) {
prefix += *m_iter + "::";
}
return prefix + type_name(ttype);
@@ -1149,7 +1174,7 @@ string t_rb_generator::rb_namespace_to_path_prefix(string rb_namespace) {
while ((loc = namespaces_left.find(".")) != string::npos) {
path_prefix = path_prefix + underscore(namespaces_left.substr(0, loc)) + "/";
- namespaces_left = namespaces_left.substr(loc + 1);
+ namespaces_left = namespaces_left.substr(loc+1);
}
if (namespaces_left.size() > 0) {
path_prefix = path_prefix + underscore(namespaces_left) + "/";
@@ -1157,14 +1182,17 @@ string t_rb_generator::rb_namespace_to_path_prefix(string rb_namespace) {
return path_prefix;
}
+
void t_rb_generator::generate_rdoc(t_rb_ofstream& out, t_doc* tdoc) {
if (tdoc->has_doc()) {
out.indent();
- generate_docstring_comment(out, "", "# ", tdoc->get_doc(), "");
+ generate_docstring_comment(out,
+ "", "# ", tdoc->get_doc(), "");
}
}
-void t_rb_generator::generate_rb_struct_required_validator(t_rb_ofstream& out, t_struct* tstruct) {
+void t_rb_generator::generate_rb_struct_required_validator(t_rb_ofstream& out,
+ t_struct* tstruct) {
out.indent() << "def validate" << endl;
out.indent_up();
@@ -1174,8 +1202,9 @@ void t_rb_generator::generate_rb_struct_required_validator(t_rb_ofstream& out, t
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
t_field* field = (*f_iter);
if (field->get_req() == t_field::T_REQUIRED) {
- out.indent() << "raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, "
- "'Required field " << field->get_name() << " is unset!')";
+ out.indent() <<
+ "raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field " <<
+ field->get_name() << " is unset!')";
if (field->get_type()->is_bool()) {
out << " if @" << field->get_name() << ".nil?";
} else {
@@ -1189,13 +1218,14 @@ void t_rb_generator::generate_rb_struct_required_validator(t_rb_ofstream& out, t
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
t_field* field = (*f_iter);
- if (field->get_type()->is_enum()) {
- out.indent() << "unless @" << field->get_name() << ".nil? || "
- << full_type_name(field->get_type()) << "::VALID_VALUES.include?(@"
- << field->get_name() << ")" << endl;
+ if (field->get_type()->is_enum()){
+ out.indent() << "unless @" << field->get_name() << ".nil? || " <<
+ full_type_name(field->get_type()) << "::VALID_VALUES.include?(@" <<
+ field->get_name() << ")" << endl;
out.indent_up();
- out.indent() << "raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, "
- "'Invalid value of field " << field->get_name() << "!')" << endl;
+ out.indent() <<
+ "raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field " <<
+ field->get_name() << "!')" << endl;
out.indent_down();
out.indent() << "end" << endl;
}
@@ -1205,28 +1235,27 @@ void t_rb_generator::generate_rb_struct_required_validator(t_rb_ofstream& out, t
out.indent() << "end" << endl << endl;
}
-void t_rb_generator::generate_rb_union_validator(t_rb_ofstream& out, t_struct* tstruct) {
+void t_rb_generator::generate_rb_union_validator(t_rb_ofstream& out,
+ t_struct* tstruct) {
out.indent() << "def validate" << endl;
out.indent_up();
const vector<t_field*>& fields = tstruct->get_members();
vector<t_field*>::const_iterator f_iter;
- out.indent()
- << "raise(StandardError, 'Union fields are not set.') if get_set_field.nil? || get_value.nil?"
- << endl;
+ out.indent() <<
+ "raise(StandardError, 'Union fields are not set.') if get_set_field.nil? || get_value.nil?" << endl;
// if field is an enum, check that its value is valid
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
const t_field* field = (*f_iter);
- if (field->get_type()->is_enum()) {
+ if (field->get_type()->is_enum()){
out.indent() << "if get_set_field == :" << field->get_name() << endl;
- out.indent() << " raise "
- "::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, "
- "'Invalid value of field " << field->get_name() << "!') unless "
- << full_type_name(field->get_type()) << "::VALID_VALUES.include?(get_value)"
- << endl;
+ out.indent() <<
+ " raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field " <<
+ field->get_name() << "!') unless " << full_type_name(field->get_type()) <<
+ "::VALID_VALUES.include?(get_value)" << endl;
out.indent() << "end" << endl;
}
}
@@ -1235,8 +1264,6 @@ void t_rb_generator::generate_rb_union_validator(t_rb_ofstream& out, t_struct* t
out.indent() << "end" << endl << endl;
}
-THRIFT_REGISTER_GENERATOR(
- rb,
- "Ruby",
- " rubygems: Add a \"require 'rubygems'\" line to the top of each generated file.\n"
- " namespaced: Generate files in idiomatic namespaced directories.\n")
+THRIFT_REGISTER_GENERATOR(rb, "Ruby",
+" rubygems: Add a \"require 'rubygems'\" line to the top of each generated file.\n"
+" namespaced: Generate files in idiomatic namespaced directories.\n")
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/compiler/cpp/src/generate/t_st_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_st_generator.cc b/compiler/cpp/src/generate/t_st_generator.cc
index 9235f68..32ffd88 100644
--- a/compiler/cpp/src/generate/t_st_generator.cc
+++ b/compiler/cpp/src/generate/t_st_generator.cc
@@ -43,20 +43,22 @@ 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
/**
* Smalltalk code generator.
*
*/
class t_st_generator : public t_oop_generator {
-public:
- t_st_generator(t_program* program,
- const std::map<std::string, std::string>& parsed_options,
- const std::string& option_string)
- : t_oop_generator(program) {
- (void)parsed_options;
- (void)option_string;
+ public:
+ t_st_generator(
+ t_program* program,
+ const std::map<std::string, std::string>& parsed_options,
+ const std::string& option_string)
+ : t_oop_generator(program)
+ {
+ (void) parsed_options;
+ (void) option_string;
out_dir_base_ = "gen-st";
}
@@ -71,14 +73,15 @@ public:
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
- void generate_class_side_definition();
- void generate_force_consts();
+ void generate_typedef (t_typedef* ttypedef);
+ void generate_enum (t_enum* tenum);
+ void generate_const (t_const* tconst);
+ void generate_struct (t_struct* tstruct);
+ void generate_xception (t_struct* txception);
+ void generate_service (t_service* tservice);
+ void generate_class_side_definition ();
+ void generate_force_consts ();
+
std::string render_const_value(t_type* type, t_const_value* value);
@@ -86,30 +89,30 @@ public:
* Struct generation code
*/
- void generate_st_struct(std::ofstream& out, t_struct* tstruct, bool is_exception);
- void generate_accessors(std::ofstream& out, t_struct* tstruct);
+ void generate_st_struct (std::ofstream& out, t_struct* tstruct, bool is_exception);
+ void generate_accessors (std::ofstream& out, t_struct* tstruct);
/**
* Service-level generation functions
*/
- void generate_service_client(t_service* tservice);
+ void generate_service_client (t_service* tservice);
- void generate_send_method(t_function* tfunction);
- void generate_recv_method(t_function* tfunction);
+ void generate_send_method (t_function* tfunction);
+ void generate_recv_method (t_function* tfunction);
- std::string map_reader(t_map* tmap);
- std::string list_reader(t_list* tlist);
- std::string set_reader(t_set* tset);
- std::string struct_reader(t_struct* tstruct, std::string clsName);
+ std::string map_reader (t_map *tmap);
+ std::string list_reader (t_list *tlist);
+ std::string set_reader (t_set *tset);
+ std::string struct_reader (t_struct *tstruct, std::string clsName);
- std::string map_writer(t_map* tmap, std::string name);
- std::string list_writer(t_list* tlist, std::string name);
- std::string set_writer(t_set* tset, std::string name);
- std::string struct_writer(t_struct* tstruct, std::string fname);
+ std::string map_writer (t_map *tmap, std::string name);
+ std::string list_writer (t_list *tlist, std::string name);
+ std::string set_writer (t_set *tset, std::string name);
+ std::string struct_writer (t_struct *tstruct, std::string fname);
- std::string write_val(t_type* t, std::string fname);
- std::string read_val(t_type* t);
+ std::string write_val (t_type *t, std::string fname);
+ std::string read_val (t_type *t);
/**
* Helper rendering functions
@@ -117,15 +120,15 @@ public:
std::string st_autogen_comment();
- void st_class_def(std::ofstream& out, std::string name);
- void st_method(std::ofstream& out, std::string cls, std::string name);
- void st_method(std::ofstream& out, std::string cls, std::string name, std::string category);
- void st_close_method(std::ofstream& out);
- void st_class_method(std::ofstream& out, std::string cls, std::string name);
- void st_class_method(std::ofstream& out, std::string cls, std::string name, std::string category);
- void st_setter(std::ofstream& out, std::string cls, std::string name, std::string type);
- void st_getter(std::ofstream& out, std::string cls, std::string name);
- void st_accessors(std::ofstream& out, std::string cls, std::string name, std::string type);
+ void st_class_def(std::ofstream &out, std::string name);
+ void st_method(std::ofstream &out, std::string cls, std::string name);
+ void st_method(std::ofstream &out, std::string cls, std::string name, std::string category);
+ void st_close_method(std::ofstream &out);
+ void st_class_method(std::ofstream &out, std::string cls, std::string name);
+ void st_class_method(std::ofstream &out, std::string cls, std::string name, std::string category);
+ void st_setter(std::ofstream &out, std::string cls, std::string name, std::string type);
+ void st_getter(std::ofstream &out, std::string cls, std::string name);
+ void st_accessors(std::ofstream &out, std::string cls, std::string name, std::string type);
std::string class_name();
static bool is_valid_namespace(const std::string& sub_namespace);
@@ -144,14 +147,17 @@ public:
std::string temp_name();
std::string generated_category();
-private:
+ private:
+
/**
* File streams
*/
int temporary_var;
std::ofstream f_;
+
};
+
/**
* Prepares for file generation by opening up the necessary file output
* streams.
@@ -165,7 +171,7 @@ void t_st_generator::init_generator() {
temporary_var = 0;
// Make output file
- string f_name = get_out_dir() + "/" + program_name_ + ".st";
+ string f_name = get_out_dir()+"/"+program_name_+".st";
f_.open(f_name.c_str());
// Print header
@@ -174,7 +180,7 @@ void t_st_generator::init_generator() {
st_class_def(f_, program_name_);
generate_class_side_definition();
- // Generate enums
+ //Generate enums
vector<t_enum*> enums = program_->get_enums();
vector<t_enum*>::iterator en_iter;
for (en_iter = enums.begin(); en_iter != enums.end(); ++en_iter) {
@@ -205,16 +211,21 @@ string t_st_generator::client_class_name() {
* Autogen'd comment
*/
string t_st_generator::st_autogen_comment() {
- return std::string("'") + "Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n" + "\n"
- + "DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n" + "'!\n";
+ return
+ std::string("'") +
+ "Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n" +
+ "\n" +
+ "DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n" +
+ "'!\n";
}
void t_st_generator::generate_force_consts() {
- f_ << prefix(class_name()) << " enums keysAndValuesDo: [:k :v | " << prefix(class_name())
- << " enums at: k put: v value].!" << endl;
+ f_ << prefix(class_name()) << " enums keysAndValuesDo: [:k :v | " <<
+ prefix(class_name()) << " enums at: k put: v value].!" << endl;
+
+ f_ << prefix(class_name()) << " constants keysAndValuesDo: [:k :v | " <<
+ prefix(class_name()) << " constants at: k put: v value].!" << endl;
- f_ << prefix(class_name()) << " constants keysAndValuesDo: [:k :v | " << prefix(class_name())
- << " constants at: k put: v value].!" << endl;
}
void t_st_generator::close_generator() {
@@ -240,76 +251,72 @@ string t_st_generator::generated_category() {
* @param ttypedef The type definition
*/
void t_st_generator::generate_typedef(t_typedef* ttypedef) {
- (void)ttypedef;
+ (void) ttypedef;
}
-void t_st_generator::st_class_def(std::ofstream& out, string name) {
+void t_st_generator::st_class_def(std::ofstream &out, string name) {
out << "Object subclass: #" << prefix(name) << endl;
indent_up();
- out << indent() << "instanceVariableNames: ''" << endl << indent() << "classVariableNames: ''"
- << endl << indent() << "poolDictionaries: ''" << endl << indent() << "category: '"
- << generated_category() << "'!" << endl << endl;
+ out << indent() << "instanceVariableNames: ''" << endl <<
+ indent() << "classVariableNames: ''" << endl <<
+ indent() << "poolDictionaries: ''" << endl <<
+ indent() << "category: '" << generated_category() << "'!" << endl << endl;
}
-void t_st_generator::st_method(std::ofstream& out, string cls, string name) {
+void t_st_generator::st_method(std::ofstream &out, string cls, string name) {
st_method(out, cls, name, "as yet uncategorized");
}
-void t_st_generator::st_class_method(std::ofstream& out, string cls, string name) {
+void t_st_generator::st_class_method(std::ofstream &out, string cls, string name) {
st_method(out, cls + " class", name);
}
-void t_st_generator::st_class_method(std::ofstream& out, string cls, string name, string category) {
+void t_st_generator::st_class_method(std::ofstream &out, string cls, string name, string category) {
st_method(out, cls, name, category);
}
-void t_st_generator::st_method(std::ofstream& out, string cls, string name, string category) {
+void t_st_generator::st_method(std::ofstream &out, string cls, string name, string category) {
char timestr[50];
time_t rawtime;
- struct tm* tinfo;
+ struct tm *tinfo;
time(&rawtime);
tinfo = localtime(&rawtime);
strftime(timestr, 50, "%m/%d/%Y %H:%M", tinfo);
- out << "!" << prefix(cls) << " methodsFor: '" + category + "' stamp: 'thrift " << timestr
- << "'!\n" << name << endl;
+ out << "!" << prefix(cls) <<
+ " methodsFor: '"+category+"' stamp: 'thrift " << timestr << "'!\n" <<
+ name << endl;
indent_up();
out << indent();
}
-void t_st_generator::st_close_method(std::ofstream& out) {
+void t_st_generator::st_close_method(std::ofstream &out) {
out << "! !" << endl << endl;
indent_down();
}
-void t_st_generator::st_setter(std::ofstream& out,
- string cls,
- string name,
- string type = "anObject") {
+void t_st_generator::st_setter(std::ofstream &out, string cls, string name, string type = "anObject") {
st_method(out, cls, name + ": " + type);
out << name << " := " + type;
st_close_method(out);
}
-void t_st_generator::st_getter(std::ofstream& out, string cls, string name) {
+void t_st_generator::st_getter(std::ofstream &out, string cls, string name) {
st_method(out, cls, name + "");
out << "^ " << name;
st_close_method(out);
}
-void t_st_generator::st_accessors(std::ofstream& out,
- string cls,
- string name,
- string type = "anObject") {
+void t_st_generator::st_accessors(std::ofstream &out, string cls, string name, string type = "anObject") {
st_setter(out, cls, name, type);
st_getter(out, cls, name);
}
void t_st_generator::generate_class_side_definition() {
- f_ << prefix(class_name()) << " class" << endl << "\tinstanceVariableNames: 'constants enums'!"
- << endl << endl;
+ f_ << prefix(class_name()) << " class" << endl <<
+ "\tinstanceVariableNames: 'constants enums'!" << endl << endl;
st_accessors(f_, class_name() + " class", "enums");
st_accessors(f_, class_name() + " class", "constants");
@@ -329,8 +336,8 @@ void t_st_generator::generate_class_side_definition() {
void t_st_generator::generate_enum(t_enum* tenum) {
string cls_name = program_name_ + capitalize(tenum->get_name());
- f_ << prefix(class_name()) << " enums at: '" << tenum->get_name() << "' put: ["
- << "(Dictionary new " << endl;
+ f_ << prefix(class_name()) << " enums at: '" << tenum->get_name() << "' put: [" <<
+ "(Dictionary new " << endl;
vector<t_enum_value*> constants = tenum->get_constants();
vector<t_enum_value*>::iterator c_iter;
@@ -350,8 +357,8 @@ void t_st_generator::generate_const(t_const* tconst) {
string name = tconst->get_name();
t_const_value* value = tconst->get_value();
- f_ << prefix(class_name()) << " constants at: '" << name << "' put: ["
- << render_const_value(type, value) << "]!" << endl << endl;
+ f_ << prefix(class_name()) << " constants at: '" << name << "' put: [" <<
+ render_const_value(type, value) << "]!" << endl << endl;
}
/**
@@ -409,8 +416,8 @@ string t_st_generator::render_const_value(t_type* type, t_const_value* value) {
throw "type error: " + type->get_name() + " has no field " + v_iter->first->get_string();
}
- out << indent() << v_iter->first->get_string() << ": "
- << render_const_value(field_type, v_iter->second) << ";" << endl;
+ out << indent() << v_iter->first->get_string() << ": " <<
+ render_const_value(field_type, v_iter->second) << ";" << endl;
}
out << indent() << "yourself)";
@@ -483,9 +490,7 @@ void t_st_generator::generate_xception(t_struct* txception) {
/**
* Generates a smalltalk class to represent a struct
*/
-void t_st_generator::generate_st_struct(std::ofstream& out,
- t_struct* tstruct,
- bool is_exception = false) {
+void t_st_generator::generate_st_struct(std::ofstream& out, t_struct* tstruct, bool is_exception = false) {
const vector<t_field*>& members = tstruct->get_members();
vector<t_field*>::const_iterator m_iter;
@@ -494,31 +499,27 @@ void t_st_generator::generate_st_struct(std::ofstream& out,
else
out << "Object";
- out << " subclass: #" << prefix(type_name(tstruct)) << endl << "\tinstanceVariableNames: '";
+ out << " subclass: #" << prefix(type_name(tstruct)) << endl <<
+ "\tinstanceVariableNames: '";
if (members.size() > 0) {
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- if (m_iter != members.begin())
- out << " ";
+ if (m_iter != members.begin()) out << " ";
out << camelcase((*m_iter)->get_name());
}
}
- out << "'\n"
- << "\tclassVariableNames: ''\n"
- << "\tpoolDictionaries: ''\n"
- << "\tcategory: '" << generated_category() << "'!\n\n";
+ out << "'\n" <<
+ "\tclassVariableNames: ''\n" <<
+ "\tpoolDictionaries: ''\n" <<
+ "\tcategory: '" << generated_category() << "'!\n\n";
generate_accessors(out, tstruct);
}
bool t_st_generator::is_vowel(char c) {
- switch (tolower(c)) {
- case 'a':
- case 'e':
- case 'i':
- case 'o':
- case 'u':
+ switch(tolower(c)) {
+ case 'a': case 'e': case 'i': case 'o': case 'u':
return true;
}
return false;
@@ -568,30 +569,30 @@ string t_st_generator::temp_name() {
return out.str();
}
-string t_st_generator::map_writer(t_map* tmap, string fname) {
+string t_st_generator::map_writer(t_map *tmap, string fname) {
std::ostringstream out;
string key = temp_name();
string val = temp_name();
- out << "[oprot writeMapBegin: (TMap new keyType: " << type_to_enum(tmap->get_key_type())
- << "; valueType: " << type_to_enum(tmap->get_val_type()) << "; size: " << fname << " size)."
- << endl;
+ out << "[oprot writeMapBegin: (TMap new keyType: " << type_to_enum(tmap->get_key_type()) <<
+ "; valueType: " << type_to_enum(tmap->get_val_type()) << "; size: " << fname << " size)." << endl;
indent_up();
out << indent() << fname << " keysAndValuesDo: [:" << key << " :" << val << " |" << endl;
indent_up();
- out << indent() << write_val(tmap->get_key_type(), key) << "." << endl << indent()
- << write_val(tmap->get_val_type(), val);
+ out << indent() << write_val(tmap->get_key_type(), key) << "." << endl <<
+ indent() << write_val(tmap->get_val_type(), val);
indent_down();
- out << "]." << endl << indent() << "oprot writeMapEnd] value";
+ out << "]." << endl <<
+ indent() << "oprot writeMapEnd] value";
indent_down();
return out.str();
}
-string t_st_generator::map_reader(t_map* tmap) {
+string t_st_generator::map_reader(t_map *tmap) {
std::ostringstream out;
string desc = temp_name();
string val = temp_name();
@@ -599,26 +600,29 @@ string t_st_generator::map_reader(t_map* tmap) {
out << "[|" << desc << " " << val << "| " << endl;
indent_up();
- out << indent() << desc << " := iprot readMapBegin." << endl << indent() << val
- << " := Dictionary new." << endl << indent() << desc << " size timesRepeat: [" << endl;
+ out << indent() << desc << " := iprot readMapBegin." << endl <<
+ indent() << val << " := Dictionary new." << endl <<
+ indent() << desc << " size timesRepeat: [" << endl;
indent_up();
- out << indent() << val << " at: " << read_val(tmap->get_key_type())
- << " put: " << read_val(tmap->get_val_type());
+ out << indent() << val << " at: " << read_val(tmap->get_key_type()) <<
+ " put: " << read_val(tmap->get_val_type());
indent_down();
- out << "]." << endl << indent() << "iprot readMapEnd." << endl << indent() << val << "] value";
+ out << "]." << endl <<
+ indent() << "iprot readMapEnd." << endl <<
+ indent() << val << "] value";
indent_down();
return out.str();
}
-string t_st_generator::list_writer(t_list* tlist, string fname) {
+string t_st_generator::list_writer(t_list *tlist, string fname) {
std::ostringstream out;
string val = temp_name();
- out << "[oprot writeListBegin: (TList new elemType: " << type_to_enum(tlist->get_elem_type())
- << "; size: " << fname << " size)." << endl;
+ out << "[oprot writeListBegin: (TList new elemType: " <<
+ type_to_enum(tlist->get_elem_type()) << "; size: " << fname << " size)." << endl;
indent_up();
out << indent() << fname << " do: [:" << val << "|" << endl;
@@ -627,13 +631,14 @@ string t_st_generator::list_writer(t_list* tlist, string fname) {
out << indent() << write_val(tlist->get_elem_type(), val) << endl;
indent_down();
- out << "]." << endl << indent() << "oprot writeListEnd] value";
+ out << "]." << endl <<
+ indent() << "oprot writeListEnd] value";
indent_down();
return out.str();
}
-string t_st_generator::list_reader(t_list* tlist) {
+string t_st_generator::list_reader(t_list *tlist) {
std::ostringstream out;
string desc = temp_name();
string val = temp_name();
@@ -641,25 +646,27 @@ string t_st_generator::list_reader(t_list* tlist) {
out << "[|" << desc << " " << val << "| " << desc << " := iprot readListBegin." << endl;
indent_up();
- out << indent() << val << " := OrderedCollection new." << endl << indent() << desc
- << " size timesRepeat: [" << endl;
+ out << indent() << val << " := OrderedCollection new." << endl <<
+ indent() << desc << " size timesRepeat: [" << endl;
indent_up();
out << indent() << val << " add: " << read_val(tlist->get_elem_type());
indent_down();
- out << "]." << endl << indent() << "iprot readListEnd." << endl << indent() << val << "] value";
+ out << "]." << endl <<
+ indent() << "iprot readListEnd." << endl <<
+ indent() << val << "] value";
indent_down();
return out.str();
}
-string t_st_generator::set_writer(t_set* tset, string fname) {
+string t_st_generator::set_writer(t_set *tset, string fname) {
std::ostringstream out;
string val = temp_name();
- out << "[oprot writeSetBegin: (TSet new elemType: " << type_to_enum(tset->get_elem_type())
- << "; size: " << fname << " size)." << endl;
+ out << "[oprot writeSetBegin: (TSet new elemType: " << type_to_enum(tset->get_elem_type()) <<
+ "; size: " << fname << " size)." << endl;
indent_up();
out << indent() << fname << " do: [:" << val << "|" << endl;
@@ -668,13 +675,14 @@ string t_st_generator::set_writer(t_set* tset, string fname) {
out << indent() << write_val(tset->get_elem_type(), val) << endl;
indent_down();
- out << "]." << endl << indent() << "oprot writeSetEnd] value";
+ out << "]." << endl <<
+ indent() << "oprot writeSetEnd] value";
indent_down();
return out.str();
}
-string t_st_generator::set_reader(t_set* tset) {
+string t_st_generator::set_reader(t_set *tset) {
std::ostringstream out;
string desc = temp_name();
string val = temp_name();
@@ -682,26 +690,28 @@ string t_st_generator::set_reader(t_set* tset) {
out << "[|" << desc << " " << val << "| " << desc << " := iprot readSetBegin." << endl;
indent_up();
- out << indent() << val << " := Set new." << endl << indent() << desc << " size timesRepeat: ["
- << endl;
+ out << indent() << val << " := Set new." << endl <<
+ indent() << desc << " size timesRepeat: [" << endl;
indent_up();
out << indent() << val << " add: " << read_val(tset->get_elem_type());
indent_down();
- out << "]." << endl << indent() << "iprot readSetEnd." << endl << indent() << val << "] value";
+ out << "]." << endl <<
+ indent() << "iprot readSetEnd." << endl <<
+ indent() << val << "] value";
indent_down();
return out.str();
}
-string t_st_generator::struct_writer(t_struct* tstruct, string sname) {
+string t_st_generator::struct_writer(t_struct *tstruct, string sname) {
std::ostringstream out;
const vector<t_field*>& fields = tstruct->get_sorted_members();
vector<t_field*>::const_iterator fld_iter;
- out << "[oprot writeStructBegin: "
- << "(TStruct new name: '" + tstruct->get_name() + "')." << endl;
+ out << "[oprot writeStructBegin: " <<
+ "(TStruct new name: '" + tstruct->get_name() +"')." << endl;
indent_up();
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
@@ -714,12 +724,12 @@ string t_st_generator::struct_writer(t_struct* tstruct, string sname) {
indent_up();
}
- out << indent() << "oprot writeFieldBegin: (TField new name: '" << fname
- << "'; type: " << type_to_enum((*fld_iter)->get_type())
- << "; id: " << (*fld_iter)->get_key() << ")." << endl;
+ out << indent() << "oprot writeFieldBegin: (TField new name: '" << fname <<
+ "'; type: " << type_to_enum((*fld_iter)->get_type()) <<
+ "; id: " << (*fld_iter)->get_key() << ")." << endl;
- out << indent() << write_val((*fld_iter)->get_type(), accessor) << "." << endl << indent()
- << "oprot writeFieldEnd";
+ out << indent() << write_val((*fld_iter)->get_type(), accessor) << "." << endl <<
+ indent() << "oprot writeFieldEnd";
if (optional) {
out << "]";
@@ -735,7 +745,7 @@ string t_st_generator::struct_writer(t_struct* tstruct, string sname) {
return out.str();
}
-string t_st_generator::struct_reader(t_struct* tstruct, string clsName = "") {
+string t_st_generator::struct_reader(t_struct *tstruct, string clsName = "") {
std::ostringstream out;
const vector<t_field*>& fields = tstruct->get_members();
vector<t_field*>::const_iterator fld_iter;
@@ -750,21 +760,23 @@ string t_st_generator::struct_reader(t_struct* tstruct, string clsName = "") {
out << "[|" << desc << " " << val << "|" << endl;
indent_up();
- // This is nasty, but without it we'll break things by prefixing TResult.
+ //This is nasty, but without it we'll break things by prefixing TResult.
string name = ((capitalize(clsName) == "TResult") ? capitalize(clsName) : prefix(clsName));
out << indent() << val << " := " << name << " new." << endl;
- out << indent() << "iprot readStructBegin." << endl << indent() << "[" << desc
- << " := iprot readFieldBegin." << endl << indent() << desc
- << " type = TType stop] whileFalse: [|" << found << "|" << endl;
+ out << indent() << "iprot readStructBegin." << endl <<
+ indent() << "[" << desc << " := iprot readFieldBegin." << endl <<
+ indent() << desc << " type = TType stop] whileFalse: [|" << found << "|" << endl;
indent_up();
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
- out << indent() << desc << " id = " << (*fld_iter)->get_key() << " ifTrue: [" << endl;
+ out << indent() << desc << " id = " << (*fld_iter)->get_key() <<
+ " ifTrue: [" << endl;
indent_up();
- out << indent() << found << " := true." << endl << indent() << val << " "
- << camelcase((*fld_iter)->get_name()) << ": " << read_val((*fld_iter)->get_type());
+ out << indent() << found << " := true." << endl <<
+ indent() << val << " " << camelcase((*fld_iter)->get_name()) << ": " <<
+ read_val((*fld_iter)->get_type());
indent_down();
out << "]." << endl;
@@ -773,18 +785,19 @@ string t_st_generator::struct_reader(t_struct* tstruct, string clsName = "") {
out << indent() << found << " ifNil: [iprot skip: " << desc << " type]]." << endl;
indent_down();
- out << indent() << "oprot readStructEnd." << endl << indent() << val << "] value";
+ out << indent() << "oprot readStructEnd." << endl <<
+ indent() << val << "] value";
indent_down();
return out.str();
}
-string t_st_generator::write_val(t_type* t, string fname) {
+string t_st_generator::write_val(t_type *t, string fname) {
t = get_true_type(t);
if (t->is_base_type()) {
- t_base_type::t_base tbase = ((t_base_type*)t)->get_base();
- switch (tbase) {
+ t_base_type::t_base tbase = ((t_base_type*) t)->get_base();
+ switch(tbase) {
case t_base_type::TYPE_DOUBLE:
return "iprot writeDouble: " + fname + " asFloat";
break;
@@ -797,13 +810,13 @@ string t_st_generator::write_val(t_type* t, string fname) {
return "iprot write" + capitalize(type_name(t)) + ": " + fname;
}
} else if (t->is_map()) {
- return map_writer((t_map*)t, fname);
+ return map_writer((t_map*) t, fname);
} else if (t->is_struct() || t->is_xception()) {
- return struct_writer((t_struct*)t, fname);
+ return struct_writer((t_struct*) t, fname);
} else if (t->is_list()) {
- return list_writer((t_list*)t, fname);
+ return list_writer((t_list*) t, fname);
} else if (t->is_set()) {
- return set_writer((t_set*)t, fname);
+ return set_writer((t_set*) t, fname);
} else if (t->is_enum()) {
return "iprot writeI32: " + fname;
} else {
@@ -811,19 +824,19 @@ string t_st_generator::write_val(t_type* t, string fname) {
}
}
-string t_st_generator::read_val(t_type* t) {
+string t_st_generator::read_val(t_type *t) {
t = get_true_type(t);
if (t->is_base_type()) {
return "iprot read" + capitalize(type_name(t));
} else if (t->is_map()) {
- return map_reader((t_map*)t);
+ return map_reader((t_map*) t);
} else if (t->is_struct() || t->is_xception()) {
- return struct_reader((t_struct*)t);
+ return struct_reader((t_struct*) t);
} else if (t->is_list()) {
- return list_reader((t_list*)t);
+ return list_reader((t_list*) t);
} else if (t->is_set()) {
- return set_reader((t_set*)t);
+ return set_reader((t_set*) t);
} else if (t->is_enum()) {
return "iprot readI32";
} else {
@@ -845,23 +858,23 @@ void t_st_generator::generate_send_method(t_function* function) {
f_ << indent() << "(TCallMessage new" << endl;
indent_up();
- f_ << indent() << "name: '" << funname << "'; " << endl << indent() << "seqid: self nextSeqid)."
- << endl;
+ f_ << indent() << "name: '" << funname << "'; " << endl <<
+ indent() << "seqid: self nextSeqid)." << endl;
indent_down();
indent_down();
- f_ << indent() << "oprot writeStructBegin: "
- << "(TStruct new name: '" + capitalize(camelcase(funname)) + "_args')." << endl;
+ f_ << indent() << "oprot writeStructBegin: " <<
+ "(TStruct new name: '" + capitalize(camelcase(funname)) + "_args')." << endl;
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
string fname = camelcase((*fld_iter)->get_name());
- f_ << indent() << "oprot writeFieldBegin: (TField new name: '" << fname
- << "'; type: " << type_to_enum((*fld_iter)->get_type()) << "; id: " << (*fld_iter)->get_key()
- << ")." << endl;
+ f_ << indent() << "oprot writeFieldBegin: (TField new name: '" << fname <<
+ "'; type: " << type_to_enum((*fld_iter)->get_type()) <<
+ "; id: " << (*fld_iter)->get_key() << ")." << endl;
- f_ << indent() << write_val((*fld_iter)->get_type(), fname) << "." << endl << indent()
- << "oprot writeFieldEnd." << endl;
+ f_ << indent() << write_val((*fld_iter)->get_type(), fname) << "." << endl <<
+ indent() << "oprot writeFieldEnd." << endl;
}
f_ << indent() << "oprot writeFieldStop; writeStructEnd; writeMessageEnd." << endl;
@@ -884,16 +897,19 @@ void t_st_generator::generate_recv_method(t_function* function) {
vector<t_field*>::const_iterator f_iter;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
// duplicate the field, but call it "exception"... we don't need a dynamic name
- t_field* exception = new t_field((*f_iter)->get_type(), "exception", (*f_iter)->get_key());
+ t_field *exception = new t_field((*f_iter)->get_type(), "exception", (*f_iter)->get_key());
result.append(exception);
}
st_method(f_, client_class_name(), "recv" + capitalize(funname));
- f_ << "| f msg res | " << endl << indent() << "msg := oprot readMessageBegin." << endl << indent()
- << "self validateRemoteMessage: msg." << endl << indent()
- << "res := " << struct_reader(&result) << "." << endl << indent() << "oprot readMessageEnd."
- << endl << indent() << "oprot transport flush." << endl << indent()
- << "res exception ifNotNil: [res exception signal]." << endl << indent() << "^ res";
+ f_ << "| f msg res | " << endl <<
+ indent() << "msg := oprot readMessageBegin." << endl <<
+ indent() << "self validateRemoteMessage: msg." << endl <<
+ indent() << "res := " << struct_reader(&result) << "." << endl <<
+ indent() << "oprot readMessageEnd." << endl <<
+ indent() << "oprot transport flush." << endl <<
+ indent() << "res exception ifNotNil: [res exception signal]." << endl <<
+ indent() << "^ res";
st_close_method(f_);
}
@@ -932,19 +948,19 @@ void t_st_generator::generate_service_client(t_service* tservice) {
extends_client = extends + "Client";
}
- f_ << extends_client << " subclass: #" << prefix(client_class_name()) << endl
- << "\tinstanceVariableNames: ''\n"
- << "\tclassVariableNames: ''\n"
- << "\tpoolDictionaries: ''\n"
- << "\tcategory: '" << generated_category() << "'!\n\n";
+ f_ << extends_client << " subclass: #" << prefix(client_class_name()) << endl <<
+ "\tinstanceVariableNames: ''\n" <<
+ "\tclassVariableNames: ''\n" <<
+ "\tpoolDictionaries: ''\n" <<
+ "\tcategory: '" << generated_category() << "'!\n\n";
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
string funname = camelcase((*f_iter)->get_name());
string signature = function_signature(*f_iter);
st_method(f_, client_class_name(), signature);
- f_ << function_types_comment(*f_iter) << endl << indent() << "self send"
- << capitalize(signature) << "." << endl;
+ f_ << function_types_comment(*f_iter) << endl <<
+ indent() << "self send" << capitalize(signature) << "." << endl;
if (!(*f_iter)->is_oneway()) {
f_ << indent() << "^ self recv" << capitalize(funname) << " success " << endl;
@@ -1046,4 +1062,6 @@ string t_st_generator::type_to_enum(t_type* type) {
throw "INVALID TYPE IN type_to_enum: " + type->get_name();
}
+
THRIFT_REGISTER_GENERATOR(st, "Smalltalk", "")
+
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/compiler/cpp/src/generate/t_xsd_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_xsd_generator.cc b/compiler/cpp/src/generate/t_xsd_generator.cc
index ed76bec..7135f6a 100644
--- a/compiler/cpp/src/generate/t_xsd_generator.cc
+++ b/compiler/cpp/src/generate/t_xsd_generator.cc
@@ -35,20 +35,22 @@ 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
/**
* XSD generator, creates an XSD for the base types etc.
*
*/
class t_xsd_generator : public t_generator {
-public:
- t_xsd_generator(t_program* program,
- const std::map<std::string, std::string>& parsed_options,
- const std::string& option_string)
- : t_generator(program) {
- (void)parsed_options;
- (void)option_string;
+ public:
+ t_xsd_generator(
+ t_program* program,
+ const std::map<std::string, std::string>& parsed_options,
+ const std::string& option_string)
+ : t_generator(program)
+ {
+ (void) parsed_options;
+ (void) option_string;
out_dir_base_ = "gen-xsd";
}
@@ -66,23 +68,24 @@ public:
*/
void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum) { (void)tenum; }
+ void generate_enum(t_enum* tenum) {
+ (void) tenum;
+ }
void generate_service(t_service* tservice);
void generate_struct(t_struct* tstruct);
-private:
- void generate_element(std::ostream& out,
- std::string name,
- t_type* ttype,
- t_struct* attrs = NULL,
- bool optional = false,
- bool nillable = false,
- bool list_element = false);
+ private:
- std::string ns(std::string in, std::string ns) { return ns + ":" + in; }
+ void generate_element(std::ostream& out, std::string name, t_type* ttype, t_struct* attrs=NULL, bool optional=false, bool nillable=false, bool list_element=false);
- std::string xsd(std::string in) { return ns(in, "xsd"); }
+ std::string ns(std::string in, std::string ns) {
+ return ns + ":" + in;
+ }
+
+ std::string xsd(std::string in) {
+ return ns(in, "xsd");
+ }
std::string type_name(t_type* ttype);
std::string base_type_name(t_base_type::t_base tbase);
@@ -97,17 +100,21 @@ private:
* Output string stream
*/
std::ostringstream s_xsd_types_;
+
};
+
void t_xsd_generator::init_generator() {
// Make output directory
MKDIR(get_out_dir().c_str());
// Make output file
- string f_php_name = get_out_dir() + program_->get_name() + "_xsd.php";
+ string f_php_name = get_out_dir()+program_->get_name()+"_xsd.php";
f_php_.open(f_php_name.c_str());
- f_php_ << "<?php" << endl;
+ f_php_ <<
+ "<?php" << endl;
+
}
void t_xsd_generator::close_generator() {
@@ -116,25 +123,29 @@ void t_xsd_generator::close_generator() {
}
void t_xsd_generator::generate_typedef(t_typedef* ttypedef) {
- indent(s_xsd_types_) << "<xsd:simpleType name=\"" << ttypedef->get_name() << "\">" << endl;
+ indent(s_xsd_types_) <<
+ "<xsd:simpleType name=\"" << ttypedef->get_name() << "\">" << endl;
indent_up();
if (ttypedef->get_type()->is_string() && ((t_base_type*)ttypedef->get_type())->is_string_enum()) {
- indent(s_xsd_types_) << "<xsd:restriction base=\"" << type_name(ttypedef->get_type()) << "\">"
- << endl;
+ indent(s_xsd_types_) <<
+ "<xsd:restriction base=\"" << type_name(ttypedef->get_type()) << "\">" << endl;
indent_up();
const vector<string>& values = ((t_base_type*)ttypedef->get_type())->get_string_enum_vals();
vector<string>::const_iterator v_iter;
for (v_iter = values.begin(); v_iter != values.end(); ++v_iter) {
- indent(s_xsd_types_) << "<xsd:enumeration value=\"" << (*v_iter) << "\" />" << endl;
+ indent(s_xsd_types_) <<
+ "<xsd:enumeration value=\"" << (*v_iter) << "\" />" << endl;
}
indent_down();
- indent(s_xsd_types_) << "</xsd:restriction>" << endl;
+ indent(s_xsd_types_) <<
+ "</xsd:restriction>" << endl;
} else {
- indent(s_xsd_types_) << "<xsd:restriction base=\"" << type_name(ttypedef->get_type()) << "\" />"
- << endl;
+ indent(s_xsd_types_) <<
+ "<xsd:restriction base=\"" << type_name(ttypedef->get_type()) << "\" />" << endl;
}
indent_down();
- indent(s_xsd_types_) << "</xsd:simpleType>" << endl << endl;
+ indent(s_xsd_types_) <<
+ "</xsd:simpleType>" << endl << endl;
}
void t_xsd_generator::generate_struct(t_struct* tstruct) {
@@ -152,12 +163,7 @@ void t_xsd_generator::generate_struct(t_struct* tstruct) {
indent_up();
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- generate_element(s_xsd_types_,
- (*m_iter)->get_name(),
- (*m_iter)->get_type(),
- (*m_iter)->get_xsd_attrs(),
- (*m_iter)->get_xsd_optional() || xsd_all,
- (*m_iter)->get_xsd_nillable());
+ generate_element(s_xsd_types_, (*m_iter)->get_name(), (*m_iter)->get_type(), (*m_iter)->get_xsd_attrs(), (*m_iter)->get_xsd_optional() || xsd_all, (*m_iter)->get_xsd_nillable());
}
indent_down();
@@ -167,7 +173,9 @@ void t_xsd_generator::generate_struct(t_struct* tstruct) {
indent(s_xsd_types_) << "</xsd:sequence>" << endl;
}
indent_down();
- indent(s_xsd_types_) << "</xsd:complexType>" << endl << endl;
+ indent(s_xsd_types_) <<
+ "</xsd:complexType>" << endl <<
+ endl;
}
void t_xsd_generator::generate_element(ostream& out,
@@ -183,12 +191,15 @@ void t_xsd_generator::generate_element(ostream& out,
string snillable = nillable ? " nillable=\"true\"" : "";
if (ttype->is_void() || ttype->is_list()) {
- indent(out) << "<xsd:element name=\"" << name << "\"" << soptional << snillable << ">" << endl;
+ indent(out) <<
+ "<xsd:element name=\"" << name << "\"" << soptional << snillable << ">" << endl;
indent_up();
if (attrs == NULL && ttype->is_void()) {
- indent(out) << "<xsd:complexType />" << endl;
+ indent(out) <<
+ "<xsd:complexType />" << endl;
} else {
- indent(out) << "<xsd:complexType>" << endl;
+ indent(out) <<
+ "<xsd:complexType>" << endl;
indent_up();
if (ttype->is_list()) {
indent(out) << "<xsd:sequence minOccurs=\"0\" maxOccurs=\"unbounded\">" << endl;
@@ -200,8 +211,7 @@ void t_xsd_generator::generate_element(ostream& out,
} else {
subname = type_name(subtype);
}
- f_php_ << "$GLOBALS['" << program_->get_name() << "_xsd_elt_" << name << "'] = '" << subname
- << "';" << endl;
+ f_php_ << "$GLOBALS['" << program_->get_name() << "_xsd_elt_" << name << "'] = '" << subname << "';" << endl;
generate_element(out, subname, subtype, NULL, false, false, true);
indent_down();
indent(out) << "</xsd:sequence>" << endl;
@@ -211,24 +221,23 @@ void t_xsd_generator::generate_element(ostream& out,
const vector<t_field*>& members = attrs->get_members();
vector<t_field*>::const_iterator a_iter;
for (a_iter = members.begin(); a_iter != members.end(); ++a_iter) {
- indent(out) << "<xsd:attribute name=\"" << (*a_iter)->get_name() << "\" type=\""
- << type_name((*a_iter)->get_type()) << "\" />" << endl;
+ indent(out) << "<xsd:attribute name=\"" << (*a_iter)->get_name() << "\" type=\"" << type_name((*a_iter)->get_type()) << "\" />" << endl;
}
}
indent_down();
- indent(out) << "</xsd:complexType>" << endl;
+ indent(out) <<
+ "</xsd:complexType>" << endl;
}
indent_down();
- indent(out) << "</xsd:element>" << endl;
+ indent(out) <<
+ "</xsd:element>" << endl;
} else {
if (attrs == NULL) {
- indent(out) << "<xsd:element name=\"" << name << "\""
- << " type=\"" << type_name(ttype) << "\"" << soptional << snillable << " />"
- << endl;
+ indent(out) <<
+ "<xsd:element name=\"" << name << "\"" << " type=\"" << type_name(ttype) << "\"" << soptional << snillable << " />" << endl;
} else {
// Wow, all this work for a SIMPLE TYPE with attributes?!?!?!
- indent(out) << "<xsd:element name=\"" << name << "\"" << soptional << snillable << ">"
- << endl;
+ indent(out) << "<xsd:element name=\"" << name << "\"" << soptional << snillable << ">" << endl;
indent_up();
indent(out) << "<xsd:complexType>" << endl;
indent_up();
@@ -239,8 +248,7 @@ void t_xsd_generator::generate_element(ostream& out,
const vector<t_field*>& members = attrs->get_members();
vector<t_field*>::const_iterator a_iter;
for (a_iter = members.begin(); a_iter != members.end(); ++a_iter) {
- indent(out) << "<xsd:attribute name=\"" << (*a_iter)->get_name() << "\" type=\""
- << type_name((*a_iter)->get_type()) << "\" />" << endl;
+ indent(out) << "<xsd:attribute name=\"" << (*a_iter)->get_name() << "\" type=\"" << type_name((*a_iter)->get_type()) << "\" />" << endl;
}
indent_down();
indent(out) << "</xsd:extension>" << endl;
@@ -256,19 +264,22 @@ void t_xsd_generator::generate_element(ostream& out,
void t_xsd_generator::generate_service(t_service* tservice) {
// Make output file
- string f_xsd_name = get_out_dir() + tservice->get_name() + ".xsd";
+ string f_xsd_name = get_out_dir()+tservice->get_name()+".xsd";
f_xsd_.open(f_xsd_name.c_str());
string ns = program_->get_namespace("xsd");
if (ns.size() > 0) {
- ns = " targetNamespace=\"" + ns + "\" xmlns=\"" + ns + "\" "
- + "elementFormDefault=\"qualified\"";
+ ns = " targetNamespace=\"" + ns + "\" xmlns=\"" + ns + "\" " +
+ "elementFormDefault=\"qualified\"";
}
// Print the XSD header
- f_xsd_ << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << endl
- << "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" << ns << ">" << endl
- << endl << "<!-- Yo yo yo, this XSD woz be generated by Thrift. -->" << endl << endl;
+ f_xsd_ <<
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << endl <<
+ "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" << ns << ">" << endl <<
+ endl <<
+ "<!-- Yo yo yo, this XSD woz be generated by Thrift. -->" << endl <<
+ endl;
// Print out the type definitions
indent(f_xsd_) << s_xsd_types_.str();
@@ -353,3 +364,4 @@ string t_xsd_generator::base_type_name(t_base_type::t_base tbase) {
}
THRIFT_REGISTER_GENERATOR(xsd, "XSD", "")
+
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/compiler/cpp/src/globals.h
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/globals.h b/compiler/cpp/src/globals.h
index 93d11aa..cf924f1 100644
--- a/compiler/cpp/src/globals.h
+++ b/compiler/cpp/src/globals.h
@@ -48,7 +48,10 @@ class t_type;
* Parsing mode, two passes up in this gin rummy!
*/
-enum PARSE_MODE { INCLUDES = 1, PROGRAM = 2 };
+enum PARSE_MODE {
+ INCLUDES = 1,
+ PROGRAM = 2
+};
/**
* Strictness level
@@ -116,18 +119,19 @@ extern int g_doctext_lineno;
*/
enum PROGDOCTEXT_STATUS {
INVALID = 0,
- STILL_CANDIDATE = 1, // the text may or may not be the program doctext
- ALREADY_PROCESSED = 2, // doctext has been used and is no longer available
- ABSOLUTELY_SURE = 3, // this is the program doctext
- NO_PROGRAM_DOCTEXT = 4 // there is no program doctext
+ STILL_CANDIDATE = 1, // the text may or may not be the program doctext
+ ALREADY_PROCESSED = 2, // doctext has been used and is no longer available
+ ABSOLUTELY_SURE = 3, // this is the program doctext
+ NO_PROGRAM_DOCTEXT = 4 // there is no program doctext
};
+
/**
* The program level doctext. Stored seperately to make parsing easier.
*/
extern char* g_program_doctext_candidate;
-extern int g_program_doctext_lineno;
-extern PROGDOCTEXT_STATUS g_program_doctext_status;
+extern int g_program_doctext_lineno;
+extern PROGDOCTEXT_STATUS g_program_doctext_status;
/**
* Whether or not negative field keys are accepted.
http://git-wip-us.apache.org/repos/asf/thrift/blob/240120c8/compiler/cpp/src/logging.h
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/logging.h b/compiler/cpp/src/logging.h
index 3f1fce8..097469d 100644
--- a/compiler/cpp/src/logging.h
+++ b/compiler/cpp/src/logging.h
@@ -42,4 +42,5 @@ void pverbose(const char* fmt, ...);
*/
void failure(const char* fmt, ...);
+
#endif