From 9f16d785531a408cc48d8bb0e63b6b6058c55d59 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Tue, 17 Feb 2009 20:27:58 +0000 Subject: [PATCH] Remove t_erl_generator.h. t_erl_generator.h is no longer included anywhere, because the Erlang 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@745232 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/cpp/Makefile.am | 3 +- compiler/cpp/src/generate/t_erl_generator.cc | 136 +++++++++++++++++- compiler/cpp/src/generate/t_erl_generator.h | 138 ------------------- 3 files changed, 136 insertions(+), 141 deletions(-) delete mode 100644 compiler/cpp/src/generate/t_erl_generator.h diff --git a/compiler/cpp/Makefile.am b/compiler/cpp/Makefile.am index 024f4435..132462ca 100644 --- a/compiler/cpp/Makefile.am +++ b/compiler/cpp/Makefile.am @@ -38,8 +38,7 @@ thrift_SOURCES = src/thrifty.yy \ src/generate/t_generator.h \ src/generate/t_oop_generator.h \ src/generate/t_php_generator.h \ - src/generate/t_xsd_generator.h \ - src/generate/t_erl_generator.h + src/generate/t_xsd_generator.h if THRIFT_GEN_cpp thrift_SOURCES += src/generate/t_cpp_generator.cc diff --git a/compiler/cpp/src/generate/t_erl_generator.cc b/compiler/cpp/src/generate/t_erl_generator.cc index 6fec5124..64cadcf0 100644 --- a/compiler/cpp/src/generate/t_erl_generator.cc +++ b/compiler/cpp/src/generate/t_erl_generator.cc @@ -4,15 +4,149 @@ // 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_erl_generator.h" +#include "t_generator.h" #include "platform.h" using namespace std; + +/** + * Erlang code generator. + * + * @author + */ +class t_erl_generator : public t_generator { + public: + t_erl_generator( + t_program* program, + const std::map& parsed_options, + const std::string& option_string) + : t_generator(program) + { + program_name_[0] = tolower(program_name_[0]); + service_name_[0] = tolower(service_name_[0]); + out_dir_base_ = "gen-erl"; + } + + /** + * Init and close methods + */ + + void init_generator(); + void close_generator(); + + /** + * Program-level generation functions + */ + + void generate_typedef (t_typedef* ttypedef); + void generate_enum (t_enum* tenum); + void generate_const (t_const* tconst); + void generate_struct (t_struct* tstruct); + void generate_xception (t_struct* txception); + void generate_service (t_service* tservice); + + std::string render_const_value(t_type* type, t_const_value* value); + + /** + * Struct generation code + */ + + void generate_erl_struct(t_struct* tstruct, bool is_exception); + void generate_erl_struct_definition(std::ostream& out, std::ostream& hrl_out, t_struct* tstruct, bool is_xception=false, bool is_result=false); + void generate_erl_struct_info(std::ostream& out, t_struct* tstruct); + void generate_erl_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_function_info (t_service* tservice, t_function* tfunction); + + /** + * Helper rendering functions + */ + + std::string erl_autogen_comment(); + std::string erl_imports(); + std::string render_includes(); + std::string declare_field(t_field* tfield); + std::string type_name(t_type* ttype); + + std::string function_signature(t_function* tfunction, std::string prefix=""); + + + std::string argument_list(t_struct* tstruct); + std::string type_to_enum(t_type* ttype); + std::string generate_type_term(t_type* ttype, bool expand_structs); + std::string type_module(t_type* ttype); + + std::string capitalize(std::string in) { + in[0] = toupper(in[0]); + return in; + } + + std::string uncapitalize(std::string in) { + in[0] = tolower(in[0]); + return in; + } + + private: + + /** + * add function to export list + */ + + void export_function(t_function* tfunction, std::string prefix=""); + void export_string(std::string name, int num); + + void export_types_function(t_function* tfunction, std::string prefix=""); + void export_types_string(std::string name, int num); + + /** + * write out headers and footers for hrl files + */ + + void hrl_header(std::ostream& out, std::string name); + void hrl_footer(std::ostream& out, std::string name); + + /** + * stuff to spit out at the top of generated files + */ + + bool export_lines_first_; + std::ostringstream export_lines_; + + bool export_types_lines_first_; + std::ostringstream export_types_lines_; + + /** + * File streams + */ + + std::ostringstream f_types_; + std::ofstream f_types_file_; + std::ofstream f_types_hrl_file_; + + std::ofstream f_consts_; + std::ostringstream f_service_; + std::ofstream f_service_file_; + std::ofstream f_service_hrl_; + +}; + + /** * UI for file generation by opening up the necessary file output * streams. diff --git a/compiler/cpp/src/generate/t_erl_generator.h b/compiler/cpp/src/generate/t_erl_generator.h deleted file mode 100644 index d8f2d1a7..00000000 --- a/compiler/cpp/src/generate/t_erl_generator.h +++ /dev/null @@ -1,138 +0,0 @@ -#ifndef T_ERL_GENERATOR_H -#define T_ERL_GENERATOR_H - -#include -#include -#include -#include - -#include "t_oop_generator.h" - -/** - * Erlang code generator. - * - * @author - */ -class t_erl_generator : public t_generator { - public: - t_erl_generator( - t_program* program, - const std::map& parsed_options, - const std::string& option_string) - : t_generator(program) - { - program_name_[0] = tolower(program_name_[0]); - service_name_[0] = tolower(service_name_[0]); - out_dir_base_ = "gen-erl"; - } - - /** - * Init and close methods - */ - - void init_generator(); - void close_generator(); - - /** - * Program-level generation functions - */ - - void generate_typedef (t_typedef* ttypedef); - void generate_enum (t_enum* tenum); - void generate_const (t_const* tconst); - void generate_struct (t_struct* tstruct); - void generate_xception (t_struct* txception); - void generate_service (t_service* tservice); - - std::string render_const_value(t_type* type, t_const_value* value); - - /** - * Struct generation code - */ - - void generate_erl_struct(t_struct* tstruct, bool is_exception); - void generate_erl_struct_definition(std::ostream& out, std::ostream& hrl_out, t_struct* tstruct, bool is_xception=false, bool is_result=false); - void generate_erl_struct_info(std::ostream& out, t_struct* tstruct); - void generate_erl_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_function_info (t_service* tservice, t_function* tfunction); - - /** - * Helper rendering functions - */ - - std::string erl_autogen_comment(); - std::string erl_imports(); - std::string render_includes(); - std::string declare_field(t_field* tfield); - std::string type_name(t_type* ttype); - - std::string function_signature(t_function* tfunction, std::string prefix=""); - - - std::string argument_list(t_struct* tstruct); - std::string type_to_enum(t_type* ttype); - std::string generate_type_term(t_type* ttype, bool expand_structs); - std::string type_module(t_type* ttype); - - std::string capitalize(std::string in) { - in[0] = toupper(in[0]); - return in; - } - - std::string uncapitalize(std::string in) { - in[0] = tolower(in[0]); - return in; - } - - private: - - /** - * add function to export list - */ - - void export_function(t_function* tfunction, std::string prefix=""); - void export_string(std::string name, int num); - - void export_types_function(t_function* tfunction, std::string prefix=""); - void export_types_string(std::string name, int num); - - /** - * write out headers and footers for hrl files - */ - - void hrl_header(std::ostream& out, std::string name); - void hrl_footer(std::ostream& out, std::string name); - - /** - * stuff to spit out at the top of generated files - */ - - bool export_lines_first_; - std::ostringstream export_lines_; - - bool export_types_lines_first_; - std::ostringstream export_types_lines_; - - /** - * File streams - */ - - std::ostringstream f_types_; - std::ofstream f_types_file_; - std::ofstream f_types_hrl_file_; - - std::ofstream f_consts_; - std::ostringstream f_service_; - std::ofstream f_service_file_; - std::ofstream f_service_hrl_; - -}; - -#endif -- 2.17.1