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:26 UTC

[34/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_cocoa_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_cocoa_generator.cc b/compiler/cpp/src/generate/t_cocoa_generator.cc
index 3ad6c31..cbed831 100644
--- a/compiler/cpp/src/generate/t_cocoa_generator.cc
+++ b/compiler/cpp/src/generate/t_cocoa_generator.cc
@@ -35,7 +35,7 @@ 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
 
 /**
  * Objective-C code generator.
@@ -43,12 +43,14 @@ static const string endl = "\n"; // avoid ostream << std::endl flushes
  * mostly copy/pasting/tweaking from mcslee's work.
  */
 class t_cocoa_generator : public t_oop_generator {
-public:
-  t_cocoa_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_cocoa_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("log_unexpected");
@@ -73,38 +75,26 @@ 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 defval = false,
-                         bool is_property = false);
-  std::string render_const_value(ofstream& out,
-                                 t_type* type,
-                                 t_const_value* value,
-                                 bool containerize_it = false);
+  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 defval=false, bool is_property=false);
+  std::string render_const_value(ofstream& out, t_type* type, t_const_value* value, bool containerize_it=false);
 
   void generate_cocoa_struct(t_struct* tstruct, bool is_exception);
-  void generate_cocoa_struct_interface(std::ofstream& out,
-                                       t_struct* tstruct,
-                                       bool is_xception = false);
-  void generate_cocoa_struct_implementation(std::ofstream& out,
-                                            t_struct* tstruct,
-                                            bool is_xception = false,
-                                            bool is_result = false);
-  void generate_cocoa_struct_initializer_signature(std::ofstream& out, t_struct* tstruct);
-  void generate_cocoa_struct_init_with_coder_method(ofstream& out,
+  void generate_cocoa_struct_interface(std::ofstream& out, t_struct* tstruct, bool is_xception=false);
+  void generate_cocoa_struct_implementation(std::ofstream& out, t_struct* tstruct, bool is_xception=false, bool is_result=false);
+  void generate_cocoa_struct_initializer_signature(std::ofstream& out,
+                                                   t_struct* tstruct);
+  void generate_cocoa_struct_init_with_coder_method(ofstream &out,
+                                                    t_struct* tstruct,
+                                                    bool is_exception);
+  void generate_cocoa_struct_encode_with_coder_method(ofstream &out,
                                                     t_struct* tstruct,
                                                     bool is_exception);
-  void generate_cocoa_struct_encode_with_coder_method(ofstream& out,
-                                                      t_struct* tstruct,
-                                                      bool is_exception);
   void generate_cocoa_struct_field_accessor_declarations(std::ofstream& out,
                                                          t_struct* tstruct,
                                                          bool is_exception);
@@ -125,51 +115,69 @@ public:
    * Service-level generation functions
    */
 
-  void generate_cocoa_service_protocol(std::ofstream& out, t_service* tservice);
-  void generate_cocoa_service_client_interface(std::ofstream& out, t_service* tservice);
-  void generate_cocoa_service_client_implementation(std::ofstream& out, t_service* tservice);
-  void generate_cocoa_service_server_interface(std::ofstream& out, t_service* tservice);
-  void generate_cocoa_service_server_implementation(std::ofstream& out, t_service* tservice);
-  void generate_cocoa_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_cocoa_service_protocol (std::ofstream& out, t_service* tservice);
+  void generate_cocoa_service_client_interface (std::ofstream& out, t_service* tservice);
+  void generate_cocoa_service_client_implementation (std::ofstream& out, t_service* tservice);
+  void generate_cocoa_service_server_interface (std::ofstream& out, t_service* tservice);
+  void generate_cocoa_service_server_implementation (std::ofstream& out, t_service* tservice);
+  void generate_cocoa_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 fieldName);
+  void generate_deserialize_field        (std::ofstream& out,
+                                          t_field*    tfield,
+                                          std::string fieldName);
 
-  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 fieldName = "");
+  void generate_serialize_struct         (std::ofstream& out,
+                                          t_struct*   tstruct,
+                                          std::string fieldName="");
 
