From: David Reiss Date: Thu, 27 Mar 2008 21:40:59 +0000 (+0000) Subject: Remove t_cocoa_generator.h. X-Git-Tag: 0.2.0~868 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=e21ce4c6ca430f093bf626175088caf2178cc2c3;p=common%2Fthrift.git Remove t_cocoa_generator.h. t_cocoa_generator.h is no longer included anywhere, because the Cocoa generator uses the new dynamic generator framework. Therefore, we can collapse the class definition into the .cc file. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665604 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/Makefile.am b/compiler/cpp/Makefile.am index dacb2a9d..eb8a2fcc 100644 --- a/compiler/cpp/Makefile.am +++ b/compiler/cpp/Makefile.am @@ -47,7 +47,6 @@ thrift_SOURCES = src/thrifty.yy \ src/generate/t_xsd_generator.h \ src/generate/t_perl_generator.h \ src/generate/t_erl_generator.h \ - src/generate/t_cocoa_generator.h \ src/generate/t_csharp_generator.h if THRIFT_GEN_cpp diff --git a/compiler/cpp/src/generate/t_cocoa_generator.cc b/compiler/cpp/src/generate/t_cocoa_generator.cc index 4be14dbd..cb56c794 100644 --- a/compiler/cpp/src/generate/t_cocoa_generator.cc +++ b/compiler/cpp/src/generate/t_cocoa_generator.cc @@ -4,13 +4,187 @@ // See accompanying file LICENSE or visit the Thrift site at: // http://developers.facebook.com/thrift/ +#include +#include +#include +#include + #include #include #include -#include "t_cocoa_generator.h" +#include "t_oop_generator.h" #include "platform.h" using namespace std; + +/** + * Objective-C code generator. + * + * @author Andrew McGeachie , although it was + * 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& parsed_options, + const std::string& option_string) + : t_oop_generator(program) + { + out_dir_base_ = "gen-cocoa"; + } + + /** + * Init and close methods + */ + + void init_generator(); + void close_generator(); + + void generate_consts(std::vector consts); + + /** + * 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); + std::string render_const_value(std::string name, 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_field_accessor_declarations(std::ofstream& out, + t_struct* tstruct, + bool is_exception); + void generate_cocoa_struct_field_accessor_implementations(std::ofstream& out, + t_struct* tstruct, + bool is_exception); + void generate_cocoa_struct_reader(std::ofstream& out, t_struct* tstruct); + void generate_cocoa_struct_result_writer(std::ofstream& out, t_struct* tstruct); + void generate_cocoa_struct_writer(std::ofstream& out, t_struct* tstruct); + void generate_cocoa_struct_description(std::ofstream& out, t_struct* tstruct); + + std::string function_result_helper_struct_type(t_function* tfunction); + void generate_function_helpers(t_function* tfunction); + + /** + * 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_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_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_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_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_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_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_list_element (std::ofstream& out, + t_list* tlist, + std::string index, + std::string listName); + + /** + * Helper rendering functions + */ + + 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 base_type_name(t_base_type* tbase); + std::string declare_field(t_field* tfield); + std::string function_signature(t_function* tfunction); + std::string argument_list(t_struct* tstruct); + 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); + + 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(); + } + + private: + + std::string cocoa_prefix_; + std::string constants_declarations_; + + /** + * File streams + */ + + std::ofstream f_header_; + std::ofstream f_impl_; + +}; + + /** * Prepares for file generation by opening up the necessary file output * streams. diff --git a/compiler/cpp/src/generate/t_cocoa_generator.h b/compiler/cpp/src/generate/t_cocoa_generator.h deleted file mode 100644 index 1d68fa52..00000000 --- a/compiler/cpp/src/generate/t_cocoa_generator.h +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright (c) 2006- Facebook -// Distributed under the Thrift Software License -// -// See accompanying file LICENSE or visit the Thrift site at: -// http://developers.facebook.com/thrift/ - -#ifndef T_COCOA_GENERATOR_H -#define T_COCOA_GENERATOR_H - -#include -#include -#include -#include - -#include "t_oop_generator.h" - -/** - * Objective-C code generator. - * - * @author Andrew McGeachie , although it was - * 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& parsed_options, - const std::string& option_string) - : t_oop_generator(program) - { - out_dir_base_ = "gen-cocoa"; - } - - /** - * Init and close methods - */ - - void init_generator(); - void close_generator(); - - void generate_consts(std::vector consts); - - /** - * 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); - std::string render_const_value(std::string name, 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_field_accessor_declarations(std::ofstream& out, - t_struct* tstruct, - bool is_exception); - void generate_cocoa_struct_field_accessor_implementations(std::ofstream& out, - t_struct* tstruct, - bool is_exception); - void generate_cocoa_struct_reader(std::ofstream& out, t_struct* tstruct); - void generate_cocoa_struct_result_writer(std::ofstream& out, t_struct* tstruct); - void generate_cocoa_struct_writer(std::ofstream& out, t_struct* tstruct); - void generate_cocoa_struct_description(std::ofstream& out, t_struct* tstruct); - - std::string function_result_helper_struct_type(t_function* tfunction); - void generate_function_helpers(t_function* tfunction); - - /** - * 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_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_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_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_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_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_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_list_element (std::ofstream& out, - t_list* tlist, - std::string index, - std::string listName); - - /** - * Helper rendering functions - */ - - 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 base_type_name(t_base_type* tbase); - std::string declare_field(t_field* tfield); - std::string function_signature(t_function* tfunction); - std::string argument_list(t_struct* tstruct); - 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); - - 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(); - } - - private: - - std::string cocoa_prefix_; - std::string constants_declarations_; - - /** - * File streams - */ - - std::ofstream f_header_; - std::ofstream f_impl_; - -}; - -#endif