From: David Reiss Date: Thu, 27 Mar 2008 21:40:20 +0000 (+0000) Subject: Remove t_hs_generator.h. X-Git-Tag: 0.2.0~877 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=42e6d5143761fc0e20254a46a15e3da59ca0ac51;p=common%2Fthrift.git Remove t_hs_generator.h. t_hs_generator.h is no longer included anywhere, because the Haskell 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@665595 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/Makefile.am b/compiler/cpp/Makefile.am index bb78b1ef..f06b821d 100644 --- a/compiler/cpp/Makefile.am +++ b/compiler/cpp/Makefile.am @@ -49,7 +49,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_hs_generator.h \ src/generate/t_cocoa_generator.h \ src/generate/t_st_generator.h \ src/generate/t_csharp_generator.h diff --git a/compiler/cpp/src/generate/t_hs_generator.cc b/compiler/cpp/src/generate/t_hs_generator.cc index a71b15c4..e5fcb60f 100644 --- a/compiler/cpp/src/generate/t_hs_generator.cc +++ b/compiler/cpp/src/generate/t_hs_generator.cc @@ -4,14 +4,152 @@ // See accompanying file LICENSE or visit the Thrift site at: // http://developers.facebook.com/thrift/ +#include +#include +#include +#include + #include #include #include #include -#include "t_hs_generator.h" +#include "t_oop_generator.h" #include "platform.h" using namespace std; + +/** + * Haskell code generator. + * + * @author Iain Proctor + */ +class t_hs_generator : public t_oop_generator { + public: + t_hs_generator( + t_program* program, + const std::map& parsed_options, + const std::string& option_string) + : t_oop_generator(program) + { + out_dir_base_ = "gen-hs"; + } + + /** + * Init and close methods + */ + + void init_generator(); + void close_generator(); + + /** + * Program-level generation functions + */ + void generate_program (); + void generate_typedef (t_typedef* ttypedef); + void generate_enum (t_enum* tenum); + void generate_const (t_const* tconst); + void generate_struct (t_struct* tstruct); + void generate_xception (t_struct* txception); + void generate_service (t_service* tservice); + + std::string render_const_value(t_type* type, t_const_value* value); + + /** + * Struct generation code + */ + + void generate_hs_struct(t_struct* tstruct, bool is_exception); + void generate_hs_struct_definition(std::ofstream &out,t_struct* tstruct, bool is_xception=false,bool helper=false); + void generate_hs_struct_reader(std::ofstream& out, t_struct* tstruct); + void generate_hs_struct_writer(std::ofstream& out, t_struct* tstruct); + void generate_hs_function_helpers(t_function* tfunction); + + /** + * Service-level generation functions + */ + + void generate_service_helpers (t_service* tservice); + void generate_service_interface (t_service* tservice); + void generate_service_client (t_service* tservice); + void generate_service_server (t_service* tservice); + void generate_process_function (t_service* tservice, t_function* tfunction); + + /** + * Serialization constructs + */ + + void generate_deserialize_field (std::ofstream &out, + t_field* tfield, + std::string prefix); + + void generate_deserialize_struct (std::ofstream &out, + t_struct* tstruct); + + void generate_deserialize_container (std::ofstream &out, + t_type* ttype); + + void generate_deserialize_set_element (std::ofstream &out, + t_set* tset); + + + void generate_deserialize_list_element (std::ofstream &out, + t_list* tlist, + std::string prefix=""); + void generate_deserialize_type (std::ofstream &out, + t_type* type); + + void generate_serialize_field (std::ofstream &out, + t_field* tfield, + std::string name= ""); + + void generate_serialize_struct (std::ofstream &out, + t_struct* tstruct, + std::string prefix=""); + + void generate_serialize_container (std::ofstream &out, + t_type* ttype, + std::string prefix=""); + + void generate_serialize_map_element (std::ofstream &out, + t_map* tmap, + std::string kiter, + std::string viter); + + void generate_serialize_set_element (std::ofstream &out, + t_set* tmap, + std::string iter); + + void generate_serialize_list_element (std::ofstream &out, + t_list* tlist, + std::string iter); + + /** + * Helper rendering functions + */ + + std::string hs_autogen_comment(); + std::string hs_imports(); + std::string type_name(t_type* ttype); + std::string function_type(t_function* tfunc, bool options = false, bool io = false, bool method = false); + std::string type_to_enum(t_type* ttype); + std::string render_hs_type(t_type* type); + + + private: + + /** + * File streams + */ + + std::ofstream f_types_; + std::ofstream f_consts_; + std::ofstream f_service_; + std::ofstream f_iface_; + std::ofstream f_client_; + +}; + + /* * This is necessary because we want typedefs to appear later, * after all the types have been declared. diff --git a/compiler/cpp/src/generate/t_hs_generator.h b/compiler/cpp/src/generate/t_hs_generator.h deleted file mode 100644 index 4a387301..00000000 --- a/compiler/cpp/src/generate/t_hs_generator.h +++ /dev/null @@ -1,148 +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_HS_GENERATOR_H -#define T_HS_GENERATOR_H - -#include -#include -#include -#include - -#include "t_oop_generator.h" - -/** - * Haskell code generator. - * - * @author Iain Proctor - */ -class t_hs_generator : public t_oop_generator { - public: - t_hs_generator( - t_program* program, - const std::map& parsed_options, - const std::string& option_string) - : t_oop_generator(program) - { - out_dir_base_ = "gen-hs"; - } - - /** - * Init and close methods - */ - - void init_generator(); - void close_generator(); - - /** - * Program-level generation functions - */ - void generate_program (); - void generate_typedef (t_typedef* ttypedef); - void generate_enum (t_enum* tenum); - void generate_const (t_const* tconst); - void generate_struct (t_struct* tstruct); - void generate_xception (t_struct* txception); - void generate_service (t_service* tservice); - - std::string render_const_value(t_type* type, t_const_value* value); - - /** - * Struct generation code - */ - - void generate_hs_struct(t_struct* tstruct, bool is_exception); - void generate_hs_struct_definition(std::ofstream &out,t_struct* tstruct, bool is_xception=false,bool helper=false); - void generate_hs_struct_reader(std::ofstream& out, t_struct* tstruct); - void generate_hs_struct_writer(std::ofstream& out, t_struct* tstruct); - void generate_hs_function_helpers(t_function* tfunction); - - /** - * Service-level generation functions - */ - - void generate_service_helpers (t_service* tservice); - void generate_service_interface (t_service* tservice); - void generate_service_client (t_service* tservice); - void generate_service_server (t_service* tservice); - void generate_process_function (t_service* tservice, t_function* tfunction); - - /** - * Serialization constructs - */ - - void generate_deserialize_field (std::ofstream &out, - t_field* tfield, - std::string prefix); - - void generate_deserialize_struct (std::ofstream &out, - t_struct* tstruct); - - void generate_deserialize_container (std::ofstream &out, - t_type* ttype); - - void generate_deserialize_set_element (std::ofstream &out, - t_set* tset); - - - void generate_deserialize_list_element (std::ofstream &out, - t_list* tlist, - std::string prefix=""); - void generate_deserialize_type (std::ofstream &out, - t_type* type); - - void generate_serialize_field (std::ofstream &out, - t_field* tfield, - std::string name= ""); - - void generate_serialize_struct (std::ofstream &out, - t_struct* tstruct, - std::string prefix=""); - - void generate_serialize_container (std::ofstream &out, - t_type* ttype, - std::string prefix=""); - - void generate_serialize_map_element (std::ofstream &out, - t_map* tmap, - std::string kiter, - std::string viter); - - void generate_serialize_set_element (std::ofstream &out, - t_set* tmap, - std::string iter); - - void generate_serialize_list_element (std::ofstream &out, - t_list* tlist, - std::string iter); - - /** - * Helper rendering functions - */ - - std::string hs_autogen_comment(); - std::string hs_imports(); - std::string type_name(t_type* ttype); - std::string function_type(t_function* tfunc, bool options = false, bool io = false, bool method = false); - std::string type_to_enum(t_type* ttype); - std::string render_hs_type(t_type* type); - - - private: - - /** - * File streams - */ - - std::ofstream f_types_; - std::ofstream f_consts_; - std::ofstream f_service_; - std::ofstream f_iface_; - std::ofstream f_client_; - -}; - -#endif