-  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 index,
-                                       std::string listName);
+  void generate_serialize_list_element   (std::ofstream& out,
+                                          t_list*     tlist,
+                                          std::string index,
+                                          std::string listName);
 
   /**
    * Helper rendering functions
@@ -178,7 +186,7 @@ public:
   std::string cocoa_prefix();
   std::string cocoa_imports();
   std::string cocoa_thrift_imports();
-  std::string type_name(t_type* ttype, bool class_ref = false);
+  std::string type_name(t_type* ttype, bool class_ref=false);
   std::string base_type_name(t_base_type* tbase);
   std::string declare_field(t_field* tfield);
   std::string declare_property(t_field* tfield);
@@ -187,17 +195,21 @@ public:
   std::string type_to_enum(t_type* ttype);
   std::string format_string_for_type(t_type* type);
   std::string call_field_setter(t_field* tfield, std::string fieldName);
-  std::string containerize(t_type* ttype, std::string fieldName);
-  std::string decontainerize(t_field* tfield, std::string fieldName);
+  std::string containerize(t_type * ttype, std::string fieldName);
+  std::string decontainerize(t_field * tfield, std::string fieldName);
 
   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();
   }
 
-private:
+ private:
+
   std::string cocoa_prefix_;
   std::string constants_declarations_;
 
@@ -212,6 +224,7 @@ private:
   bool validate_required_;
 };
 
+
 /**
  * Prepares for file generation by opening up the necessary file output
  * streams.
@@ -222,22 +235,32 @@ void t_cocoa_generator::init_generator() {
   cocoa_prefix_ = program_->get_namespace("cocoa");
 
   // we have a .h header file...
-  string f_header_name = program_name_ + ".h";
-  string f_header_fullname = get_out_dir() + f_header_name;
+  string f_header_name = program_name_+".h";
+  string f_header_fullname = get_out_dir()+f_header_name;
   f_header_.open(f_header_fullname.c_str());
 
-  f_header_ << autogen_comment() << endl;
+  f_header_ <<
+    autogen_comment() <<
+    endl;
 
-  f_header_ << cocoa_imports() << cocoa_thrift_imports();
+  f_header_ <<
+    cocoa_imports() <<
+    cocoa_thrift_imports();
 
   // ...and a .m implementation file
-  string f_impl_name = get_out_dir() + program_name_ + ".m";
+  string f_impl_name = get_out_dir()+program_name_+".m";
   f_impl_.open(f_impl_name.c_str());
 
-  f_impl_ << autogen_comment() << endl;
+  f_impl_ <<
+    autogen_comment() <<
+    endl;
+
+  f_impl_ <<
+    cocoa_imports() <<
+    cocoa_thrift_imports() <<
+    "#import \"" << f_header_name << "\"" << endl <<
+    endl;
 
-  f_impl_ << cocoa_imports() << cocoa_thrift_imports() << "#import \"" << f_header_name << "\""
-          << endl << endl;
 }
 
 /**
@@ -246,7 +269,10 @@ void t_cocoa_generator::init_generator() {
  * @return List of imports for Cocoa libraries
  */
 string t_cocoa_generator::cocoa_imports() {
-  return string() + "#import <Foundation/Foundation.h>\n" + "\n";
+  return
+    string() +
+    "#import <Foundation/Foundation.h>\n" +
+    "\n";
 }
 
 /**
@@ -255,10 +281,15 @@ string t_cocoa_generator::cocoa_imports() {
  * @return List of imports necessary for thrift runtime
  */
 string t_cocoa_generator::cocoa_thrift_imports() {
-  string result = string() + "#import \"TProtocol.h\"\n" + "#import \"TApplicationException.h\"\n"
-                  + "#import \"TProtocolException.h\"\n" + "#import \"TProtocolUtil.h\"\n"
-                  + "#import \"TProcessor.h\"\n" + "#import \"TObjective-C.h\"\n"
-                  + "#import \"TBase.h\"\n" + "\n";
+  string result = string() +
+    "#import \"TProtocol.h\"\n" +
+    "#import \"TApplicationException.h\"\n" +
+    "#import \"TProtocolException.h\"\n" +
+    "#import \"TProtocolUtil.h\"\n" +
+    "#import \"TProcessor.h\"\n" +
+    "#import \"TObjective-C.h\"\n" +
+    "#import \"TBase.h\"\n" +
+    "\n";
 
   // Include other Thrift includes
   const vector<t_program*>& includes = program_->get_includes();
@@ -270,10 +301,12 @@ string t_cocoa_generator::cocoa_thrift_imports() {
   return result;
 }
 
+
 /**
  * Finish up generation.
  */
-void t_cocoa_generator::close_generator() {
+void t_cocoa_generator::close_generator()
+{
   // stick our constants declarations at the end of the header file
   // since they refer to things we are defining.
   f_header_ << constants_declarations_ << endl;
@@ -285,8 +318,9 @@ void t_cocoa_generator::close_generator() {
  * @param ttypedef The type definition
  */
 void t_cocoa_generator::generate_typedef(t_typedef* ttypedef) {
-  f_header_ << indent() << "typedef " << type_name(ttypedef->get_type()) << " " << cocoa_prefix_
-            << ttypedef->get_symbolic() << ";" << endl << endl;
+  f_header_ <<
+    indent() << "typedef " << type_name(ttypedef->get_type()) << " " << cocoa_prefix_ << ttypedef->get_symbolic() << ";" << endl <<
+    endl;
 }
 
 /**
@@ -298,7 +332,8 @@ void t_cocoa_generator::generate_typedef(t_typedef* ttypedef) {
  * @param tenum The enumeration
  */
 void t_cocoa_generator::generate_enum(t_enum* tenum) {
-  f_header_ << indent() << "enum " << cocoa_prefix_ << tenum->get_name() << " {" << endl;
+  f_header_ <<
+    indent() << "enum " << cocoa_prefix_ << tenum->get_name() << " {" << endl;
   indent_up();
 
   vector<t_enum_value*> constants = tenum->get_constants();
@@ -308,14 +343,20 @@ void t_cocoa_generator::generate_enum(t_enum* tenum) {
     if (first) {
       first = false;
     } else {
-      f_header_ << "," << endl;
+      f_header_ <<
+        "," << endl;
     }
-    f_header_ << indent() << tenum->get_name() << "_" << (*c_iter)->get_name();
-    f_header_ << " = " << (*c_iter)->get_value();
+    f_header_ <<
+      indent() << tenum->get_name() << "_" << (*c_iter)->get_name();
+    f_header_ <<
+      " = " << (*c_iter)->get_value();
   }
 
   indent_down();
-  f_header_ << endl << "};" << endl << endl;
+  f_header_ <<
+    endl <<
+    "};" << endl <<
+    endl;
 }
 
 /**
@@ -336,7 +377,8 @@ void t_cocoa_generator::generate_consts(std::vector<t_const*> consts) {
   for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
     string name = (*c_iter)->get_name();
     t_type* type = (*c_iter)->get_type();
-    const_interface << "+ (" << type_name(type) << ") " << name << ";" << endl;
+    const_interface <<
+      "+ (" << type_name(type) << ") " << name << ";" << endl;
   }
 
   const_interface << "@end";
@@ -348,7 +390,8 @@ void t_cocoa_generator::generate_consts(std::vector<t_const*> consts) {
   for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
     string name = (*c_iter)->get_name();
     t_type* type = (*c_iter)->get_type();
-    f_impl_ << "static " << type_name(type) << " " << cocoa_prefix_ << name;
+    f_impl_ <<
+      "static " << type_name(type) << " " << cocoa_prefix_ << name;
     if (!type->is_container() && !type->is_struct()) {
       f_impl_ << " = " << render_const_value(f_impl_, type, (*c_iter)->get_value());
     }
@@ -363,13 +406,13 @@ void t_cocoa_generator::generate_consts(std::vector<t_const*> consts) {
   scope_up(f_impl_);
 
   for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
-    if ((*c_iter)->get_type()->is_container() || (*c_iter)->get_type()->is_struct()) {
+    if ((*c_iter)->get_type()->is_container() ||
+        (*c_iter)->get_type()->is_struct()) {
       print_const_value(f_impl_,
-                        cocoa_prefix_ + (*c_iter)->get_name(),
-                        (*c_iter)->get_type(),
-                        (*c_iter)->get_value(),
-                        false,
-                        false);
+           cocoa_prefix_+(*c_iter)->get_name(),
+           (*c_iter)->get_type(),
+           (*c_iter)->get_value(),
+           false, false);
       f_impl_ << ";" << endl;
     }
   }
@@ -379,7 +422,8 @@ void t_cocoa_generator::generate_consts(std::vector<t_const*> consts) {
   for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
     string name = (*c_iter)->get_name();
     t_type* type = (*c_iter)->get_type();
-    f_impl_ << "+ (" << type_name(type) << ") " << name;
+    f_impl_ <<
+      "+ (" << type_name(type) << ") " << name;
     scope_up(f_impl_);
     indent(f_impl_) << "return " << cocoa_prefix_ << name << ";" << endl;
     scope_down(f_impl_);
@@ -388,6 +432,7 @@ void t_cocoa_generator::generate_consts(std::vector<t_const*> consts) {
   f_impl_ << "@end" << endl << endl;
 }
 
+
 /**
  * Generates a struct definition for a thrift data type. This is a class
  * with protected data members, read(), write(), and getters and setters.
@@ -409,14 +454,15 @@ void t_cocoa_generator::generate_xception(t_struct* txception) {
   generate_cocoa_struct_implementation(f_impl_, txception, true);
 }
 
+
 /**
  * Generate the interface for a struct
  *
  * @param tstruct The struct definition
  */
-void t_cocoa_generator::generate_cocoa_struct_interface(ofstream& out,
-                                                        t_struct* tstruct,
-                                                        bool is_exception) {
+void t_cocoa_generator::generate_cocoa_struct_interface(ofstream &out,
+                                                      t_struct* tstruct,
+                                                      bool is_exception) {
   out << "@interface " << cocoa_prefix_ << tstruct->get_name() << " : ";
 
   if (is_exception) {
@@ -443,7 +489,8 @@ void t_cocoa_generator::generate_cocoa_struct_interface(ofstream& out,
     out << endl;
     // isset fields
     for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
-      indent(out) << "BOOL __" << (*m_iter)->get_name() << "_isset;" << endl;
+      indent(out) <<
+        "BOOL __" << (*m_iter)->get_name() << "_isset;" <<  endl;
     }
   }
 
@@ -452,8 +499,7 @@ void t_cocoa_generator::generate_cocoa_struct_interface(ofstream& out,
 
   // properties
   if (members.size() > 0) {
-    out << "#if TARGET_OS_IPHONE || (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)"
-        << endl;
+    out << "#if TARGET_OS_IPHONE || (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)" << endl;
     for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
       out << indent() << declare_property(*m_iter) << endl;
     }
@@ -484,22 +530,24 @@ void t_cocoa_generator::generate_cocoa_struct_interface(ofstream& out,
   out << "@end" << endl << endl;
 }
 
+
 /**
  * Generate signature for initializer of struct with a parameter for
  * each field.
  */
-void t_cocoa_generator::generate_cocoa_struct_initializer_signature(ofstream& out,
-                                                                    t_struct* tstruct) {
+void t_cocoa_generator::generate_cocoa_struct_initializer_signature(ofstream &out,
+                                                                  t_struct* tstruct) {
   const vector<t_field*>& members = tstruct->get_members();
   vector<t_field*>::const_iterator m_iter;
   indent(out) << "- (id) initWith";
-  for (m_iter = members.begin(); m_iter != members.end();) {
+  for (m_iter = members.begin(); m_iter != members.end(); ) {
     if (m_iter == members.begin()) {
       out << capitalize((*m_iter)->get_name());
     } else {
       out << (*m_iter)->get_name();
     }
-    out << ": (" << type_name((*m_iter)->get_type()) << ") " << (*m_iter)->get_name();
+    out << ": (" << type_name((*m_iter)->get_type()) << ") " <<
+      (*m_iter)->get_name();
     ++m_iter;
     if (m_iter != members.end()) {
       out << " ";
@@ -511,30 +559,31 @@ void t_cocoa_generator::generate_cocoa_struct_initializer_signature(ofstream& ou
  * Generate getter and setter declarations for all fields, plus an
  * IsSet getter.
  */
-void t_cocoa_generator::generate_cocoa_struct_field_accessor_declarations(ofstream& out,
+void t_cocoa_generator::generate_cocoa_struct_field_accessor_declarations(ofstream &out,
                                                                           t_struct* tstruct,
                                                                           bool is_exception) {
-  (void)is_exception;
+  (void) is_exception;
   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) {
     out << indent() << "#if !__has_feature(objc_arc)" << endl;
-    out << indent() << "- (" << type_name((*m_iter)->get_type()) << ") "
-        << decapitalize((*m_iter)->get_name()) << ";" << endl;
-    out << indent() << "- (void) set" << capitalize((*m_iter)->get_name()) << ": ("
-        << type_name((*m_iter)->get_type()) << ") " << (*m_iter)->get_name() << ";" << endl;
+    out << indent() << "- (" << type_name((*m_iter)->get_type()) << ") " << decapitalize((*m_iter)->get_name()) << ";" << endl;
+    out << indent() << "- (void) set" << capitalize((*m_iter)->get_name()) <<
+      ": (" << type_name((*m_iter)->get_type()) << ") " << (*m_iter)->get_name() << ";" << endl;
     out << indent() << "#endif" << endl;
     out << indent() << "- (BOOL) " << (*m_iter)->get_name() << "IsSet;" << endl << endl;
   }
 }
 
+
 /**
  * Generate the initWithCoder method for this struct so it's compatible with
  * the NSCoding protocol
  */
-void t_cocoa_generator::generate_cocoa_struct_init_with_coder_method(ofstream& out,
+void t_cocoa_generator::generate_cocoa_struct_init_with_coder_method(ofstream &out,
                                                                      t_struct* tstruct,
-                                                                     bool is_exception) {
+                                                                     bool is_exception)
+{
   indent(out) << "- (id) initWithCoder: (NSCoder *) decoder" << endl;
   scope_up(out);
   if (is_exception) {
@@ -549,39 +598,42 @@ void t_cocoa_generator::generate_cocoa_struct_init_with_coder_method(ofstream& o
 
   for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
     t_type* t = get_true_type((*m_iter)->get_type());
-    out << indent() << "if ([decoder containsValueForKey: @\"" << (*m_iter)->get_name() << "\"])"
-        << endl;
+    out << indent() << "if ([decoder containsValueForKey: @\""<< (*m_iter)->get_name() <<"\"])" << endl;
     scope_up(out);
     out << indent() << "__" << (*m_iter)->get_name() << " = ";
-    if (type_can_be_null(t)) {
-      out << "[[decoder decodeObjectForKey: @\"" << (*m_iter)->get_name() << "\"] retain_stub];"
-          << endl;
-    } else if (t->is_enum()) {
+    if (type_can_be_null(t))
+    {
+      out << "[[decoder decodeObjectForKey: @\"" << (*m_iter)->get_name() << "\"] retain_stub];" << endl;
+    }
+    else if (t->is_enum())
+    {
       out << "[decoder decodeIntForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
-    } else {
-      t_base_type::t_base tbase = ((t_base_type*)t)->get_base();
-      switch (tbase) {
-      case t_base_type::TYPE_BOOL:
-        out << "[decoder decodeBoolForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
-        break;
-      case t_base_type::TYPE_BYTE:
-        out << "[decoder decodeIntForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
-        break;
-      case t_base_type::TYPE_I16:
-        out << "[decoder decodeIntForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
-        break;
-      case t_base_type::TYPE_I32:
-        out << "[decoder decodeInt32ForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
-        break;
-      case t_base_type::TYPE_I64:
-        out << "[decoder decodeInt64ForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
-        break;
-      case t_base_type::TYPE_DOUBLE:
-        out << "[decoder decodeDoubleForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
-        break;
-      default:
-        throw "compiler error: don't know how to decode thrift type: "
-            + t_base_type::t_base_name(tbase);
+    }
+    else
+    {
+      t_base_type::t_base tbase = ((t_base_type *) t)->get_base();
+      switch (tbase)
+      {
+        case t_base_type::TYPE_BOOL:
+          out << "[decoder decodeBoolForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
+          break;
+        case t_base_type::TYPE_BYTE:
+          out << "[decoder decodeIntForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
+          break;
+        case t_base_type::TYPE_I16:
+          out << "[decoder decodeIntForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
+          break;
+        case t_base_type::TYPE_I32:
+          out << "[decoder decodeInt32ForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
+          break;
+        case t_base_type::TYPE_I64:
+          out << "[decoder decodeInt64ForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
+          break;
+        case t_base_type::TYPE_DOUBLE:
+          out << "[decoder decodeDoubleForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
+          break;
+        default:
+          throw "compiler error: don't know how to decode thrift type: " + t_base_type::t_base_name(tbase);
       }
     }
     out << indent() << "__" << (*m_iter)->get_name() << "_isset = YES;" << endl;
@@ -593,13 +645,15 @@ void t_cocoa_generator::generate_cocoa_struct_init_with_coder_method(ofstream& o
   out << endl;
 }
 
+
 /**
  * Generate the encodeWithCoder method for this struct so it's compatible with
  * the NSCoding protocol
  */
-void t_cocoa_generator::generate_cocoa_struct_encode_with_coder_method(ofstream& out,
+void t_cocoa_generator::generate_cocoa_struct_encode_with_coder_method(ofstream &out,
                                                                        t_struct* tstruct,
-                                                                       bool is_exception) {
+                                                                       bool is_exception)
+{
   indent(out) << "- (void) encodeWithCoder: (NSCoder *) encoder" << endl;
   scope_up(out);
   if (is_exception) {
@@ -612,45 +666,42 @@ void t_cocoa_generator::generate_cocoa_struct_encode_with_coder_method(ofstream&
 
   for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
     t_type* t = get_true_type((*m_iter)->get_type());
-    out << indent() << "if (__" << (*m_iter)->get_name() << "_isset)" << endl;
+    out << indent() << "if (__"<< (*m_iter)->get_name() <<"_isset)" << endl;
     scope_up(out);
-    // out << indent() << "__" << (*m_iter)->get_name() << " = ";
-    if (type_can_be_null(t)) {
-      out << indent() << "[encoder encodeObject: __" << (*m_iter)->get_name() << " forKey: @\""
-          << (*m_iter)->get_name() << "\"];" << endl;
-    } else if (t->is_enum()) {
-      out << indent() << "[encoder encodeInt: __" << (*m_iter)->get_name() << " forKey: @\""
-          << (*m_iter)->get_name() << "\"];" << endl;
-    } else {
-      t_base_type::t_base tbase = ((t_base_type*)t)->get_base();
-      switch (tbase) {
-      case t_base_type::TYPE_BOOL:
-        out << indent() << "[encoder encodeBool: __" << (*m_iter)->get_name() << " forKey: @\""
-            << (*m_iter)->get_name() << "\"];" << endl;
-        break;
-      case t_base_type::TYPE_BYTE:
-        out << indent() << "[encoder encodeInt: __" << (*m_iter)->get_name() << " forKey: @\""
-            << (*m_iter)->get_name() << "\"];" << endl;
-        break;
-      case t_base_type::TYPE_I16:
-        out << indent() << "[encoder encodeInt: __" << (*m_iter)->get_name() << " forKey: @\""
-            << (*m_iter)->get_name() << "\"];" << endl;
-        break;
-      case t_base_type::TYPE_I32:
-        out << indent() << "[encoder encodeInt32: __" << (*m_iter)->get_name() << " forKey: @\""
-            << (*m_iter)->get_name() << "\"];" << endl;
-        break;
-      case t_base_type::TYPE_I64:
-        out << indent() << "[encoder encodeInt64: __" << (*m_iter)->get_name() << " forKey: @\""
-            << (*m_iter)->get_name() << "\"];" << endl;
-        break;
-      case t_base_type::TYPE_DOUBLE:
-        out << indent() << "[encoder encodeDouble: __" << (*m_iter)->get_name() << " forKey: @\""
-            << (*m_iter)->get_name() << "\"];" << endl;
-        break;
-      default:
-        throw "compiler error: don't know how to encode thrift type: "
-            + t_base_type::t_base_name(tbase);
+    //out << indent() << "__" << (*m_iter)->get_name() << " = ";
+    if (type_can_be_null(t))
+    {
+      out << indent() << "[encoder encodeObject: __" << (*m_iter)->get_name() << " forKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
+    }
+    else if (t->is_enum())
+    {
+      out << indent() << "[encoder encodeInt: __" << (*m_iter)->get_name() << " forKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
+    }
+    else
+    {
+      t_base_type::t_base tbase = ((t_base_type *) t)->get_base();
+      switch (tbase)
+      {
+        case t_base_type::TYPE_BOOL:
+          out << indent() << "[encoder encodeBool: __" << (*m_iter)->get_name() << " forKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
+          break;
+        case t_base_type::TYPE_BYTE:
+          out << indent() << "[encoder encodeInt: __" << (*m_iter)->get_name() << " forKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
+          break;
+        case t_base_type::TYPE_I16:
+          out << indent() << "[encoder encodeInt: __" << (*m_iter)->get_name() << " forKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
+          break;
+        case t_base_type::TYPE_I32:
+          out << indent() << "[encoder encodeInt32: __" << (*m_iter)->get_name() << " forKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
+          break;
+        case t_base_type::TYPE_I64:
+          out << indent() << "[encoder encodeInt64: __" << (*m_iter)->get_name() << " forKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
+          break;
+        case t_base_type::TYPE_DOUBLE:
+          out << indent() << "[encoder encodeDouble: __" << (*m_iter)->get_name() << " forKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
+          break;
+        default:
+          throw "compiler error: don't know how to encode thrift type: " + t_base_type::t_base_name(tbase);
       }
     }
     scope_down(out);
@@ -660,6 +711,7 @@ void t_cocoa_generator::generate_cocoa_struct_encode_with_coder_method(ofstream&
   out << endl;
 }
 
+
 /**
  * Generate struct implementation.
  *
@@ -667,11 +719,12 @@ void t_cocoa_generator::generate_cocoa_struct_encode_with_coder_method(ofstream&
  * @param is_exception Is this an exception?
  * @param is_result    If this is a result it needs a different writer
  */
-void t_cocoa_generator::generate_cocoa_struct_implementation(ofstream& out,
+void t_cocoa_generator::generate_cocoa_struct_implementation(ofstream &out,
                                                              t_struct* tstruct,
                                                              bool is_exception,
                                                              bool is_result) {
-  indent(out) << "@implementation " << cocoa_prefix_ << tstruct->get_name() << endl << endl;
+  indent(out) <<
+    "@implementation " << cocoa_prefix_ << tstruct->get_name() << endl << endl;
 
   const vector<t_field*>& members = tstruct->get_members();
   vector<t_field*>::const_iterator m_iter;
@@ -680,8 +733,8 @@ void t_cocoa_generator::generate_cocoa_struct_implementation(ofstream& out,
   if (is_exception) {
     out << indent() << "- (id) init" << endl;
     scope_up(out);
-    out << indent() << "return [super initWithName: @\"" << cocoa_prefix_ << tstruct->get_name()
-        << "\" reason: @\"unknown\" userInfo: nil];" << endl;
+    out << indent() << "return [super initWithName: @\"" << cocoa_prefix_ << tstruct->get_name() <<
+        "\" reason: @\"unknown\" userInfo: nil];" << endl;
     scope_down(out);
     out << endl;
   } else {
@@ -693,17 +746,11 @@ void t_cocoa_generator::generate_cocoa_struct_implementation(ofstream& out,
     scope_up(out);
     indent(out) << "self = [super init];" << endl;
     if (members.size() > 0) {
-      out << "#if TARGET_OS_IPHONE || (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)"
-          << endl;
+      out << "#if TARGET_OS_IPHONE || (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)" << endl;
       for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
         t_type* t = get_true_type((*m_iter)->get_type());
         if ((*m_iter)->get_value() != NULL) {
-          print_const_value(out,
-                            "self." + (*m_iter)->get_name(),
-                            t,
-                            (*m_iter)->get_value(),
-                            false,
-                            true);
+          print_const_value(out, "self."+(*m_iter)->get_name(), t, (*m_iter)->get_value(), false, true);
         }
       }
       out << "#endif" << endl;
@@ -776,13 +823,16 @@ void t_cocoa_generator::generate_cocoa_struct_implementation(ofstream& out,
   out << "@end" << endl << endl;
 }
 
+
 /**
  * Generates a function to read all the fields of the struct.
  *
  * @param tstruct The struct definition
  */
-void t_cocoa_generator::generate_cocoa_struct_reader(ofstream& out, t_struct* tstruct) {
-  out << "- (void) read: (id <TProtocol>) inProtocol" << endl;
+void t_cocoa_generator::generate_cocoa_struct_reader(ofstream& out,
+                                                     t_struct* tstruct) {
+  out <<
+    "- (void) read: (id <TProtocol>) inProtocol" << endl;
   scope_up(out);
 
   const vector<t_field*>& fields = tstruct->get_members();
@@ -797,80 +847,90 @@ void t_cocoa_generator::generate_cocoa_struct_reader(ofstream& out, t_struct* ts
   indent(out) << "[inProtocol readStructBeginReturningName: NULL];" << 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)
-      << "[inProtocol readFieldBeginReturningName: &fieldName type: &fieldType fieldID: &fieldID];"
-      << endl;
+    // Read beginning field marker
+    indent(out) <<
+      "[inProtocol readFieldBeginReturningName: &fieldName type: &fieldType fieldID: &fieldID];" << endl;
 
-  // Check for field STOP marker and break
-  indent(out) << "if (fieldType == TType_STOP) { " << endl;
-  indent_up();
-  indent(out) << "break;" << endl;
-  indent_down();
-  indent(out) << "}" << endl;
+    // Check for field STOP marker and break
+    indent(out) <<
+      "if (fieldType == 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 (fieldID)" << endl;
+    // Switch statement on the field we are reading
+    indent(out) <<
+      "switch (fieldID)" << 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 " << (*f_iter)->get_key() << ":" << endl;
-    indent_up();
-    indent(out) << "if (fieldType == " << 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 " << (*f_iter)->get_key() << ":" << endl;
+        indent_up();
+        indent(out) <<
+          "if (fieldType == " << type_to_enum((*f_iter)->get_type()) << ") {" << endl;
+        indent_up();
+
+        generate_deserialize_field(out, *f_iter, "fieldValue");
+        indent(out) << call_field_setter(*f_iter, "fieldValue") << endl;
+        // if this is an allocated field, release it since the struct
+        // is now retaining it
+        if (type_can_be_null((*f_iter)->get_type())) {
+          // deserialized strings are autorelease, so don't release them
+          if (!(get_true_type((*f_iter)->get_type())->is_string())) {
+            indent(out) << "[fieldValue release_stub];" << endl;
+          }
+        }
 
-    generate_deserialize_field(out, *f_iter, "fieldValue");
-    indent(out) << call_field_setter(*f_iter, "fieldValue") << endl;
-    // if this is an allocated field, release it since the struct
-    // is now retaining it
-    if (type_can_be_null((*f_iter)->get_type())) {
-      // deserialized strings are autorelease, so don't release them
-      if (!(get_true_type((*f_iter)->get_type())->is_string())) {
-        indent(out) << "[fieldValue release_stub];" << endl;
+        indent_down();
+        out << indent() << "} else { " << endl;
+        if (log_unexpected_) {
+          out << indent() << "  NSLog(@\"%s: field ID %i has unexpected type %i.  Skipping.\", __PRETTY_FUNCTION__, fieldID, fieldType);" << endl;
+        }
+        out << indent() << "  [TProtocolUtil skipType: fieldType onProtocol: inProtocol];" << endl <<
+          indent() << "}" << endl <<
+          indent() << "break;" << endl;
+        indent_down();
       }
-    }
 
-    indent_down();
-    out << indent() << "} else { " << endl;
-    if (log_unexpected_) {
-      out << indent() << "  NSLog(@\"%s: field ID %i has unexpected type %i.  Skipping.\", "
-                         "__PRETTY_FUNCTION__, fieldID, fieldType);" << endl;
-    }
-    out << indent() << "  [TProtocolUtil skipType: fieldType onProtocol: inProtocol];" << endl
-        << indent() << "}" << endl << indent() << "break;" << endl;
-    indent_down();
-  }
-
-  // In the default case we skip the field
-  out << indent() << "default:" << endl;
-  if (log_unexpected_) {
-    out << indent() << "  NSLog(@\"%s: unexpected field ID %i with type %i.  Skipping.\", "
-                       "__PRETTY_FUNCTION__, fieldID, fieldType);" << endl;
-  }
-  out << indent() << "  [TProtocolUtil skipType: fieldType onProtocol: inProtocol];" << endl
-      << indent() << "  break;" << endl;
+      // In the default case we skip the field
+      out << indent() << "default:" << endl;
+      if (log_unexpected_) {
+        out << indent() << "  NSLog(@\"%s: unexpected field ID %i with type %i.  Skipping.\", __PRETTY_FUNCTION__, fieldID, fieldType);" << endl;
+      }
+      out << indent() << "  [TProtocolUtil skipType: fieldType onProtocol: inProtocol];" << endl <<
+        indent() << "  break;" << endl;
 
-  scope_down(out);
+      scope_down(out);
 
-  // Read field end marker
-  indent(out) << "[inProtocol readFieldEnd];" << endl;
+    // Read field end marker
+    indent(out) <<
+      "[inProtocol readFieldEnd];" << endl;
 
-  scope_down(out);
+    scope_down(out);
 
-  out << indent() << "[inProtocol readStructEnd];" << endl;
+    out <<
+      indent() << "[inProtocol readStructEnd];" << endl;
 
-  // performs various checks (e.g. check that all required fields are set)
-  if (validate_required_) {
-    out << indent() << "[self validate];" << endl;
-  }
+    // performs various checks (e.g. check that all required fields are set)
+    if (validate_required_) {
+      out <<
+        indent() << "[self validate];" << endl;
+    }
 
   indent_down();
-  out << indent() << "}" << endl << endl;
+  out <<
+    indent() << "}" << endl <<
+    endl;
 }
 
 /**
@@ -878,34 +938,40 @@ void t_cocoa_generator::generate_cocoa_struct_reader(ofstream& out, t_struct* ts
  *
  * @param tstruct The struct definition
  */
-void t_cocoa_generator::generate_cocoa_struct_writer(ofstream& out, t_struct* tstruct) {
-  out << indent() << "- (void) write: (id <TProtocol>) outProtocol {" << endl;
+void t_cocoa_generator::generate_cocoa_struct_writer(ofstream& out,
+                                                     t_struct* tstruct) {
+  out <<
+    indent() << "- (void) write: (id <TProtocol>) outProtocol {" << endl;
   indent_up();
 
   string name = tstruct->get_name();
   const vector<t_field*>& fields = tstruct->get_members();
   vector<t_field*>::const_iterator f_iter;
 
-  out << indent() << "[outProtocol writeStructBeginWithName: @\"" << name << "\"];" << endl;
+  out <<
+    indent() << "[outProtocol writeStructBeginWithName: @\"" << name << "\"];" << endl;
 
   for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
-    out << indent() << "if (__" << (*f_iter)->get_name() << "_isset) {" << endl;
+    out <<
+      indent() << "if (__" << (*f_iter)->get_name() << "_isset) {" << endl;
     indent_up();
     bool null_allowed = type_can_be_null((*f_iter)->get_type());
     if (null_allowed) {
-      out << indent() << "if (__" << (*f_iter)->get_name() << " != nil) {" << endl;
+      out <<
+        indent() << "if (__" << (*f_iter)->get_name() << " != nil) {" << endl;
       indent_up();
     }
 
-    indent(out) << "[outProtocol writeFieldBeginWithName: @\"" << (*f_iter)->get_name()
-                << "\" type: " << type_to_enum((*f_iter)->get_type())
-                << " fieldID: " << (*f_iter)->get_key() << "];" << endl;
+    indent(out) << "[outProtocol writeFieldBeginWithName: @\"" <<
+      (*f_iter)->get_name() << "\" type: " << type_to_enum((*f_iter)->get_type()) <<
+      " fieldID: " << (*f_iter)->get_key() << "];" << endl;
 
     // Write field contents
-    generate_serialize_field(out, *f_iter, "__" + (*f_iter)->get_name());
+    generate_serialize_field(out, *f_iter, "__"+(*f_iter)->get_name());
 
     // Write field closer
-    indent(out) << "[outProtocol writeFieldEnd];" << endl;
+    indent(out) <<
+      "[outProtocol writeFieldEnd];" << endl;
 
     if (null_allowed) {
       scope_down(out);
@@ -913,11 +979,14 @@ void t_cocoa_generator::generate_cocoa_struct_writer(ofstream& out, t_struct* ts
     scope_down(out);
   }
   // Write the struct map
-  out << indent() << "[outProtocol writeFieldStop];" << endl << indent()
-      << "[outProtocol writeStructEnd];" << endl;
+  out <<
+    indent() << "[outProtocol writeFieldStop];" << endl <<
+    indent() << "[outProtocol writeStructEnd];" << endl;
 
   indent_down();
-  out << indent() << "}" << endl << endl;
+  out <<
+    indent() << "}" << endl <<
+    endl;
 }
 
 /**
@@ -927,43 +996,52 @@ void t_cocoa_generator::generate_cocoa_struct_writer(ofstream& out, t_struct* ts
  *
  * @param tstruct The struct definition
  */
-void t_cocoa_generator::generate_cocoa_struct_result_writer(ofstream& out, t_struct* tstruct) {
-  out << indent() << "- (void) write: (id <TProtocol>) outProtocol {" << endl;
+void t_cocoa_generator::generate_cocoa_struct_result_writer(ofstream& out,
+                                                            t_struct* tstruct) {
+  out <<
+    indent() << "- (void) write: (id <TProtocol>) outProtocol {" << endl;
   indent_up();
 
   string name = tstruct->get_name();
   const vector<t_field*>& fields = tstruct->get_members();
   vector<t_field*>::const_iterator f_iter;
 
-  out << indent() << "[outProtocol writeStructBeginWithName: @\"" << name << "\"];" << endl;
+  out <<
+    indent() << "[outProtocol writeStructBeginWithName: @\"" << name << "\"];" << endl;
 
   bool first = true;
   for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
     if (first) {
       first = false;
-      out << endl << indent() << "if ";
+      out <<
+        endl <<
+        indent() << "if ";
     } else {
-      out << " else if ";
+      out <<
+        " else if ";
     }
 
-    out << "(__" << (*f_iter)->get_name() << "_isset) {" << endl;
+    out <<
+      "(__" << (*f_iter)->get_name() << "_isset) {" << endl;
     indent_up();
 
     bool null_allowed = type_can_be_null((*f_iter)->get_type());
     if (null_allowed) {
-      out << indent() << "if (__" << (*f_iter)->get_name() << " != nil) {" << endl;
+      out <<
+        indent() << "if (__" << (*f_iter)->get_name() << " != nil) {" << endl;
       indent_up();
     }
 
-    indent(out) << "[outProtocol writeFieldBeginWithName: @\"" << (*f_iter)->get_name()
-                << "\" type: " << type_to_enum((*f_iter)->get_type())
-                << " fieldID: " << (*f_iter)->get_key() << "];" << endl;
+    indent(out) << "[outProtocol writeFieldBeginWithName: @\"" <<
+      (*f_iter)->get_name() << "\" type: " << type_to_enum((*f_iter)->get_type()) <<
+      " fieldID: " << (*f_iter)->get_key() << "];" << endl;
 
     // Write field contents
-    generate_serialize_field(out, *f_iter, "__" + (*f_iter)->get_name());
+    generate_serialize_field(out, *f_iter, "__"+(*f_iter)->get_name());
 
     // Write field closer
-    indent(out) << "[outProtocol writeFieldEnd];" << endl;
+    indent(out) <<
+      "[outProtocol writeFieldEnd];" << endl;
 
     if (null_allowed) {
       indent_down();
@@ -974,11 +1052,15 @@ void t_cocoa_generator::generate_cocoa_struct_result_writer(ofstream& out, t_str
     indent(out) << "}";
   }
   // Write the struct map
-  out << endl << indent() << "[outProtocol writeFieldStop];" << endl << indent()
-      << "[outProtocol writeStructEnd];" << endl;
+  out <<
+    endl <<
+    indent() << "[outProtocol writeFieldStop];" << endl <<
+    indent() << "[outProtocol writeStructEnd];" << endl;
 
   indent_down();
-  out << indent() << "}" << endl << endl;
+  out <<
+    indent() << "}" << endl <<
+    endl;
 }
 
 /**
@@ -987,8 +1069,10 @@ void t_cocoa_generator::generate_cocoa_struct_result_writer(ofstream& out, t_str
  *
  * @param tstruct The struct definition
  */
-void t_cocoa_generator::generate_cocoa_struct_validator(ofstream& out, t_struct* tstruct) {
-  out << indent() << "- (void) validate {" << endl;
+void t_cocoa_generator::generate_cocoa_struct_validator(ofstream& out,
+                                                        t_struct* tstruct) {
+  out <<
+    indent() << "- (void) validate {" << endl;
   indent_up();
 
   const vector<t_field*>& fields = tstruct->get_members();
@@ -998,15 +1082,18 @@ void t_cocoa_generator::generate_cocoa_struct_validator(ofstream& out, t_struct*
   for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
     t_field* field = (*f_iter);
     if ((*f_iter)->get_req() == t_field::T_REQUIRED) {
-      out << indent() << "if (!__" << field->get_name() << "_isset) {" << endl << indent()
-          << "  @throw [TProtocolException exceptionWithName: @\"TProtocolException\"" << endl
-          << indent() << "                             reason: @\"Required field '"
-          << (*f_iter)->get_name() << "' is not set.\"];" << endl << indent() << "}" << endl;
+      out <<
+        indent() << "if (!__" << field->get_name() << "_isset) {" << endl <<
+        indent() << "  @throw [TProtocolException exceptionWithName: @\"TProtocolException\"" << endl <<
+        indent() << "                             reason: @\"Required field '" << (*f_iter)->get_name() << "' is not set.\"];" << endl <<
+        indent() << "}" << endl;
     }
   }
 
   indent_down();
-  out << indent() << "}" << endl << endl;
+  out <<
+    indent() << "}" << endl <<
+    endl;
 }
 
 /**
@@ -1018,7 +1105,7 @@ void t_cocoa_generator::generate_cocoa_struct_validator(ofstream& out, t_struct*
 void t_cocoa_generator::generate_cocoa_struct_field_accessor_implementations(ofstream& out,
                                                                              t_struct* tstruct,
                                                                              bool is_exception) {
-  (void)is_exception;
+  (void) is_exception;
   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) {
@@ -1041,8 +1128,8 @@ void t_cocoa_generator::generate_cocoa_struct_field_accessor_implementations(ofs
     indent(out) << "}" << endl << endl;
 
     // Simple setter
-    indent(out) << "- (void) set" << cap_name << ": (" << type_name(type) << ") " << field_name
-                << " {" << endl;
+    indent(out) << "- (void) set" << cap_name << ": (" << type_name(type) <<
+      ") " << field_name << " {" << endl;
     indent_up();
     if (!type_can_be_null(type)) {
       indent(out) << "__" << field_name << " = " << field_name << ";" << endl;
@@ -1080,12 +1167,15 @@ void t_cocoa_generator::generate_cocoa_struct_field_accessor_implementations(ofs
  *
  * @param tstruct The struct definition
  */
-void t_cocoa_generator::generate_cocoa_struct_description(ofstream& out, t_struct* tstruct) {
-  out << indent() << "- (NSString *) description {" << endl;
+void t_cocoa_generator::generate_cocoa_struct_description(ofstream& out,
+                                                          t_struct* tstruct) {
+  out <<
+    indent() << "- (NSString *) description {" << endl;
   indent_up();
 
-  out << indent() << "NSMutableString * ms = [NSMutableString stringWithString: @\""
-      << cocoa_prefix_ << tstruct->get_name() << "(\"];" << endl;
+  out <<
+    indent() << "NSMutableString * ms = [NSMutableString stringWithString: @\"" <<
+    cocoa_prefix_ << tstruct->get_name() << "(\"];" << endl;
 
   const vector<t_field*>& fields = tstruct->get_members();
   vector<t_field*>::const_iterator f_iter;
@@ -1098,16 +1188,19 @@ void t_cocoa_generator::generate_cocoa_struct_description(ofstream& out, t_struc
       indent(out) << "[ms appendString: @\"," << (*f_iter)->get_name() << ":\"];" << endl;
     }
     t_type* ttype = (*f_iter)->get_type();
-    indent(out) << "[ms appendFormat: @\"" << format_string_for_type(ttype) << "\", __"
-                << (*f_iter)->get_name() << "];" << endl;
+    indent(out) << "[ms appendFormat: @\"" << format_string_for_type(ttype) << "\", __" <<
+      (*f_iter)->get_name() << "];" << endl;
   }
-  out << indent() << "[ms appendString: @\")\"];" << endl << indent()
-      << "return [NSString stringWithString: ms];" << endl;
+  out <<
+    indent() << "[ms appendString: @\")\"];" << endl <<
+    indent() << "return [NSString stringWithString: ms];" << endl;
 
   indent_down();
-  indent(out) << "}" << endl << endl;
+  indent(out) << "}" << endl <<
+    endl;
 }
 
+
 /**
  * Generates a thrift service.  In Objective-C this consists of a
  * protocol definition, a client interface and a client implementation.
@@ -1123,6 +1216,7 @@ void t_cocoa_generator::generate_service(t_service* tservice) {
   generate_cocoa_service_server_implementation(f_impl_, tservice);
 }
 
+
 /**
  * Generates structs for all the service return types
  *
@@ -1147,10 +1241,12 @@ string t_cocoa_generator::function_result_helper_struct_type(t_function* tfuncti
   }
 }
 
+
 string t_cocoa_generator::function_args_helper_struct_type(t_function* tfunction) {
   return tfunction->get_name() + "_args";
 }
 
+
 /**
  * Generates a struct and helpers for a function.
  *
@@ -1181,19 +1277,21 @@ void t_cocoa_generator::generate_function_helpers(t_function* tfunction) {
   generate_cocoa_struct_implementation(f_impl_, &result, false, true);
 }
 
+
 /**
  * Generates a service protocol definition.
  *
  * @param tservice The service to generate a protocol definition for
  */
-void t_cocoa_generator::generate_cocoa_service_protocol(ofstream& out, t_service* tservice) {
+void t_cocoa_generator::generate_cocoa_service_protocol(ofstream& out,
+                                                        t_service* tservice) {
   out << "@protocol " << cocoa_prefix_ << tservice->get_name() << " <NSObject>" << endl;
 
   vector<t_function*> functions = tservice->get_functions();
   vector<t_function*>::iterator f_iter;
   for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
-    out << "- " << function_signature(*f_iter) << ";"
-        << "  // throws ";
+    out << "- " << function_signature(*f_iter) << ";" <<
+      "  // throws ";
     t_struct* xs = (*f_iter)->get_xceptions();
     const std::vector<t_field*>& xceptions = xs->get_members();
     vector<t_field*>::const_iterator x_iter;
@@ -1205,6 +1303,7 @@ void t_cocoa_generator::generate_cocoa_service_protocol(ofstream& out, t_service
   out << "@end" << endl << endl;
 }
 
+
 /**
  * Generates a service client interface definition.
  *
@@ -1212,8 +1311,8 @@ void t_cocoa_generator::generate_cocoa_service_protocol(ofstream& out, t_service
  */
 void t_cocoa_generator::generate_cocoa_service_client_interface(ofstream& out,
                                                                 t_service* tservice) {
-  out << "@interface " << cocoa_prefix_ << tservice->get_name() << "Client : NSObject <"
-      << cocoa_prefix_ << tservice->get_name() << "> ";
+  out << "@interface " << cocoa_prefix_ << tservice->get_name() << "Client : NSObject <" <<
+    cocoa_prefix_ << tservice->get_name() << "> ";
 
   scope_up(out);
   out << indent() << "id <TProtocol> inProtocol;" << endl;
@@ -1221,35 +1320,33 @@ void t_cocoa_generator::generate_cocoa_service_client_interface(ofstream& out,
   scope_down(out);
 
   out << "- (id) initWithProtocol: (id <TProtocol>) protocol;" << endl;
-  out << "- (id) initWithInProtocol: (id <TProtocol>) inProtocol outProtocol: (id <TProtocol>) "
-         "outProtocol;" << endl;
+  out << "- (id) initWithInProtocol: (id <TProtocol>) inProtocol outProtocol: (id <TProtocol>) outProtocol;" << endl;
   out << "@end" << endl << endl;
 }
 
+
 /**
- * Generates a service server interface definition. In other words, the TProcess implementation for
- *the
+ * Generates a service server interface definition. In other words, the TProcess implementation for the
  * service definition.
  *
  * @param tservice The service to generate a client interface definition for
  */
 void t_cocoa_generator::generate_cocoa_service_server_interface(ofstream& out,
                                                                 t_service* tservice) {
-  out << "@interface " << cocoa_prefix_ << tservice->get_name()
-      << "Processor : NSObject <TProcessor> ";
+  out << "@interface " << cocoa_prefix_ << tservice->get_name() << "Processor : NSObject <TProcessor> ";
 
   scope_up(out);
-  out << indent() << "id <" << cocoa_prefix_ << tservice->get_name() << "> mService;" << endl;
+  out << indent() << "id <" << cocoa_prefix_ << tservice->get_name() <<"> mService;" << endl;
   out << indent() << "NSDictionary * mMethodMap;" << endl;
   scope_down(out);
 
-  out << "- (id) initWith" << tservice->get_name() << ": (id <" << cocoa_prefix_
-      << tservice->get_name() << ">) service;" << endl;
-  out << "- (id<" << cocoa_prefix_ << tservice->get_name() << ">) service;" << endl;
+  out << "- (id) initWith" << tservice->get_name() << ": (id <" << cocoa_prefix_ << tservice->get_name() << ">) service;" << endl;
+  out << "- (id<"<<cocoa_prefix_ << tservice->get_name() << ">) service;" << endl;
 
   out << "@end" << endl << endl;
 }
 
+
 /**
  * Generates a service client implementation.
  *
@@ -1266,8 +1363,7 @@ void t_cocoa_generator::generate_cocoa_service_client_implementation(ofstream& o
   scope_down(out);
   out << endl;
 
-  out << "- (id) initWithInProtocol: (id <TProtocol>) anInProtocol outProtocol: (id <TProtocol>) "
-         "anOutProtocol" << endl;
+  out << "- (id) initWithInProtocol: (id <TProtocol>) anInProtocol outProtocol: (id <TProtocol>) anOutProtocol" << endl;
   scope_up(out);
   out << indent() << "self = [super init];" << endl;
   out << indent() << "inProtocol = [anInProtocol retain_stub];" << endl;
@@ -1298,15 +1394,18 @@ void t_cocoa_generator::generate_cocoa_service_client_implementation(ofstream& o
     string argsname = (*f_iter)->get_name() + "_args";
 
     // Open function
-    indent(out) << "- " << function_signature(&send_function) << endl;
+    indent(out) <<
+      "- " << function_signature(&send_function) << endl;
     scope_up(out);
 
     // Serialize the request
-    out << indent() << "[outProtocol writeMessageBeginWithName: @\"" << funname << "\""
-        << ((*f_iter)->is_oneway() ? " type: TMessageType_ONEWAY" : " type: TMessageType_CALL")
-        << " sequenceID: 0];" << endl;
+    out <<
+      indent() << "[outProtocol writeMessageBeginWithName: @\"" << funname << "\"" <<
+      ((*f_iter)->is_oneway() ? " type: TMessageType_ONEWAY" : " type: TMessageType_CALL") <<
+      " sequenceID: 0];" << endl;
 
-    out << indent() << "[outProtocol writeStructBeginWithName: @\"" << argsname << "\"];" << endl;
+    out <<
+      indent() << "[outProtocol writeStructBeginWithName: @\"" << argsname << "\"];" << endl;
 
     // write out function parameters
     t_struct* arg_struct = (*f_iter)->get_arglist();
@@ -1318,25 +1417,29 @@ void t_cocoa_generator::generate_cocoa_service_client_implementation(ofstream& o
         out << indent() << "if (" << fieldName << " != nil)";
         scope_up(out);
       }
-      out << indent() << "[outProtocol writeFieldBeginWithName: @\"" << fieldName
-          << "\""
-             " type: " << type_to_enum((*fld_iter)->get_type())
-          << " fieldID: " << (*fld_iter)->get_key() << "];" << endl;
+      out <<
+        indent() << "[outProtocol writeFieldBeginWithName: @\"" << fieldName << "\""
+        " type: " << type_to_enum((*fld_iter)->get_type()) <<
+        " fieldID: " << (*fld_iter)->get_key() << "];" << endl;
 
       generate_serialize_field(out, *fld_iter, fieldName);
 
-      out << indent() << "[outProtocol writeFieldEnd];" << endl;
+      out <<
+        indent() << "[outProtocol writeFieldEnd];" << endl;
 
       if (type_can_be_null((*fld_iter)->get_type())) {
         scope_down(out);
       }
     }
 
-    out << indent() << "[outProtocol writeFieldStop];" << endl;
-    out << indent() << "[outProtocol writeStructEnd];" << endl;
+    out <<
+      indent() << "[outProtocol writeFieldStop];" << endl;
+    out <<
+      indent() << "[outProtocol writeStructEnd];" << endl;
 
-    out << indent() << "[outProtocol writeMessageEnd];" << endl << indent()
-        << "[[outProtocol transport] flush];" << endl;
+    out <<
+      indent() << "[outProtocol writeMessageEnd];" << endl <<
+      indent() << "[[outProtocol transport] flush];" << endl;
 
     scope_down(out);
     out << endl;
@@ -1348,49 +1451,56 @@ void t_cocoa_generator::generate_cocoa_service_client_implementation(ofstream& o
                                &noargs,
                                (*f_iter)->get_xceptions());
       // Open function
-      indent(out) << "- " << function_signature(&recv_function) << endl;
+      indent(out) <<
+        "- " << function_signature(&recv_function) << endl;
       scope_up(out);
 
       // TODO(mcslee): Message validation here, was the seqid etc ok?
 
       // check for an exception
-      out << indent() << "int msgType = 0;" << endl << indent()
-          << "[inProtocol readMessageBeginReturningName: nil type: &msgType sequenceID: NULL];"
-          << endl << indent() << "if (msgType == TMessageType_EXCEPTION) {" << endl << indent()
-          << "  TApplicationException * x = [TApplicationException read: inProtocol];" << endl
-          << indent() << "  [inProtocol readMessageEnd];" << endl << indent() << "  @throw x;"
-          << endl << indent() << "}" << endl;
+      out <<
+        indent() << "int msgType = 0;" << endl <<
+        indent() << "[inProtocol readMessageBeginReturningName: nil type: &msgType sequenceID: NULL];" << endl <<
+        indent() << "if (msgType == TMessageType_EXCEPTION) {" << endl <<
+        indent() << "  TApplicationException * x = [TApplicationException read: inProtocol];" << endl <<
+        indent() << "  [inProtocol readMessageEnd];" << endl <<
+        indent() << "  @throw x;" << endl <<
+        indent() << "}" << endl;
 
       // FIXME - could optimize here to reduce creation of temporary objects.
       string resultname = function_result_helper_struct_type(*f_iter);
-      out << indent() << cocoa_prefix_ << resultname << " * result = [[[" << cocoa_prefix_
-          << resultname << " alloc] init] autorelease_stub];" << endl;
+      out <<
+        indent() << cocoa_prefix_ << resultname << " * result = [[[" << cocoa_prefix_ <<
+        resultname << " alloc] init] autorelease_stub];" << endl;
       indent(out) << "[result read: inProtocol];" << endl;
       indent(out) << "[inProtocol readMessageEnd];" << endl;
 
       // Careful, only return _result if not a void function
       if (!(*f_iter)->get_returntype()->is_void()) {
-        out << indent() << "if ([result successIsSet]) {" << endl << indent()
-            << "  return [result success];" << endl << indent() << "}" << endl;
+        out <<
+          indent() << "if ([result successIsSet]) {" << endl <<
+          indent() << "  return [result success];" << 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) {
-        out << indent() << "if ([result " << (*x_iter)->get_name() << "IsSet]) {" << endl
-            << indent() << "  @throw [result " << (*x_iter)->get_name() << "];" << endl << indent()
-            << "}" << endl;
+        out <<
+          indent() << "if ([result " << (*x_iter)->get_name() << "IsSet]) {" << endl <<
+          indent() << "  @throw [result " << (*x_iter)->get_name() << "];" << endl <<
+          indent() << "}" << endl;
       }
 
       // If you get here it's an exception, unless a void function
       if ((*f_iter)->get_returntype()->is_void()) {
-        indent(out) << "return;" << endl;
+        indent(out) <<
+          "return;" << endl;
       } else {
-        out << indent() << "@throw [TApplicationException exceptionWithType: "
-                           "TApplicationException_MISSING_RESULT" << endl << indent()
-            << "                                         reason: @\"" << (*f_iter)->get_name()
-            << " failed: unknown result\"];" << endl;
+        out <<
+          indent() << "@throw [TApplicationException exceptionWithType: TApplicationException_MISSING_RESULT" << endl <<
+          indent() << "                                         reason: @\"" << (*f_iter)->get_name() << " failed: unknown result\"];" << endl;
       }
 
       // Close function
@@ -1399,9 +1509,11 @@ void t_cocoa_generator::generate_cocoa_service_client_implementation(ofstream& o
     }
 
     // Open function
-    indent(out) << "- " << function_signature(*f_iter) << endl;
+    indent(out) <<
+      "- " << function_signature(*f_iter) << endl;
     scope_up(out);
-    indent(out) << "[self send_" << funname;
+    indent(out) <<
+      "[self send_" << funname;
 
     // Declare the function arguments
     bool first = true;
@@ -1422,7 +1534,8 @@ void t_cocoa_generator::generate_cocoa_service_client_implementation(ofstream& o
       if (!(*f_iter)->get_returntype()->is_void()) {
         out << "return ";
       }
-      out << "[self recv_" << funname << "];" << endl;
+      out <<
+        "[self recv_" << funname << "];" << endl;
     }
     scope_down(out);
     out << endl;
@@ -1433,6 +1546,7 @@ void t_cocoa_generator::generate_cocoa_service_client_implementation(ofstream& o
   out << "@end" << endl << endl;
 }
 
+
 /**
  * Generates a service server implementation.  In other words the actual TProcessor implementation
  * for the service.
@@ -1446,8 +1560,7 @@ void t_cocoa_generator::generate_cocoa_service_server_implementation(ofstream& o
 
   // initializer
   out << endl;
-  out << "- (id) initWith" << tservice->get_name() << ": (id <" << cocoa_prefix_
-      << tservice->get_name() << ">) service" << endl;
+  out << "- (id) initWith" << tservice->get_name() << ": (id <" << cocoa_prefix_ << tservice->get_name() << ">) service" << endl;
   scope_up(out);
   out << indent() << "self = [super init];" << endl;
   out << indent() << "if (!self) {" << endl;
@@ -1462,11 +1575,9 @@ void t_cocoa_generator::generate_cocoa_service_server_implementation(ofstream& o
   for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
     string funname = (*f_iter)->get_name();
     scope_up(out);
-    out << indent() << "SEL s = @selector(process_" << funname
-        << "_withSequenceID:inProtocol:outProtocol:);" << endl;
+    out << indent() << "SEL s = @selector(process_" << funname << "_withSequenceID:inProtocol:outProtocol:);" << endl;
     out << indent() << "NSMethodSignature * sig = [self methodSignatureForSelector: s];" << endl;
-    out << indent()
-        << "NSInvocation * invocation = [NSInvocation invocationWithMethodSignature: sig];" << endl;
+    out << indent() << "NSInvocation * invocation = [NSInvocation invocationWithMethodSignature: sig];" << endl;
     out << indent() << "[invocation setSelector: s];" << endl;
     out << indent() << "[invocation retainArguments];" << endl;
     out << indent() << "[mMethodMap setValue: invocation forKey: @\"" << funname << "\"];" << endl;
@@ -1478,7 +1589,7 @@ void t_cocoa_generator::generate_cocoa_service_server_implementation(ofstream& o
   // implementation of the 'service' method which returns the service associated with this
   // processor
   out << endl;
-  out << indent() << "- (id<" << cocoa_prefix_ << tservice->get_name() << ">) service" << endl;
+  out << indent() << "- (id<"<<cocoa_prefix_ << tservice->get_name() << ">) service" << endl;
   out << indent() << "{" << endl;
   out << indent() << "  return [[mService retain_stub] autorelease_stub];" << endl;
   out << indent() << "}" << endl;
@@ -1486,7 +1597,7 @@ void t_cocoa_generator::generate_cocoa_service_server_implementation(ofstream& o
   // implementation of the TProcess method, which dispatches the incoming call using the method map
   out << endl;
   out << indent() << "- (BOOL) processOnInputProtocol: (id <TProtocol>) inProtocol" << endl;
-  out << indent() << "                 outputProtocol: (id <TProtocol>) outProtocol" << endl;
+  out << indent() << "                 outputProtocol: (id <TProtocol>) outProtocol" <<endl;
   out << indent() << "{" << endl;
   out << indent() << "  NSString * messageName;" << endl;
   out << indent() << "  int messageType;" << endl;
@@ -1498,9 +1609,7 @@ void t_cocoa_generator::generate_cocoa_service_server_implementation(ofstream& o
   out << indent() << "  if (invocation == nil) {" << endl;
   out << indent() << "    [TProtocolUtil skipType: TType_STRUCT onProtocol: inProtocol];" << endl;
   out << indent() << "    [inProtocol readMessageEnd];" << endl;
-  out << indent() << "    TApplicationException * x = [TApplicationException exceptionWithType: "
-                     "TApplicationException_UNKNOWN_METHOD reason: [NSString stringWithFormat: "
-                     "@\"Invalid method name: '%@'\", messageName]];" << endl;
+  out << indent() << "    TApplicationException * x = [TApplicationException exceptionWithType: TApplicationException_UNKNOWN_METHOD reason: [NSString stringWithFormat: @\"Invalid method name: '%@'\", messageName]];" << endl;
   out << indent() << "    [outProtocol writeMessageBeginWithName: messageName" << endl;
   out << indent() << "                                      type: TMessageType_EXCEPTION" << endl;
   out << indent() << "                                sequenceID: seqID];" << endl;
@@ -1510,8 +1619,7 @@ void t_cocoa_generator::generate_cocoa_service_server_implementation(ofstream& o
   out << indent() << "    return YES;" << endl;
   out << indent() << "  }" << endl;
   out << indent() << "  // NSInvocation does not conform to NSCopying protocol" << endl;
-  out << indent() << "  NSInvocation * i = [NSInvocation invocationWithMethodSignature: "
-                     "[invocation methodSignature]];" << endl;
+  out << indent() << "  NSInvocation * i = [NSInvocation invocationWithMethodSignature: [invocation methodSignature]];" << endl;
   out << indent() << "  [i setSelector: [invocation selector]];" << endl;
   out << indent() << "  [i setArgument: &seqID atIndex: 2];" << endl;
   out << indent() << "  [i setArgument: &inProtocol atIndex: 3];" << endl;
@@ -1521,15 +1629,12 @@ void t_cocoa_generator::generate_cocoa_service_server_implementation(ofstream& o
   out << indent() << "  return YES;" << endl;
   out << indent() << "}" << endl;
 
-  // generate a process_XXXX method for each service function, which reads args, calls the service,
-  // and writes results
+  // generate a process_XXXX method for each service function, which reads args, calls the service, and writes results
   functions = tservice->get_functions();
   for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
     out << endl;
     string funname = (*f_iter)->get_name();
-    out << indent() << "- (void) process_" << funname
-        << "_withSequenceID: (int32_t) seqID inProtocol: (id<TProtocol>) inProtocol outProtocol: "
-           "(id<TProtocol>) outProtocol" << endl;
+    out << indent() << "- (void) process_" << funname << "_withSequenceID: (int32_t) seqID inProtocol: (id<TProtocol>) inProtocol outProtocol: (id<TProtocol>) outProtocol" << endl;
     scope_up(out);
     string argstype = cocoa_prefix_ + function_args_helper_struct_type(*f_iter);
     out << indent() << argstype << " * args = [[" << argstype << " alloc] init];" << endl;
@@ -1538,8 +1643,8 @@ void t_cocoa_generator::generate_cocoa_service_server_implementation(ofstream& o
 
     // prepare the result if not oneway
     if (!(*f_iter)->is_oneway()) {
-      string resulttype = cocoa_prefix_ + function_result_helper_struct_type(*f_iter);
-      out << indent() << resulttype << " * result = [[" << resulttype << " alloc] init];" << endl;
+        string resulttype = cocoa_prefix_ + function_result_helper_struct_type(*f_iter);
+        out << indent() << resulttype << " * result = [[" << resulttype << " alloc] init];" << endl;
     }
 
     // make the call to the actual service object
@@ -1570,13 +1675,13 @@ void t_cocoa_generator::generate_cocoa_service_server_implementation(ofstream& o
 
     // write out the result if not oneway
     if (!(*f_iter)->is_oneway()) {
-      out << indent() << "[outProtocol writeMessageBeginWithName: @\"" << funname << "\"" << endl;
-      out << indent() << "                                  type: TMessageType_REPLY" << endl;
-      out << indent() << "                            sequenceID: seqID];" << endl;
-      out << indent() << "[result write: outProtocol];" << endl;
-      out << indent() << "[outProtocol writeMessageEnd];" << endl;
-      out << indent() << "[[outProtocol transport] flush];" << endl;
-      out << indent() << "[result release_stub];" << endl;
+        out << indent() << "[outProtocol writeMessageBeginWithName: @\"" << funname << "\"" << endl;
+        out << indent() << "                                  type: TMessageType_REPLY" << endl;
+        out << indent() << "                            sequenceID: seqID];" << endl;
+        out << indent() << "[result write: outProtocol];" << endl;
+        out << indent() << "[outProtocol writeMessageEnd];" << endl;
+        out << indent() << "[[outProtocol transport] flush];" << endl;
+        out << indent() << "[result release_stub];" << endl;
     }
     out << indent() << "[args release_stub];" << endl;
 
@@ -1598,6 +1703,7 @@ void t_cocoa_generator::generate_cocoa_service_server_implementation(ofstream& o
   out << "@end" << endl << endl;
 }
 
+
 /**
  * Deserializes a field of any type.
  *
@@ -1610,21 +1716,26 @@ void t_cocoa_generator::generate_deserialize_field(ofstream& out,
   t_type* type = get_true_type(tfield->get_type());
 
   if (type->is_void()) {
-    throw "CANNOT GENERATE DESERIALIZE CODE FOR void TYPE: " + tfield->get_name();
+    throw "CANNOT GENERATE DESERIALIZE CODE FOR void TYPE: " +
+      tfield->get_name();
   }
 
   if (type->is_struct() || type->is_xception()) {
-    generate_deserialize_struct(out, (t_struct*)type, fieldName);
+    generate_deserialize_struct(out,
+                                (t_struct*)type,
+                                fieldName);
   } else if (type->is_container()) {
     generate_deserialize_container(out, type, fieldName);
   } else if (type->is_base_type() || type->is_enum()) {
-    indent(out) << type_name(type) << " " << fieldName << " = [inProtocol ";
+    indent(out) <<
+      type_name(type) << " " << fieldName << " = [inProtocol ";
 
     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: " + tfield->get_name();
+        throw "compiler error: cannot serialize void field in a struct: " +
+          tfield->get_name();
         break;
       case t_base_type::TYPE_STRING:
         if (((t_base_type*)type)->is_binary()) {
@@ -1652,17 +1763,16 @@ void t_cocoa_generator::generate_deserialize_field(ofstream& out,
         out << "readDouble];";
         break;
       default:
-        throw "compiler error: no Objective-C name for base type "
-            + t_base_type::t_base_name(tbase);
+        throw "compiler error: no Objective-C name for base type " + t_base_type::t_base_name(tbase);
       }
     } 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());
   }
 }
 
@@ -1672,8 +1782,8 @@ void t_cocoa_generator::generate_deserialize_field(ofstream& out,
 void t_cocoa_generator::generate_deserialize_struct(ofstream& out,
                                                     t_struct* tstruct,
                                                     string fieldName) {
-  indent(out) << type_name(tstruct) << fieldName << " = [[" << type_name(tstruct, true)
-              << " alloc] init];" << endl;
+  indent(out) << type_name(tstruct) << fieldName << " = [[" <<
+    type_name(tstruct, true) << " alloc] init];" << endl;
   indent(out) << "[" << fieldName << " read: inProtocol];" << endl;
 }
 
@@ -1688,20 +1798,21 @@ void t_cocoa_generator::generate_deserialize_container(ofstream& out,
 
   // Declare variables, read header
   if (ttype->is_map()) {
-    indent(out) << "[inProtocol readMapBeginReturningKeyType: NULL valueType: NULL size: &" << size
-                << "];" << endl;
-    indent(out) << "NSMutableDictionary * " << fieldName
-                << " = [[NSMutableDictionary alloc] initWithCapacity: " << size << "];" << endl;
+    indent(out)
+      << "[inProtocol readMapBeginReturningKeyType: NULL valueType: NULL size: &" <<
+      size << "];" << endl;
+    indent(out) << "NSMutableDictionary * " << fieldName <<
+      " = [[NSMutableDictionary alloc] initWithCapacity: " << size << "];" << endl;
   } else if (ttype->is_set()) {
-    indent(out) << "[inProtocol readSetBeginReturningElementType: NULL size: &" << size << "];"
-                << endl;
-    indent(out) << "NSMutableSet * " << fieldName
-                << " = [[NSMutableSet alloc] initWithCapacity: " << size << "];" << endl;
+    indent(out)
+      << "[inProtocol readSetBeginReturningElementType: NULL size: &" << size << "];" << endl;
+    indent(out) << "NSMutableSet * " << fieldName <<
+      " = [[NSMutableSet alloc] initWithCapacity: " << size << "];" << endl;
   } else if (ttype->is_list()) {
-    indent(out) << "[inProtocol readListBeginReturningElementType: NULL size: &" << size << "];"
-                << endl;
-    indent(out) << "NSMutableArray * " << fieldName
-                << " = [[NSMutableArray alloc] initWithCapacity: " << size << "];" << endl;
+    indent(out)
+      << "[inProtocol readListBeginReturningElementType: NULL size: &" << size << "];" << endl;
+    indent(out) << "NSMutableArray * " << fieldName <<
+      " = [[NSMutableArray alloc] initWithCapacity: " << size << "];" << endl;
   }
   // FIXME - the code above does not verify that the element types of
   // the containers being read match the element types of the
@@ -1709,21 +1820,22 @@ void t_cocoa_generator::generate_deserialize_container(ofstream& out,
 
   // For loop iterates over elements
   string i = tmp("_i");
-  indent(out) << "int " << i << ";" << endl << indent() << "for (" << i << " = 0; " << i << " < "
-              << size << "; "
-              << "++" << i << ")" << endl;
+  indent(out) << "int " << i << ";" << endl <<
+    indent() << "for (" << i << " = 0; " <<
+    i << " < " << size << "; " <<
+    "++" << i << ")" << endl;
 
-  scope_up(out);
+    scope_up(out);
 
-  if (ttype->is_map()) {
-    generate_deserialize_map_element(out, (t_map*)ttype, fieldName);
-  } else if (ttype->is_set()) {
-    generate_deserialize_set_element(out, (t_set*)ttype, fieldName);
-  } else if (ttype->is_list()) {
-    generate_deserialize_list_element(out, (t_list*)ttype, fieldName);
-  }
+    if (ttype->is_map()) {
+      generate_deserialize_map_element(out, (t_map*)ttype, fieldName);
+    } else if (ttype->is_set()) {
+      generate_deserialize_set_element(out, (t_set*)ttype, fieldName);
+    } else if (ttype->is_list()) {
+      generate_deserialize_list_element(out, (t_list*)ttype, fieldName);
+    }
 
-  scope_down(out);
+    scope_down(out);
 
   // Read container end
   if (ttype->is_map()) {
@@ -1733,14 +1845,18 @@ void t_cocoa_generator::generate_deserialize_container(ofstream& out,
   } else if (ttype->is_list()) {
     indent(out) << "[inProtocol readListEnd];" << endl;
   }
+
 }
 
+
 /**
  * Take a variable of a given type and wrap it in code to make it
  * suitable for putting into a container, if necessary.  Basically,
  * wrap scaler primitives in NSNumber objects.
  */
-string t_cocoa_generator::containerize(t_type* ttype, string fieldName) {
+string t_cocoa_generator::containerize(t_type * ttype,
+                                       string fieldName)
+{
   // FIXME - optimize here to avoid autorelease pool?
   ttype = get_true_type(ttype);
   if (ttype->is_enum()) {
@@ -1771,6 +1887,7 @@ string t_cocoa_generator::containerize(t_type* ttype, string fieldName) {
   return fieldName;
 }
 
+
 /**
  * Generates code to deserialize a map element
  */
@@ -1787,8 +1904,9 @@ void t_cocoa_generator::generate_deserialize_map_element(ofstream& out,
   generate_deserialize_field(out, &fkey, key);
   generate_deserialize_field(out, &fval, val);
 
-  indent(out) << "[" << fieldName << " setObject: " << containerize(valType, val)
-              << " forKey: " << containerize(keyType, key) << "];" << endl;
+  indent(out) <<
+    "[" << fieldName << " setObject: " << containerize(valType, val) <<
+    " forKey: " << containerize(keyType, key) << "];" << endl;
 
   if (type_can_be_null(keyType)) {
     if (!(get_true_type(keyType)->is_string())) {
@@ -1815,7 +1933,8 @@ void t_cocoa_generator::generate_deserialize_set_element(ofstream& out,
 
   generate_deserialize_field(out, &felem, elem);
 
-  indent(out) << "[" << fieldName << " addObject: " << containerize(type, elem) << "];" << endl;
+  indent(out) <<
+    "[" << fieldName << " addObject: " << containerize(type, elem) << "];" << endl;
 
   if (type_can_be_null(type)) {
     // deserialized strings are autorelease, so don't release them
@@ -1837,7 +1956,8 @@ void t_cocoa_generator::generate_deserialize_list_element(ofstream& out,
 
   generate_deserialize_field(out, &felem, elem);
 
-  indent(out) << "[" << fieldName << " addObject: " << containerize(type, elem) << "];" << endl;
+  indent(out) <<
+    "[" << fieldName << " addObject: " << containerize(type, elem) << "];" << endl;
 
   if (type_can_be_null(type)) {
     if (!(get_true_type(type)->is_string())) {
@@ -1846,32 +1966,42 @@ void t_cocoa_generator::generate_deserialize_list_element(ofstream& out,
   }
 }
 
+
 /**
  * Serializes a field of any type.
  *
  * @param tfield The field to serialize
  * @param fieldName Name to of the variable holding the field
  */
-void t_cocoa_generator::generate_serialize_field(ofstream& out, t_field* tfield, string fieldName) {
+void t_cocoa_generator::generate_serialize_field(ofstream& out,
+                                                 t_field* tfield,
+                                                 string fieldName) {
   t_type* type = get_true_type(tfield->get_type());
 
   // Do nothing for void types
   if (type->is_void()) {
-    throw "CANNOT GENERATE SERIALIZE CODE FOR void TYPE: " + tfield->get_name();
+    throw "CANNOT GENERATE SERIALIZE CODE FOR void TYPE: " +
+      tfield->get_name();
   }
 
   if (type->is_struct() || type->is_xception()) {
-    generate_serialize_struct(out, (t_struct*)type, fieldName);
+    generate_serialize_struct(out,
+                              (t_struct*)type,
+                              fieldName);
   } else if (type->is_container()) {
-    generate_serialize_container(out, type, fieldName);
+    generate_serialize_container(out,
+                                 type,
+                                 fieldName);
   } else if (type->is_base_type() || type->is_enum()) {
-    indent(out) << "[outProtocol ";
+    indent(out) <<
+      "[outProtocol ";
 
     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: " + fieldName;
+        throw
+          "compiler error: cannot serialize void field in a struct: " + fieldName;
         break;
       case t_base_type::TYPE_STRING:
         if (((t_base_type*)type)->is_binary()) {
@@ -1899,8 +2029,7 @@ void t_cocoa_generator::generate_serialize_field(ofstream& out, t_field* tfield,
         out << "writeDouble: " << fieldName << "];";
         break;
       default:
-        throw "compiler error: no Objective-C name for base type "
-            + t_base_type::t_base_name(tbase);
+        throw "compiler error: no Objective-C name for base type " + t_base_type::t_base_name(tbase);
       }
     } else if (type->is_enum()) {
       out << "writeI32: " << fieldName << "];";
@@ -1922,8 +2051,9 @@ void t_cocoa_generator::generate_serialize_field(ofstream& out, t_field* tfield,
 void t_cocoa_generator::generate_serialize_struct(ofstream& out,
                                                   t_struct* tstruct,
                                                   string fieldName) {
-  (void)tstruct;
-  out << indent() << "[" << fieldName << " write: outProtocol];" << endl;
+  (void) tstruct;
+  out <<
+    indent() << "[" << fieldName << " write: outProtocol];" << endl;
 }
 
 /**
@@ -1938,18 +2068,21 @@ void t_cocoa_generator::generate_serialize_container(ofstream& out,
   scope_up(out);
 
   if (ttype->is_map()) {
-    indent(out) << "[outProtocol writeMapBeginWithKeyType: "
-                << type_to_enum(((t_map*)ttype)->get_key_type())
-                << " valueType: " << type_to_enum(((t_map*)ttype)->get_val_type()) << " size: ["
-                << fieldName << " count]];" << endl;
+    indent(out) <<
+      "[outProtocol writeMapBeginWithKeyType: " <<
+      type_to_enum(((t_map*)ttype)->get_key_type()) << " valueType: " <<
+      type_to_enum(((t_map*)ttype)->get_val_type()) << " size: [" <<
+      fieldName << " count]];" << endl;
   } else if (ttype->is_set()) {
-    indent(out) << "[outProtocol writeSetBeginWithElementType: "
-                << type_to_enum(((t_set*)ttype)->get_elem_type()) << " size: [" << fieldName
-                << " count]];" << endl;
+    indent(out) <<
+      "[outProtocol writeSetBeginWithElementType: " <<
+      type_to_enum(((t_set*)ttype)->get_elem_type()) << " size: [" <<
+      fieldName << " count]];" << endl;
   } else if (ttype->is_list()) {
-    indent(out) << "[outProtocol writeListBeginWithElementType: "
-                << type_to_enum(((t_list*)ttype)->get_elem_type()) << " size: [" << fieldName
-                << " count]];" << endl;
+    indent(out) <<
+      "[outProtocol writeListBeginWithElementType: " <<
+      type_to_enum(((t_list*)ttype)->get_elem_type()) << " size: [" <<
+      fieldName << " count]];" << endl;
   }
 
   string iter = tmp("_iter");
@@ -1961,36 +2094,38 @@ void t_cocoa_generator::generate_serialize_container(ofstream& out,
     indent(out) << "while ((" << key << " = [" << iter << " nextObject]))" << endl;
   } else if (ttype->is_set()) {
     key = tmp("obj");
-    indent(out) << "NSEnumerator * " << iter << " = [" << fieldName << " objectEnumerator];"
-                << endl;
+    indent(out) << "NSEnumerator * " << iter << " = [" << fieldName << " objectEnumerator];" << endl;
     indent(out) << "id " << key << ";" << endl;
     indent(out) << "while ((" << key << " = [" << iter << " nextObject]))" << endl;
   } else if (ttype->is_list()) {
     key = tmp("idx");
     indent(out) << "int " << key << ";" << endl;
-    indent(out) << "for (" << key << " = 0; " << key << " < [" << fieldName << " count]; " << key
-                << "++)" << endl;
+    indent(out) <<
+      "for (" << key << " = 0; " << key << " < [" << fieldName << " count]; " << key << "++)" << endl;
   }
 
-  scope_up(out);
+    scope_up(out);
 
-  if (ttype->is_map()) {
-    generate_serialize_map_element(out, (t_map*)ttype, key, fieldName);
-  } else if (ttype->is_set()) {
-    generate_serialize_set_element(out, (t_set*)ttype, key);
-  } else if (ttype->is_list()) {
-    generate_serialize_list_element(out, (t_list*)ttype, key, fieldName);
-  }
+    if (ttype->is_map()) {
+      generate_serialize_map_element(out, (t_map*)ttype, key, fieldName);
+    } else if (ttype->is_set()) {
+      generate_serialize_set_element(out, (t_set*)ttype, key);
+    } else if (ttype->is_list()) {
+      generate_serialize_list_element(out, (t_list*)ttype, key, fieldName);
+    }
 
-  scope_down(out);
+    scope_down(out);
 
-  if (ttype->is_map()) {
-    indent(out) << "[outProtocol writeMapEnd];" << endl;
-  } else if (ttype->is_set()) {
-    indent(out) << "[outProtocol writeSetEnd];" << endl;
-  } else if (ttype->is_list()) {
-    indent(out) << "[outProtocol writeListEnd];" << endl;
-  }
+    if (ttype->is_map()) {
+      indent(out) <<
+        "[outProtocol writeMapEnd];" << endl;
+    } else if (ttype->is_set()) {
+      indent(out) <<
+        "[outProtocol writeSetEnd];" << endl;
+    } else if (ttype->is_list()) {
+      indent(out) <<
+        "[outProtocol writeListEnd];" << endl;
+    }
 
   scope_down(out);
 }
@@ -1999,8 +2134,10 @@ void t_cocoa_generator::generate_serialize_container(ofstream& out,
  * Given a field variable name, wrap it in code that converts it to a
  * primitive type, if necessary.
  */
-string t_cocoa_generator::decontainerize(t_field* tfield, string fieldName) {
-  t_type* ttype = get_true_type(tfield->get_type());
+string t_cocoa_generator::decontainerize(t_field * tfield,
+                                         string fieldName)
+{
+  t_type * ttype = get_true_type(tfield->get_type());
   if (ttype->is_enum()) {
     return "[" + fieldName + " intValue]";
   } else if (ttype->is_base_type()) {
@@ -2029,6 +2166,7 @@ string t_cocoa_generator::decontainerize(t_field* tfield, string fieldName) {
   return fieldName;
 }
 
+
 /**
  * Serializes the members of a map.
  */
@@ -2063,6 +2201,7 @@ v

<TRUNCATED>