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:22 UTC
[30/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_delphi_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_delphi_generator.cc b/compiler/cpp/src/generate/t_delphi_generator.cc
index 682c18d..1012614 100644
--- a/compiler/cpp/src/generate/t_delphi_generator.cc
+++ b/compiler/cpp/src/generate/t_delphi_generator.cc
@@ -45,375 +45,236 @@ using std::string;
using std::stringstream;
using std::vector;
-static const string endl = "\n"; // avoid ostream << std::endl flushes
-
-class t_delphi_generator : public t_oop_generator {
-public:
- t_delphi_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;
- indent_impl_ = 0;
- has_forward = false;
- has_enum = false;
- has_const = false;
- std::map<std::string, std::string>::const_iterator iter;
-
- iter = parsed_options.find("ansistr_binary");
- ansistr_binary_ = (iter != parsed_options.end());
- iter = parsed_options.find("register_types");
- register_types_ = (iter != parsed_options.end());
- iter = parsed_options.find("constprefix");
- constprefix_ = (iter != parsed_options.end());
- iter = parsed_options.find("events");
- events_ = (iter != parsed_options.end());
- iter = parsed_options.find("xmldoc");
- xmldoc_ = (iter != parsed_options.end());
-
- out_dir_base_ = "gen-delphi";
- escape_.clear();
- escape_['\''] = "''";
- }
-
- void init_generator();
- void close_generator();
-
- void generate_consts(std::vector<t_const*> consts);
-
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_forward_declaration(t_struct* tstruct);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
- void generate_property(ostream& out, t_field* tfield, bool isPublic, bool is_xception);
- void generate_property_writer_(ostream& out, t_field* tfield, bool isPublic);
-
- void generate_delphi_property(ostream& out,
- bool struct_is_exception,
- t_field* tfield,
- bool isPublic,
- std::string fieldPrefix = "");
- void generate_delphi_isset_reader_definition(ostream& out, t_field* tfield, bool is_xception);
- void generate_delphi_property_reader_definition(ostream& out,
- t_field* tfield,
- bool is_xception_class);
- void generate_delphi_property_writer_definition(ostream& out,
- t_field* tfield,
- bool is_xception_class);
- void generate_delphi_property_reader_impl(ostream& out,
- std::string cls_prefix,
- std::string name,
- t_type* type,
- t_field* tfield,
- std::string fieldPrefix,
- bool is_xception_class);
- void generate_delphi_property_writer_impl(ostream& out,
- std::string cls_prefix,
- std::string name,
- t_type* type,
- t_field* tfield,
- std::string fieldPrefix,
- bool is_xception_class,
- bool is_union,
- bool is_xception_factory,
- std::string xception_factroy_name);
- void generate_delphi_clear_union_value(ostream& out,
- std::string cls_prefix,
- std::string name,
- t_type* type,
- t_field* tfield,
- std::string fieldPrefix,
- bool is_xception_class,
- bool is_union,
- bool is_xception_factory,
- std::string xception_factroy_name);
- void generate_delphi_isset_reader_impl(ostream& out,
- std::string cls_prefix,
- std::string name,
- t_type* type,
- t_field* tfield,
- std::string fieldPrefix,
- bool is_xception);
- void generate_delphi_struct_writer_impl(ostream& out,
- std::string cls_prefix,
- t_struct* tstruct,
- bool is_exception);
- void generate_delphi_struct_result_writer_impl(ostream& out,
- std::string cls_prefix,
- t_struct* tstruct,
- bool is_exception);
-
- void generate_delphi_struct_tostring_impl(ostream& out,
- std::string cls_prefix,
- t_struct* tstruct,
- bool is_exception,
- bool is_x_factory);
-
- void add_delphi_uses_list(string unitname);
-
- void generate_delphi_struct_reader_impl(ostream& out,
- std::string cls_prefix,
- t_struct* tstruct,
- bool is_exception);
- void generate_delphi_create_exception_impl(ostream& out,
- string cls_prefix,
- t_struct* tstruct,
- bool is_exception);
-
- bool const_needs_var(t_type* type);
- void print_const_prop(std::ostream& out, string name, t_type* type, t_const_value* value);
- void print_private_field(std::ostream& out, string name, t_type* type, t_const_value* value);
- void print_const_value(std::ostream& vars,
- std::ostream& out,
- std::string name,
- t_type* type,
- t_const_value* value);
- void initialize_field(std::ostream& vars,
- std::ostream& out,
- std::string name,
- t_type* type,
- t_const_value* value);
- void finalize_field(std::ostream& out,
- std::string name,
- t_type* type,
- t_const_value* value,
- std::string cls_nm = "");
- std::string render_const_value(std::ostream& local_vars,
- std::ostream& out,
- std::string name,
- t_type* type,
- t_const_value* value);
- void print_const_def_value(std::ostream& vars,
- std::ostream& out,
- std::string name,
- t_type* type,
- t_const_value* value,
- std::string cls_nm = "");
- std::string make_constants_classname();
-
- void generate_delphi_struct(t_struct* tstruct, bool is_exception);
- void generate_delphi_struct_impl(ostream& out,
- std::string cls_prefix,
- t_struct* tstruct,
- bool is_exception,
- bool is_result = false,
- bool is_x_factory = false);
- void print_delphi_struct_type_factory_func(ostream& out, t_struct* tstruct);
- void generate_delphi_struct_type_factory(ostream& out,
- std::string cls_prefix,
- t_struct* tstruct,
- bool is_exception,
- bool is_result = false,
- bool is_x_factory = false);
- void generate_delphi_struct_type_factory_registration(ostream& out,
- std::string cls_prefix,
- t_struct* tstruct,
- bool is_exception,
- bool is_result = false,
- bool is_x_factory = false);
- void generate_delphi_struct_definition(std::ostream& out,
- t_struct* tstruct,
- bool is_xception = false,
- bool in_class = false,
- bool is_result = false,
- bool is_x_factory = false);
- void generate_delphi_struct_reader(std::ostream& out, t_struct* tstruct);
- void generate_delphi_struct_result_writer(std::ostream& out, t_struct* tstruct);
- void generate_delphi_struct_writer(std::ostream& out, t_struct* tstruct);
- void generate_delphi_struct_tostring(std::ostream& out, t_struct* tstruct);
-
- void generate_function_helpers(t_function* tfunction);
- void generate_service_interface(t_service* tservice);
- void generate_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* function);
-
- void generate_deserialize_field(std::ostream& out,
- bool is_xception,
- t_field* tfield,
- std::string prefix,
- std::ostream& local_vars);
- void generate_deserialize_struct(std::ostream& out,
- t_struct* tstruct,
- std::string name,
- std::string prefix);
- void generate_deserialize_container(ostream& out,
- bool is_xception,
- t_type* ttype,
- string name,
- std::ostream& local_vars);
-
- void generate_deserialize_set_element(std::ostream& out,
- bool is_xception,
- t_set* tset,
- std::string prefix,
- std::ostream& local_vars);
- void generate_deserialize_map_element(std::ostream& out,
- bool is_xception,
- t_map* tmap,
- std::string prefix,
- std::ostream& local_vars);
- void generate_deserialize_list_element(std::ostream& out,
- bool is_xception,
- t_list* list,
- std::string prefix,
- std::ostream& local_vars);
-
- void generate_serialize_field(std::ostream& out,
- bool is_xception,
- t_field* tfield,
- std::string prefix,
- std::ostream& local_vars);
- void generate_serialize_struct(std::ostream& out,
- t_struct* tstruct,
- std::string prefix,
- std::ostream& local_vars);
- void generate_serialize_container(std::ostream& out,
- bool is_xception,
- t_type* ttype,
- std::string prefix,
- std::ostream& local_vars);
- void generate_serialize_map_element(std::ostream& out,
- bool is_xception,
- t_map* tmap,
- std::string iter,
- std::string map,
- std::ostream& local_vars);
- void generate_serialize_set_element(std::ostream& out,
- bool is_xception,
- t_set* tmap,
- std::string iter,
- std::ostream& local_vars);
- void generate_serialize_list_element(std::ostream& out,
- bool is_xception,
- t_list* tlist,
- std::string iter,
- std::ostream& local_vars);
-
- void delphi_type_usings(std::ostream& out);
- std::string delphi_thrift_usings();
-
- std::string type_name(t_type* ttype,
- bool b_cls = false,
- bool b_no_postfix = false,
- bool b_exception_factory = false,
- bool b_full_exception_factory = false);
- std::string normalize_clsnm(std::string name,
- std::string prefix,
- bool b_no_check_keyword = false);
- std::string make_valid_delphi_identifier(std::string const& fromName);
- std::string input_arg_prefix(t_type* ttype);
-
- std::string base_type_name(t_base_type* tbase);
- std::string declare_field(t_field* tfield,
- bool init = false,
- std::string prefix = "",
- bool is_xception_class = false);
- std::string function_signature(t_function* tfunction,
- std::string full_cls = "",
- bool is_xception = false);
- std::string argument_list(t_struct* tstruct);
- std::string constructor_argument_list(t_struct* tstruct, std::string current_indent);
- std::string type_to_enum(t_type* ttype);
- std::string prop_name(t_field* tfield, bool is_xception = false);
- std::string prop_name(std::string name, bool is_xception = false);
- std::string constructor_param_name(string name);
-
- void write_enum(std::string line);
- void write_forward_decr(std::string line);
- void write_const(std::string line);
- void write_struct(std::string line);
- void write_service(std::string line);
-
- virtual std::string autogen_comment() {
- return std::string("(**\n") + " * Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n"
- + " *\n" + " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n"
- + " *)\n";
- }
-
- string replace_all(string contents, string search, string replace);
- string xml_encode(string contents);
- string xmldoc_encode(string contents);
- string xmlattrib_encode(string contents);
- void generate_delphi_doc(std::ostream& out, t_field* field);
- void generate_delphi_doc(std::ostream& out, t_doc* tdoc);
- void generate_delphi_doc(std::ostream& out, t_function* tdoc);
- void generate_delphi_docstring_comment(std::ostream& out, string contents);
-
- bool type_can_be_null(t_type* ttype) {
- while (ttype->is_typedef()) {
- ttype = ((t_typedef*)ttype)->get_type();
- }
+static const string endl = "\n"; // avoid ostream << std::endl flushes
+
+class t_delphi_generator : public t_oop_generator
+{
+ public:
+ t_delphi_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;
+ indent_impl_ = 0;
+ has_forward = false;
+ has_enum = false;
+ has_const = false;
+ std::map<std::string, std::string>::const_iterator iter;
+
+ iter = parsed_options.find("ansistr_binary");
+ ansistr_binary_ = (iter != parsed_options.end());
+ iter = parsed_options.find("register_types");
+ register_types_ = (iter != parsed_options.end());
+ iter = parsed_options.find("constprefix");
+ constprefix_ = (iter != parsed_options.end());
+ iter = parsed_options.find("events");
+ events_ = (iter != parsed_options.end());
+ iter = parsed_options.find("xmldoc");
+ xmldoc_ = (iter != parsed_options.end());
+
+
+ out_dir_base_ = "gen-delphi";
+ escape_.clear();
+ escape_['\''] = "''";
+ }
+
+
+ void init_generator();
+ void close_generator();
+
+ void generate_consts(std::vector<t_const*> consts);
+
+ void generate_typedef (t_typedef* ttypedef);
+ void generate_enum (t_enum* tenum);
+ void generate_forward_declaration(t_struct* tstruct);
+ void generate_struct (t_struct* tstruct);
+ void generate_xception (t_struct* txception);
+ void generate_service (t_service* tservice);
+ void generate_property(ostream& out, t_field* tfield, bool isPublic, bool is_xception);
+ void generate_property_writer_(ostream& out, t_field* tfield, bool isPublic);
+
+ void generate_delphi_property(ostream& out, bool struct_is_exception, t_field* tfield, bool isPublic, std::string fieldPrefix = "");
+ void generate_delphi_isset_reader_definition(ostream& out, t_field* tfield, bool is_xception);
+ void generate_delphi_property_reader_definition(ostream& out, t_field* tfield, bool is_xception_class);
+ void generate_delphi_property_writer_definition(ostream& out, t_field* tfield, bool is_xception_class);
+ void generate_delphi_property_reader_impl(ostream& out, std::string cls_prefix, std::string name, t_type* type, t_field* tfield, std::string fieldPrefix, bool is_xception_class);
+ void generate_delphi_property_writer_impl(ostream& out, std::string cls_prefix, std::string name, t_type* type, t_field* tfield, std::string fieldPrefix, bool is_xception_class, bool is_union, bool is_xception_factory, std::string xception_factroy_name);
+ void generate_delphi_clear_union_value(ostream& out, std::string cls_prefix, std::string name, t_type* type, t_field* tfield, std::string fieldPrefix, bool is_xception_class, bool is_union, bool is_xception_factory, std::string xception_factroy_name);
+ void generate_delphi_isset_reader_impl(ostream& out, std::string cls_prefix, std::string name, t_type* type, t_field* tfield, std::string fieldPrefix, bool is_xception);
+ void generate_delphi_struct_writer_impl(ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception);
+ void generate_delphi_struct_result_writer_impl(ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception);
+
+ void generate_delphi_struct_tostring_impl(ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception, bool is_x_factory);
+
+ void add_delphi_uses_list( string unitname);
+
+ void generate_delphi_struct_reader_impl(ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception);
+ void generate_delphi_create_exception_impl(ostream& out, string cls_prefix, t_struct* tstruct, bool is_exception);
+
+ bool const_needs_var(t_type* type);
+ void print_const_prop(std::ostream& out, string name, t_type* type, t_const_value* value);
+ void print_private_field(std::ostream& out, string name, t_type* type, t_const_value* value);
+ void print_const_value ( std::ostream& vars, std::ostream& out, std::string name, t_type* type, t_const_value* value);
+ void initialize_field(std::ostream& vars, std::ostream& out, std::string name, t_type* type, t_const_value* value);
+ void finalize_field(std::ostream& out, std::string name, t_type* type, t_const_value* value, std::string cls_nm = "");
+ std::string render_const_value( std::ostream& local_vars, std::ostream& out, std::string name, t_type* type, t_const_value* value);
+ void print_const_def_value( std::ostream& vars, std::ostream& out, std::string name, t_type* type, t_const_value* value, std::string cls_nm = "");
+ std::string make_constants_classname();
+
+ void generate_delphi_struct(t_struct* tstruct, bool is_exception);
+ void generate_delphi_struct_impl( ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception, bool is_result = false, bool is_x_factory = false);
+ void print_delphi_struct_type_factory_func( ostream& out, t_struct* tstruct);
+ void generate_delphi_struct_type_factory( ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception, bool is_result = false, bool is_x_factory = false);
+ void generate_delphi_struct_type_factory_registration( ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception, bool is_result = false, bool is_x_factory = false);
+ void generate_delphi_struct_definition(std::ostream& out, t_struct* tstruct, bool is_xception=false, bool in_class=false, bool is_result=false, bool is_x_factory = false);
+ void generate_delphi_struct_reader(std::ostream& out, t_struct* tstruct);
+ void generate_delphi_struct_result_writer(std::ostream& out, t_struct* tstruct);
+ void generate_delphi_struct_writer(std::ostream& out, t_struct* tstruct);
+ void generate_delphi_struct_tostring(std::ostream& out, t_struct* tstruct);
+
+ void generate_function_helpers(t_function* tfunction);
+ void generate_service_interface (t_service* tservice);
+ void generate_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* function);
+
+ void generate_deserialize_field (std::ostream& out, bool is_xception, t_field* tfield, std::string prefix, std::ostream& local_vars);
+ void generate_deserialize_struct (std::ostream& out, t_struct* tstruct, std::string name, std::string prefix);
+ void generate_deserialize_container(ostream& out, bool is_xception, t_type* ttype, string name, std::ostream& local_vars);
+
+ void generate_deserialize_set_element (std::ostream& out, bool is_xception, t_set* tset, std::string prefix, std::ostream& local_vars);
+ void generate_deserialize_map_element (std::ostream& out, bool is_xception, t_map* tmap, std::string prefix, std::ostream& local_vars);
+ void generate_deserialize_list_element (std::ostream& out, bool is_xception, t_list* list, std::string prefix, std::ostream& local_vars);
+
+ void generate_serialize_field (std::ostream& out, bool is_xception, t_field* tfield, std::string prefix, std::ostream& local_vars);
+ void generate_serialize_struct (std::ostream& out, t_struct* tstruct, std::string prefix, std::ostream& local_vars);
+ void generate_serialize_container (std::ostream& out, bool is_xception, t_type* ttype, std::string prefix, std::ostream& local_vars);
+ void generate_serialize_map_element (std::ostream& out, bool is_xception, t_map* tmap, std::string iter, std::string map, std::ostream& local_vars);
+ void generate_serialize_set_element (std::ostream& out, bool is_xception, t_set* tmap, std::string iter, std::ostream& local_vars);
+ void generate_serialize_list_element (std::ostream& out, bool is_xception, t_list* tlist, std::string iter, std::ostream& local_vars);
+
+ void delphi_type_usings(std::ostream& out);
+ std::string delphi_thrift_usings();
+
+ std::string type_name( t_type* ttype, bool b_cls=false, bool b_no_postfix=false, bool b_exception_factory=false, bool b_full_exception_factory = false);
+ std::string normalize_clsnm(std::string name, std::string prefix, bool b_no_check_keyword = false);
+ std::string make_valid_delphi_identifier( std::string const & fromName);
+ std::string input_arg_prefix( t_type* ttype);
+
+ std::string base_type_name(t_base_type* tbase);
+ std::string declare_field(t_field* tfield, bool init=false, std::string prefix="", bool is_xception_class = false);
+ std::string function_signature(t_function* tfunction, std::string full_cls="", bool is_xception = false);
+ std::string argument_list(t_struct* tstruct);
+ std::string constructor_argument_list(t_struct* tstruct, std::string current_indent);
+ std::string type_to_enum(t_type* ttype);
+ std::string prop_name(t_field* tfield, bool is_xception = false);
+ std::string prop_name(std::string name, bool is_xception = false);
+ std::string constructor_param_name(string name);
+
+ void write_enum(std::string line);
+ void write_forward_decr(std::string line);
+ void write_const(std::string line);
+ void write_struct(std::string line);
+ void write_service(std::string line);
+
+ virtual std::string autogen_comment() {
+ return
+ std::string("(**\n") +
+ " * Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n" +
+ " *\n" +
+ " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n" +
+ " *)\n";
+ }
+
+ string replace_all( string contents, string search, string replace);
+ string xml_encode( string contents);
+ string xmldoc_encode( string contents);
+ string xmlattrib_encode( string contents);
+ void generate_delphi_doc (std::ostream& out, t_field* field);
+ void generate_delphi_doc (std::ostream& out, t_doc* tdoc);
+ void generate_delphi_doc (std::ostream& out, t_function* tdoc);
+ void generate_delphi_docstring_comment (std::ostream &out, string contents);
+
+ bool type_can_be_null(t_type* ttype) {
+ while (ttype->is_typedef()) {
+ ttype = ((t_typedef*)ttype)->get_type();
+ }
- return ttype->is_container() || ttype->is_struct() || ttype->is_xception();
- }
-
-private:
- std::string namespace_name_;
- std::ostringstream s_forward_decr;
- std::ostringstream s_enum;
- std::ostringstream s_const;
- std::ostringstream s_struct;
- std::ostringstream s_service;
- std::ostringstream s_const_impl;
- std::ostringstream s_struct_impl;
- std::ostringstream s_service_impl;
- std::ostringstream s_type_factory_registration;
- std::ostringstream s_type_factory_funcs;
- bool has_forward;
- bool has_enum;
- bool has_const;
- std::string namespace_dir_;
- std::map<std::string, int> delphi_keywords;
- std::map<std::string, int> delphi_reserved_method;
- std::map<std::string, int> delphi_reserved_method_exception;
- std::map<std::string, int> types_known;
- std::list<t_typedef*> typedefs_pending;
- std::vector<std::string> uses_list;
- void create_keywords();
- bool find_keyword(std::map<std::string, int>& keyword_map, std::string name);
- std::string normalize_name(std::string name,
- bool b_method = false,
- bool b_exception_method = false);
- std::string empty_value(t_type* type);
- bool is_fully_defined_type(t_type* ttype);
- void add_defined_type(t_type* ttype);
- void init_known_types_list();
- bool is_void(t_type* type);
- int indent_impl_;
- bool ansistr_binary_;
- bool register_types_;
- bool constprefix_;
- bool events_;
- bool xmldoc_;
- void indent_up_impl() { ++indent_impl_; };
- void indent_down_impl() { --indent_impl_; };
- std::string indent_impl() {
- std::string ind = "";
- int i;
- for (i = 0; i < indent_impl_; ++i) {
- ind += " ";
- }
- return ind;
- };
- std::ostream& indent_impl(std::ostream& os) { return os << indent_impl(); };
+ return ttype->is_container() ||
+ ttype->is_struct() ||
+ ttype->is_xception();
+ }
+
+ private:
+ std::string namespace_name_;
+ std::ostringstream s_forward_decr;
+ std::ostringstream s_enum;
+ std::ostringstream s_const;
+ std::ostringstream s_struct;
+ std::ostringstream s_service;
+ std::ostringstream s_const_impl;
+ std::ostringstream s_struct_impl;
+ std::ostringstream s_service_impl;
+ std::ostringstream s_type_factory_registration;
+ std::ostringstream s_type_factory_funcs;
+ bool has_forward;
+ bool has_enum;
+ bool has_const;
+ std::string namespace_dir_;
+ std::map<std::string, int> delphi_keywords;
+ std::map<std::string, int> delphi_reserved_method;
+ std::map<std::string, int> delphi_reserved_method_exception;
+ std::map<std::string, int> types_known;
+ std::list<t_typedef*> typedefs_pending;
+ std::vector<std::string> uses_list;
+ void create_keywords();
+ bool find_keyword( std::map<std::string, int>& keyword_map, std::string name);
+ std::string normalize_name( std::string name, bool b_method = false, bool b_exception_method = false);
+ std::string empty_value(t_type* type);
+ bool is_fully_defined_type( t_type* ttype);
+ void add_defined_type( t_type* ttype);
+ void init_known_types_list();
+ bool is_void( t_type* type );
+ int indent_impl_;
+ bool ansistr_binary_;
+ bool register_types_;
+ bool constprefix_;
+ bool events_;
+ bool xmldoc_;
+ void indent_up_impl(){
+ ++indent_impl_;
+ };
+ void indent_down_impl() {
+ --indent_impl_;
+ };
+ std::string indent_impl() {
+ std::string ind = "";
+ int i;
+ for (i = 0; i < indent_impl_; ++i) {
+ ind += " ";
+ }
+ return ind;
+ };
+ std::ostream& indent_impl(std::ostream &os) {
+ return os << indent_impl();
+ };
};
-string t_delphi_generator::replace_all(string contents, string search, string repl) {
- string str(contents);
+string t_delphi_generator::replace_all( string contents, string search, string repl) {
+ string str( contents);
size_t slen = search.length();
size_t rlen = repl.length();
size_t incr = (rlen > 0) ? rlen : 1;
- if (slen > 0) {
+ if( slen > 0) {
size_t found = str.find(search);
- while ((found != string::npos) && (found < str.length())) {
- str.replace(found, slen, repl);
- found = str.find(search, found + incr);
+ while( (found != string::npos) && (found < str.length())) {
+ str.replace( found, slen, repl);
+ found = str.find(search, found+incr);
}
}
@@ -421,56 +282,57 @@ string t_delphi_generator::replace_all(string contents, string search, string re
}
// XML encoding
-string t_delphi_generator::xml_encode(string contents) {
- string str(contents);
+string t_delphi_generator::xml_encode( string contents) {
+ string str( contents);
// escape the escape
- str = replace_all(str, "&", "&");
+ str = replace_all( str, "&", "&");
// other standard XML entities
- str = replace_all(str, "<", "<");
- str = replace_all(str, ">", ">");
+ str = replace_all( str, "<", "<");
+ str = replace_all( str, ">", ">");
return str;
}
// XML attribute encoding
-string t_delphi_generator::xmlattrib_encode(string contents) {
- string str(xml_encode(contents));
+string t_delphi_generator::xmlattrib_encode( string contents) {
+ string str( xml_encode( contents));
// our attribs are enclosed in "
- str = replace_all(str, "\"", "\\\"");
+ str = replace_all( str, "\"", "\\\"");
return str;
}
// XML encoding for doc comments
-string t_delphi_generator::xmldoc_encode(string contents) {
- string str(xml_encode(contents));
+string t_delphi_generator::xmldoc_encode( string contents) {
+ string str( xml_encode( contents));
// XMLDoc specific: convert linebreaks into <para>graphs</para>
- str = replace_all(str, "\r\n", "\r");
- str = replace_all(str, "\n", "\r");
- str = replace_all(str, "\r", "</para>\n<para>");
+ str = replace_all( str, "\r\n", "\r");
+ str = replace_all( str, "\n", "\r");
+ str = replace_all( str, "\r", "</para>\n<para>");
return str;
}
-void t_delphi_generator::generate_delphi_docstring_comment(ostream& out, string contents) {
- if (xmldoc_) {
+void t_delphi_generator::generate_delphi_docstring_comment(ostream &out, string contents) {
+ if( xmldoc_) {
generate_docstring_comment(out,
"{$REGION 'XMLDoc'}/// <summary>\n",
- "/// ",
- "<para>" + contents + "</para>",
+ "/// ", "<para>" + contents + "</para>",
"/// </summary>\n{$ENDREGION}\n");
}
}
-void t_delphi_generator::generate_delphi_doc(ostream& out, t_field* field) {
- if (xmldoc_) {
+void t_delphi_generator::generate_delphi_doc(ostream &out, t_field* field) {
+ if( xmldoc_) {
if (field->get_type()->is_enum()) {
- string combined_message = xmldoc_encode(field->get_doc()) + "\n<seealso cref=\""
- + xmldoc_encode(type_name(field->get_type())) + "\"/>";
+ string combined_message = xmldoc_encode( field->get_doc())
+ + "\n<seealso cref=\""
+ + xmldoc_encode( type_name(field->get_type()))
+ + "\"/>";
generate_delphi_docstring_comment(out, combined_message);
} else {
generate_delphi_doc(out, (t_doc*)field);
@@ -478,24 +340,23 @@ void t_delphi_generator::generate_delphi_doc(ostream& out, t_field* field) {
}
}
-void t_delphi_generator::generate_delphi_doc(ostream& out, t_doc* tdoc) {
+void t_delphi_generator::generate_delphi_doc(ostream &out, t_doc* tdoc) {
if (tdoc->has_doc() && xmldoc_) {
- generate_delphi_docstring_comment(out, xmldoc_encode(tdoc->get_doc()));
+ generate_delphi_docstring_comment(out, xmldoc_encode( tdoc->get_doc()));
}
}
-void t_delphi_generator::generate_delphi_doc(ostream& out, t_function* tfunction) {
+void t_delphi_generator::generate_delphi_doc(ostream &out, t_function* tfunction) {
if (tfunction->has_doc() && xmldoc_) {
stringstream ps;
const vector<t_field*>& fields = tfunction->get_arglist()->get_members();
vector<t_field*>::const_iterator p_iter;
for (p_iter = fields.begin(); p_iter != fields.end(); ++p_iter) {
t_field* p = *p_iter;
- ps << "\n<param name=\"" << xmlattrib_encode(p->get_name()) << "\">";
+ ps << "\n<param name=\"" << xmlattrib_encode( p->get_name()) << "\">";
if (p->has_doc()) {
std::string str = p->get_doc();
- str.erase(std::remove(str.begin(), str.end(), '\n'),
- str.end()); // remove the newlines that appear from the parser
+ str.erase(std::remove(str.begin(), str.end(), '\n'), str.end()); // remove the newlines that appear from the parser
ps << xmldoc_encode(str);
}
ps << "</param>";
@@ -503,43 +364,40 @@ void t_delphi_generator::generate_delphi_doc(ostream& out, t_function* tfunction
generate_docstring_comment(out,
"{$REGION 'XMLDoc'}",
"/// ",
- "<summary><para>" + xmldoc_encode(tfunction->get_doc())
- + "</para></summary>" + ps.str(),
+ "<summary><para>" + xmldoc_encode(tfunction->get_doc()) + "</para></summary>" + ps.str(),
"{$ENDREGION}\n");
}
}
-bool t_delphi_generator::find_keyword(std::map<std::string, int>& keyword_map, std::string name) {
+bool t_delphi_generator::find_keyword( std::map<std::string, int>& keyword_map, std::string name) {
int len = name.length();
- if (len <= 0) {
+ if ( len <= 0 ) {
return false;
}
int nlast = name.find_last_of('_');
- if (nlast >= 1) {
+ if ( nlast >= 1) {
if (nlast == (len - 1)) {
- string new_name(name, 0, nlast);
- return find_keyword(keyword_map, new_name);
+ string new_name( name, 0, nlast);
+ return find_keyword( keyword_map, new_name);
}
}
return (keyword_map[name] == 1);
}
-std::string t_delphi_generator::normalize_name(std::string name,
- bool b_method,
- bool b_exception_method) {
- string tmp(name);
+std::string t_delphi_generator::normalize_name( std::string name, bool b_method, bool b_exception_method) {
+ string tmp( name );
std::transform(tmp.begin(), tmp.end(), tmp.begin(), static_cast<int (*)(int)>(std::tolower));
bool b_found = false;
- if (find_keyword(delphi_keywords, tmp)) {
+ if ( find_keyword( delphi_keywords, tmp) ) {
b_found = true;
- } else if (b_method && find_keyword(delphi_reserved_method, tmp)) {
+ } else if ( b_method && find_keyword( delphi_reserved_method, tmp)) {
b_found = true;
- } else if (b_exception_method && find_keyword(delphi_reserved_method_exception, tmp)) {
+ } else if ( b_exception_method && find_keyword( delphi_reserved_method_exception, tmp)) {
b_found = true;
}
@@ -684,17 +542,17 @@ void t_delphi_generator::create_keywords() {
delphi_reserved_method_exception["throwouterexception"] = 1;
}
-void t_delphi_generator::add_delphi_uses_list(string unitname) {
+void t_delphi_generator::add_delphi_uses_list( string unitname){
vector<std::string>::const_iterator s_iter;
bool found = false;
for (s_iter = uses_list.begin(); s_iter != uses_list.end(); ++s_iter) {
- if ((*s_iter) == unitname) {
+ if ((*s_iter) == unitname ) {
found = true;
break;
}
}
- if (!found) {
- uses_list.push_back(unitname);
+ if (! found) {
+ uses_list.push_back( unitname );
}
}
@@ -714,7 +572,8 @@ void t_delphi_generator::init_generator() {
add_delphi_uses_list("Thrift.Protocol");
add_delphi_uses_list("Thrift.Transport");
- if (register_types_) {
+ if (register_types_)
+ {
add_delphi_uses_list("Thrift.TypeRegistry");
}
@@ -725,37 +584,38 @@ void t_delphi_generator::init_generator() {
for (size_t i = 0; i < includes.size(); ++i) {
unitname = includes[i]->get_name();
nsname = includes[i]->get_namespace("delphi");
- if ("" != nsname) {
+ if ( "" != nsname) {
unitname = nsname;
}
add_delphi_uses_list(unitname);
}
+
MKDIR(get_out_dir().c_str());
}
void t_delphi_generator::close_generator() {
std::string unitname = program_name_;
- if ("" != namespace_name_) {
+ if( "" != namespace_name_) {
unitname = namespace_name_;
}
- for (int i = 0; i < (int)unitname.size(); i++) {
- if (unitname[i] == ' ') {
- unitname.replace(i, 1, "_");
+ for ( int i = 0; i < (int)unitname.size(); i++) {
+ if ( unitname[i] == ' ' ) {
+ unitname.replace( i, 1, "_" );
}
}
std::string f_name = get_out_dir() + "/" + unitname + ".pas";
std::ofstream f_all;
- f_all.open(f_name.c_str());
+ f_all.open( f_name.c_str() );
f_all << autogen_comment() << endl;
generate_delphi_doc(f_all, program_);
f_all << "unit " << unitname << ";" << endl << endl;
f_all << "interface" << endl << endl;
- f_all << "uses" << endl;
+ f_all << "uses" << endl;
indent_up();
@@ -772,97 +632,89 @@ void t_delphi_generator::close_generator() {
indent_down();
- string tmp_unit(unitname);
- for (int i = 0; i < (int)tmp_unit.size(); i++) {
- if (tmp_unit[i] == '.') {
- tmp_unit.replace(i, 1, "_");
+ string tmp_unit( unitname );
+ for ( int i = 0; i < (int)tmp_unit.size(); i++) {
+ if ( tmp_unit[i] == '.' ) {
+ tmp_unit.replace( i, 1, "_" );
}
}
- f_all << "const" << endl;
+ f_all << "const" << endl;
indent_up();
- indent(f_all) << "c" << tmp_unit
- << "_Option_AnsiStr_Binary = " << (ansistr_binary_ ? "True" : "False") << ";"
- << endl;
- indent(f_all) << "c" << tmp_unit
- << "_Option_Register_Types = " << (register_types_ ? "True" : "False") << ";"
- << endl;
- indent(f_all) << "c" << tmp_unit
- << "_Option_ConstPrefix = " << (constprefix_ ? "True" : "False") << ";" << endl;
- indent(f_all) << "c" << tmp_unit << "_Option_Events = " << (events_ ? "True" : "False")
- << ";" << endl;
- indent(f_all) << "c" << tmp_unit << "_Option_XmlDoc = " << (xmldoc_ ? "True" : "False")
- << ";" << endl;
+ indent(f_all) << "c" << tmp_unit << "_Option_AnsiStr_Binary = " << ( ansistr_binary_ ? "True" : "False") << ";" << endl;
+ indent(f_all) << "c" << tmp_unit << "_Option_Register_Types = " << ( register_types_ ? "True" : "False") << ";" << endl;
+ indent(f_all) << "c" << tmp_unit << "_Option_ConstPrefix = " << ( constprefix_ ? "True" : "False") << ";" << endl;
+ indent(f_all) << "c" << tmp_unit << "_Option_Events = " << ( events_ ? "True" : "False") << ";" << endl;
+ indent(f_all) << "c" << tmp_unit << "_Option_XmlDoc = " << ( xmldoc_ ? "True" : "False") << ";" << endl;
indent_down();
- f_all << endl;
- f_all << "type" << endl;
- if (has_forward) {
- f_all << s_forward_decr.str() << endl;
+ f_all << endl;
+ f_all << "type" << endl;
+ if(has_forward) {
+ f_all << s_forward_decr.str() << endl;
}
if (has_enum) {
indent(f_all) << endl;
indent(f_all) << "{$SCOPEDENUMS ON}" << endl << endl;
- f_all << s_enum.str();
+ f_all << s_enum.str();
indent(f_all) << "{$SCOPEDENUMS OFF}" << endl << endl;
}
- f_all << s_struct.str();
- f_all << s_service.str();
- f_all << s_const.str();
- f_all << "implementation" << endl << endl;
- f_all << s_struct_impl.str();
- f_all << s_service_impl.str();
- f_all << s_const_impl.str();
+ f_all << s_struct.str();
+ f_all << s_service.str();
+ f_all << s_const.str();
+ f_all << "implementation" << endl << endl;
+ f_all << s_struct_impl.str();
+ f_all << s_service_impl.str();
+ f_all << s_const_impl.str();
- if (register_types_) {
- f_all << endl;
- f_all << "// Type factory methods and registration" << endl;
- f_all << s_type_factory_funcs.str();
+
+ if (register_types_)
+ {
+ f_all << endl;
+ f_all << "// Type factory methods and registration" << endl;
+ f_all << s_type_factory_funcs.str();
f_all << "procedure RegisterTypeFactories;" << endl;
f_all << "begin" << endl;
f_all << s_type_factory_registration.str();
f_all << "end;" << endl;
}
- f_all << endl;
+ f_all << endl;
string constants_class = make_constants_classname();
- f_all << "initialization" << endl;
- if (has_const) {
- f_all << "{$IF CompilerVersion < 21.0} // D2010" << endl;
- f_all << " " << constants_class.c_str() << "_Initialize;" << endl;
- f_all << "{$IFEND}" << endl;
+ f_all << "initialization" << endl;
+ if ( has_const ) {
+ f_all << "{$IF CompilerVersion < 21.0} // D2010" << endl;
+ f_all << " " << constants_class.c_str() << "_Initialize;" << endl;
+ f_all << "{$IFEND}" << endl;
}
if (register_types_) {
f_all << " RegisterTypeFactories;" << endl;
}
- f_all << endl;
+ f_all << endl;
- f_all << "finalization" << endl;
- if (has_const) {
- f_all << "{$IF CompilerVersion < 21.0} // D2010" << endl;
- f_all << " " << constants_class.c_str() << "_Finalize;" << endl;
- f_all << "{$IFEND}" << endl;
+ f_all << "finalization" << endl;
+ if ( has_const ) {
+ f_all << "{$IF CompilerVersion < 21.0} // D2010" << endl;
+ f_all << " " << constants_class.c_str() << "_Finalize;" << endl;
+ f_all << "{$IFEND}" << endl;
}
- f_all << endl << endl;
+ f_all << endl << endl;
- f_all << "end." << endl;
+ f_all << "end." << endl;
f_all.close();
- if (!typedefs_pending.empty()) {
+ if( ! typedefs_pending.empty()) {
pwarning(0, "%d typedefs with unresolved type references left:\n", typedefs_pending.size());
- for (std::list<t_typedef*>::iterator iter = typedefs_pending.begin();
- typedefs_pending.end() != iter;
- ++iter) {
+ for( std::list<t_typedef*>::iterator iter = typedefs_pending.begin(); typedefs_pending.end() != iter; ++iter) {
pwarning(0, "- %s\n", (*iter)->get_symbolic().c_str());
}
}
}
-void t_delphi_generator::delphi_type_usings(ostream& out) {
+void t_delphi_generator::delphi_type_usings( ostream& out) {
indent_up();
- indent(out) << "Classes, SysUtils, Generics.Collections, Thrift.Collections, Thrift.Protocol,"
- << endl;
+ indent(out) << "Classes, SysUtils, Generics.Collections, Thrift.Collections, Thrift.Protocol," << endl;
indent(out) << "Thrift.Transport;" << endl << endl;
indent_down();
}
@@ -875,8 +727,8 @@ void t_delphi_generator::generate_forward_declaration(t_struct* tstruct) {
string what = tstruct->is_xception() ? "class" : "interface";
indent_up();
- indent(s_forward_decr) << type_name(tstruct, tstruct->is_xception(), true) << " = " << what << ";"
- << endl;
+ indent(s_forward_decr) <<
+ type_name(tstruct,tstruct->is_xception(),true) << " = " << what << ";" << endl;
indent_down();
add_defined_type(tstruct);
@@ -886,77 +738,80 @@ void t_delphi_generator::generate_typedef(t_typedef* ttypedef) {
t_type* type = ttypedef->get_type();
// write now or save for later?
- if (!is_fully_defined_type(type)) {
+ if( ! is_fully_defined_type( type)) {
pverbose("typedef %s: unresolved dependencies found\n", type_name(ttypedef).c_str());
- typedefs_pending.push_back(ttypedef);
+ typedefs_pending.push_back( ttypedef);
return;
}
indent_up();
generate_delphi_doc(s_struct, ttypedef);
- indent(s_struct) << type_name(ttypedef) << " = ";
+ indent(s_struct) <<
+ type_name(ttypedef) << " = ";
// commented out: the benefit is not big enough to risk breaking existing code
- // bool container = type->is_list() || type->is_map() || type->is_set();
- // if( ! container)
+ //bool container = type->is_list() || type->is_map() || type->is_set();
+ //if( ! container)
// s_struct << "type "; //the "type A = type B" syntax leads to E2574 with generics
- s_struct << type_name(ttypedef->get_type()) << ";" << endl << endl;
+ s_struct << type_name(ttypedef->get_type()) << ";" << endl <<
+ endl;
indent_down();
- add_defined_type(ttypedef);
+ add_defined_type( ttypedef);
}
-bool t_delphi_generator::is_fully_defined_type(t_type* ttype) {
- if ((NULL != ttype->get_program()) && (ttype->get_program() != program_)) {
+bool t_delphi_generator::is_fully_defined_type( t_type* ttype) {
+ if( (NULL != ttype->get_program()) && (ttype->get_program() != program_)) {
t_scope* scope = ttype->get_program()->scope();
- if (NULL != scope->get_type(ttype->get_name())) {
- // printf("type %s found in included scope %s\n", ttype->get_name().c_str(),
- // ttype->get_program()->get_name().c_str());
+ if( NULL != scope->get_type( ttype->get_name())) {
+ //printf("type %s found in included scope %s\n", ttype->get_name().c_str(), ttype->get_program()->get_name().c_str());
return true;
}
}
if (ttype->is_typedef()) {
- return (1 == types_known[type_name(ttype)]);
+ return (1 == types_known[ type_name(ttype)]);
}
if (ttype->is_base_type()) {
- return (1 == types_known[base_type_name((t_base_type*)ttype)]);
+ return (1 == types_known[ base_type_name((t_base_type*)ttype)]);
} else if (ttype->is_enum()) {
- return true; // enums are written first, before all other types
+ return true; // enums are written first, before all other types
} else if (ttype->is_map()) {
- t_map* tmap = (t_map*)ttype;
- return is_fully_defined_type(tmap->get_key_type())
- && is_fully_defined_type(tmap->get_val_type());
+ t_map *tmap = (t_map*) ttype;
+ return is_fully_defined_type( tmap->get_key_type()) &&
+ is_fully_defined_type( tmap->get_val_type());
} else if (ttype->is_set()) {
- t_set* tset = (t_set*)ttype;
- return is_fully_defined_type(tset->get_elem_type());
+ t_set* tset = (t_set*) ttype;
+ return is_fully_defined_type( tset->get_elem_type());
} else if (ttype->is_list()) {
- t_list* tlist = (t_list*)ttype;
- return is_fully_defined_type(tlist->get_elem_type());
+ t_list* tlist = (t_list*) ttype;
+ return is_fully_defined_type( tlist->get_elem_type());
}
- return (1 == types_known[type_name(ttype)]);
+ return (1 == types_known[ type_name(ttype)]);
}
-void t_delphi_generator::add_defined_type(t_type* ttype) {
+void t_delphi_generator::add_defined_type( t_type* ttype) {
// mark as known type
- types_known[type_name(ttype)] = 1;
+ types_known[ type_name(ttype)] = 1;
// check all pending typedefs
- std::list<t_typedef*>::iterator iter;
+ std::list<t_typedef*>::iterator iter;
bool more = true;
- while (more && (!typedefs_pending.empty())) {
+ while( more && (! typedefs_pending.empty()))
+ {
more = false;
- for (iter = typedefs_pending.begin(); typedefs_pending.end() != iter; ++iter) {
+ for( iter = typedefs_pending.begin(); typedefs_pending.end() != iter; ++iter)
+ {
t_typedef* ttypedef = (*iter);
- if (is_fully_defined_type(ttypedef->get_type())) {
- pverbose("typedef %s: all pending references are now resolved\n",
- type_name(ttypedef).c_str());
- typedefs_pending.erase(iter);
- generate_typedef(ttypedef);
+ if( is_fully_defined_type( ttypedef->get_type()))
+ {
+ pverbose("typedef %s: all pending references are now resolved\n", type_name(ttypedef).c_str());
+ typedefs_pending.erase( iter);
+ generate_typedef( ttypedef);
more = true;
break;
}
@@ -966,22 +821,22 @@ void t_delphi_generator::add_defined_type(t_type* ttype) {
void t_delphi_generator::init_known_types_list() {
// known base types
- types_known[type_name(g_type_string)] = 1;
- types_known[type_name(g_type_binary)] = 1;
- types_known[type_name(g_type_bool)] = 1;
- types_known[type_name(g_type_byte)] = 1;
- types_known[type_name(g_type_i16)] = 1;
- types_known[type_name(g_type_i32)] = 1;
- types_known[type_name(g_type_i64)] = 1;
- types_known[type_name(g_type_double)] = 1;
+ types_known[ type_name( g_type_string)] = 1;
+ types_known[ type_name( g_type_binary)] = 1;
+ types_known[ type_name( g_type_bool)] = 1;
+ types_known[ type_name( g_type_byte)] = 1;
+ types_known[ type_name( g_type_i16)] = 1;
+ types_known[ type_name( g_type_i32)] = 1;
+ types_known[ type_name( g_type_i64)] = 1;
+ types_known[ type_name( g_type_double)] = 1;
}
void t_delphi_generator::generate_enum(t_enum* tenum) {
has_enum = true;
indent_up();
- generate_delphi_doc(s_enum, tenum);
- indent(s_enum) << type_name(tenum, true, true) << " = "
- << "(" << endl;
+ generate_delphi_doc( s_enum, tenum);
+ indent(s_enum) <<
+ type_name(tenum,true,true) << " = " << "(" << endl;
indent_up();
vector<t_enum_value*> constants = tenum->get_constants();
if (constants.empty()) {
@@ -1004,43 +859,48 @@ void t_delphi_generator::generate_enum(t_enum* tenum) {
indent_down();
}
-std::string t_delphi_generator::make_valid_delphi_identifier(std::string const& fromName) {
- std::string str = fromName;
- if (str.empty()) {
- return str;
- }
- // tests rely on this
- assert(('A' < 'Z') && ('a' < 'z') && ('0' < '9'));
+std::string t_delphi_generator::make_valid_delphi_identifier( std::string const & fromName) {
+ std::string str = fromName;
+ if( str.empty()) {
+ return str;
+ }
- // if the first letter is a number, we add an additional underscore in front of it
- char c = str.at(0);
- if (('0' <= c) && (c <= '9')) {
- str = "_" + str;
- }
+ // tests rely on this
+ assert( ('A' < 'Z') && ('a' < 'z') && ('0' < '9'));
- // following chars: letter, number or underscore
- for (size_t i = 0; i < str.size(); ++i) {
- c = str.at(i);
- if ((('A' > c) || (c > 'Z')) && (('a' > c) || (c > 'z')) && (('0' > c) || (c > '9'))
- && ('_' != c)) {
- str.replace(i, 1, "_");
+ // if the first letter is a number, we add an additional underscore in front of it
+ char c = str.at(0);
+ if( ('0' <= c) && (c <= '9')) {
+ str = "_" + str;
}
- }
- return str;
+ // following chars: letter, number or underscore
+ for( size_t i = 0; i < str.size(); ++i) {
+ c = str.at(i);
+ if( (('A' > c) || (c > 'Z')) &&
+ (('a' > c) || (c > 'z')) &&
+ (('0' > c) || (c > '9')) &&
+ ('_' != c) ) {
+ str.replace( i, 1, "_");
+ }
+ }
+
+ return str;
}
+
std::string t_delphi_generator::make_constants_classname() {
- if (constprefix_) {
- return make_valid_delphi_identifier("T" + program_name_ + "Constants");
+ if( constprefix_) {
+ return make_valid_delphi_identifier( "T" + program_name_ + "Constants");
} else {
- return "TConstants"; // compatibility
+ return "TConstants"; // compatibility
}
}
+
void t_delphi_generator::generate_consts(std::vector<t_const*> consts) {
- if (consts.empty()) {
+ if (consts.empty()){
return;
}
@@ -1048,16 +908,15 @@ void t_delphi_generator::generate_consts(std::vector<t_const*> consts) {
string constants_class = make_constants_classname();
indent_up();
- indent(s_const) << constants_class.c_str() << " = class" << endl;
+ indent(s_const) <<
+ constants_class.c_str() << " = class" << endl;
indent(s_const) << "private" << endl;
indent_up();
vector<t_const*>::iterator c_iter;
for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
- if (const_needs_var((*c_iter)->get_type())) {
- print_private_field(s_const,
- normalize_name((*c_iter)->get_name()),
- (*c_iter)->get_type(),
- (*c_iter)->get_value());
+ if( const_needs_var((*c_iter)->get_type())) {
+ print_private_field(s_const, normalize_name((*c_iter)->get_name()),
+ (*c_iter)->get_type(), (*c_iter)->get_value());
}
}
indent_down();
@@ -1065,10 +924,8 @@ void t_delphi_generator::generate_consts(std::vector<t_const*> consts) {
indent_up();
for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
generate_delphi_doc(s_const, *c_iter);
- print_const_prop(s_const,
- normalize_name((*c_iter)->get_name()),
- (*c_iter)->get_type(),
- (*c_iter)->get_value());
+ print_const_prop(s_const, normalize_name((*c_iter)->get_name()),
+ (*c_iter)->get_type(), (*c_iter)->get_value());
}
indent(s_const) << "{$IF CompilerVersion >= 21.0}" << endl;
indent(s_const) << "class constructor Create;" << endl;
@@ -1078,41 +935,34 @@ void t_delphi_generator::generate_consts(std::vector<t_const*> consts) {
indent(s_const) << "end;" << endl << endl;
indent_down();
- std::ostringstream vars, code;
+ std::ostringstream vars, code;
indent_up_impl();
for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
- initialize_field(vars,
- code,
- "F" + prop_name((*c_iter)->get_name()),
- (*c_iter)->get_type(),
- (*c_iter)->get_value());
+ initialize_field(vars, code, "F" + prop_name( (*c_iter)->get_name()),
+ (*c_iter)->get_type(), (*c_iter)->get_value());
}
indent_down_impl();
indent_impl(s_const_impl) << "{$IF CompilerVersion >= 21.0}" << endl;
- indent_impl(s_const_impl) << "class constructor " << constants_class.c_str() << ".Create;"
- << endl;
+ indent_impl(s_const_impl) << "class constructor " << constants_class.c_str() << ".Create;" << endl;
- if (!vars.str().empty()) {
+ if ( ! vars.str().empty() ) {
indent_impl(s_const_impl) << "var" << endl;
s_const_impl << vars.str();
}
indent_impl(s_const_impl) << "begin" << endl;
- if (!code.str().empty()) {
+ if ( ! code.str().empty() ) {
s_const_impl << code.str();
}
indent_impl(s_const_impl) << "end;" << endl << endl;
- indent_impl(s_const_impl) << "class destructor " << constants_class.c_str() << ".Destroy;"
- << endl;
+ indent_impl(s_const_impl) << "class destructor " << constants_class.c_str() << ".Destroy;" << endl;
indent_impl(s_const_impl) << "begin" << endl;
indent_up_impl();
for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
- if (const_needs_var((*c_iter)->get_type())) {
- finalize_field(s_const_impl,
- normalize_name((*c_iter)->get_name()),
- (*c_iter)->get_type(),
- (*c_iter)->get_value());
+ if( const_needs_var((*c_iter)->get_type())) {
+ finalize_field(s_const_impl, normalize_name( (*c_iter)->get_name()),
+ (*c_iter)->get_type(), (*c_iter)->get_value());
}
}
indent_impl(s_const_impl) << "inherited;" << endl;
@@ -1125,23 +975,20 @@ void t_delphi_generator::generate_consts(std::vector<t_const*> consts) {
indent_up_impl();
for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
- if (const_needs_var((*c_iter)->get_type())) {
- initialize_field(vars,
- code,
- constants_class + ".F" + prop_name((*c_iter)->get_name()),
- (*c_iter)->get_type(),
- (*c_iter)->get_value());
+ if( const_needs_var((*c_iter)->get_type())) {
+ initialize_field( vars, code, constants_class + ".F" + prop_name( (*c_iter)->get_name()),
+ (*c_iter)->get_type(), (*c_iter)->get_value());
}
}
indent_down_impl();
indent_impl(s_const_impl) << "procedure " << constants_class.c_str() << "_Initialize;" << endl;
- if (!vars.str().empty()) {
+ if ( ! vars.str().empty() ) {
indent_impl(s_const_impl) << "var" << endl;
s_const_impl << vars.str();
}
indent_impl(s_const_impl) << "begin" << endl;
- if (!code.str().empty()) {
+ if ( ! code.str().empty() ) {
s_const_impl << code.str();
}
indent_impl(s_const_impl) << "end;" << endl << endl;
@@ -1150,23 +997,16 @@ void t_delphi_generator::generate_consts(std::vector<t_const*> consts) {
indent_impl(s_const_impl) << "begin" << endl;
indent_up_impl();
for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
- finalize_field(s_const_impl,
- normalize_name((*c_iter)->get_name()),
- (*c_iter)->get_type(),
- (*c_iter)->get_value(),
- constants_class);
+ finalize_field(s_const_impl, normalize_name( (*c_iter)->get_name()),
+ (*c_iter)->get_type(), (*c_iter)->get_value(), constants_class);
}
indent_down_impl();
indent_impl(s_const_impl) << "end;" << endl;
indent_impl(s_const_impl) << "{$IFEND}" << endl << endl;
}
-void t_delphi_generator::print_const_def_value(std::ostream& vars,
- std::ostream& out,
- string name,
- t_type* type,
- t_const_value* value,
- string cls_nm) {
+void t_delphi_generator::print_const_def_value(std::ostream& vars, std::ostream& out, string name, t_type* type, t_const_value* value, string cls_nm)
+{
string cls_prefix;
@@ -1191,10 +1031,8 @@ void t_delphi_generator::print_const_def_value(std::ostream& vars,
if (field_type == NULL) {
throw "type error: " + type->get_name() + " has no field " + v_iter->first->get_string();
}
- string val = render_const_value(vars, out, name, field_type, v_iter->second);
- indent_impl(out) << cls_prefix << normalize_name(name) << "."
- << prop_name(v_iter->first->get_string(), type->is_xception())
- << " := " << val << ";" << endl;
+ string val = render_const_value( vars, out, name, field_type, v_iter->second);
+ indent_impl(out) << cls_prefix << normalize_name(name) << "." << prop_name( v_iter->first->get_string(), type->is_xception()) << " := " << val << ";" << endl;
}
} else if (type->is_map()) {
t_type* ktype = ((t_map*)type)->get_key_type();
@@ -1202,10 +1040,9 @@ void t_delphi_generator::print_const_def_value(std::ostream& vars,
const map<t_const_value*, t_const_value*>& val = value->get_map();
map<t_const_value*, t_const_value*>::const_iterator v_iter;
for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
- string key = render_const_value(vars, out, name, ktype, v_iter->first);
- string val = render_const_value(vars, out, name, vtype, v_iter->second);
- indent_impl(out) << cls_prefix << normalize_name(name) << "[" << key << "]"
- << " := " << val << ";" << endl;
+ string key = render_const_value( vars, out, name, ktype, v_iter->first);
+ string val = render_const_value( vars, out, name, vtype, v_iter->second);
+ indent_impl(out) << cls_prefix << normalize_name(name) << "[" << key << "]" << " := " << val << ";" << endl;
}
} else if (type->is_list() || type->is_set()) {
t_type* etype;
@@ -1218,48 +1055,39 @@ void t_delphi_generator::print_const_def_value(std::ostream& vars,
const vector<t_const_value*>& val = value->get_list();
vector<t_const_value*>::const_iterator v_iter;
for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
- string val = render_const_value(vars, out, name, etype, *v_iter);
+ string val = render_const_value( vars, out, name, etype, *v_iter);
indent_impl(out) << cls_prefix << normalize_name(name) << ".Add(" << val << ");" << endl;
}
}
}
-void t_delphi_generator::print_private_field(std::ostream& out,
- string name,
- t_type* type,
- t_const_value* value) {
- (void)value;
+void t_delphi_generator::print_private_field(std::ostream& out, string name, t_type* type, t_const_value* value) {
+ (void) value;
indent(out) << "class var F" << name << ": " << type_name(type) << ";" << endl;
}
+
bool t_delphi_generator::const_needs_var(t_type* type) {
t_type* truetype = type;
while (truetype->is_typedef()) {
truetype = ((t_typedef*)truetype)->get_type();
}
- return (!truetype->is_base_type());
+ return (! truetype->is_base_type());
}
-void t_delphi_generator::print_const_prop(std::ostream& out,
- string name,
- t_type* type,
- t_const_value* value) {
- (void)value;
+
+void t_delphi_generator::print_const_prop(std::ostream& out, string name, t_type* type, t_const_value* value) {
+ (void) value;
if (const_needs_var(type)) {
- indent(out) << "class property " << name << ": " << type_name(type) << " read F" << name << ";"
- << endl;
+ indent(out) << "class property " << name << ": " << type_name(type) << " read F" << name << ";" << endl;
} else {
std::ostringstream vars; // dummy
- string v2 = render_const_value(vars, out, name, type, value);
+ string v2 = render_const_value( vars, out, name, type, value);
indent(out) << "const " << name << " = " << v2 << ";" << endl;
}
}
-void t_delphi_generator::print_const_value(std::ostream& vars,
- std::ostream& out,
- string name,
- t_type* type,
- t_const_value* value) {
+void t_delphi_generator::print_const_value( std::ostream& vars, std::ostream& out, string name, t_type* type, t_const_value* value) {
t_type* truetype = type;
while (truetype->is_typedef()) {
truetype = ((t_typedef*)truetype)->get_type();
@@ -1267,45 +1095,32 @@ void t_delphi_generator::print_const_value(std::ostream& vars,
if (truetype->is_base_type()) {
// already done
- // string v2 = render_const_value( vars, out, name, type, value);
- // indent_impl(out) << name << " := " << v2 << ";" << endl;
+ //string v2 = render_const_value( vars, out, name, type, value);
+ //indent_impl(out) << name << " := " << v2 << ";" << endl;
} else if (truetype->is_enum()) {
- indent_impl(out) << name << " := " << type_name(type) << "." << value->get_identifier_name()
- << ";" << endl;
+ indent_impl(out) << name << " := " << type_name(type) << "." << value->get_identifier_name() << ";" << endl;
} else {
string typname;
- typname = type_name(truetype, true, false, type->is_xception(), type->is_xception());
+ typname = type_name( truetype, true, false, type->is_xception(), type->is_xception());
indent_impl(out) << name << " := " << typname << ".Create;" << endl;
- print_const_def_value(vars, out, name, truetype, value);
+ print_const_def_value( vars, out, name, truetype, value);
}
}
-void t_delphi_generator::initialize_field(std::ostream& vars,
- std::ostream& out,
- string name,
- t_type* type,
- t_const_value* value) {
- print_const_value(vars, out, name, type, value);
+void t_delphi_generator::initialize_field(std::ostream& vars, std::ostream& out, string name, t_type* type, t_const_value* value) {
+ print_const_value( vars, out, name, type, value );
}
-void t_delphi_generator::finalize_field(std::ostream& out,
- string name,
- t_type* type,
- t_const_value* value,
- string cls_nm) {
- (void)out;
- (void)name;
- (void)type;
- (void)value;
- (void)cls_nm;
+void t_delphi_generator::finalize_field(std::ostream& out, string name, t_type* type, t_const_value* value , string cls_nm) {
+ (void) out;
+ (void) name;
+ (void) type;
+ (void) value;
+ (void) cls_nm;
}
-string t_delphi_generator::render_const_value(ostream& vars,
- ostream& out,
- string name,
- t_type* type,
- t_const_value* value) {
- (void)name;
+string t_delphi_generator::render_const_value(ostream& vars, ostream& out, string name, t_type* type, t_const_value* value) {
+ (void) name;
t_type* truetype = type;
while (truetype->is_typedef()) {
@@ -1317,40 +1132,40 @@ string t_delphi_generator::render_const_value(ostream& vars,
if (truetype->is_base_type()) {
t_base_type::t_base tbase = ((t_base_type*)truetype)->get_base();
switch (tbase) {
- case t_base_type::TYPE_STRING:
- render << "'" << get_escaped_string(value) << "'";
- break;
- case t_base_type::TYPE_BOOL:
- render << ((value->get_integer() > 0) ? "True" : "False");
- break;
- case t_base_type::TYPE_BYTE:
- render << "ShortInt( " << value->get_integer() << ")";
- break;
- case t_base_type::TYPE_I16:
- render << "SmallInt( " << value->get_integer() << ")";
- break;
- case t_base_type::TYPE_I32:
- render << "LongInt( " << value->get_integer() << ")";
- break;
- case t_base_type::TYPE_I64:
- render << "Int64( " << value->get_integer() << ")";
- break;
- case t_base_type::TYPE_DOUBLE:
- if (value->get_type() == t_const_value::CV_INTEGER) {
- render << value->get_integer() << ".0"; // make it a double constant by adding ".0"
- } else {
- render << value->get_double();
- }
- break;
- default:
- throw "compiler error: no const of base type " + t_base_type::t_base_name(tbase);
+ case t_base_type::TYPE_STRING:
+ render << "'" << get_escaped_string(value) << "'";
+ break;
+ case t_base_type::TYPE_BOOL:
+ render << ((value->get_integer() > 0) ? "True" : "False");
+ break;
+ case t_base_type::TYPE_BYTE:
+ render << "ShortInt( " << value->get_integer() << ")";
+ break;
+ case t_base_type::TYPE_I16:
+ render << "SmallInt( " << value->get_integer() << ")";
+ break;
+ case t_base_type::TYPE_I32:
+ render << "LongInt( " << value->get_integer() << ")";
+ break;
+ case t_base_type::TYPE_I64:
+ render << "Int64( " << value->get_integer() << ")";
+ break;
+ case t_base_type::TYPE_DOUBLE:
+ if (value->get_type() == t_const_value::CV_INTEGER) {
+ render << value->get_integer() << ".0"; // make it a double constant by adding ".0"
+ } else {
+ render << value->get_double();
+ }
+ break;
+ default:
+ throw "compiler error: no const of base type " + t_base_type::t_base_name(tbase);
}
} else if (truetype->is_enum()) {
- render << type_name(type, false) << "." << value->get_identifier_name();
+ render << type_name( type, false) << "." << value->get_identifier_name();
} else {
string t = tmp("tmp");
- vars << " " << t << " : " << type_name(type) << ";" << endl;
- print_const_value(vars, out, t, type, value);
+ vars << " " << t << " : " << type_name(type) << ";" << endl;
+ print_const_value( vars, out, t, type, value);
render << t;
}
@@ -1370,27 +1185,19 @@ void t_delphi_generator::generate_delphi_struct(t_struct* tstruct, bool is_excep
generate_delphi_struct_definition(s_struct, tstruct, is_exception);
indent_down();
- add_defined_type(tstruct);
+ add_defined_type( tstruct);
generate_delphi_struct_impl(s_struct_impl, "", tstruct, is_exception);
if (register_types_) {
generate_delphi_struct_type_factory(s_type_factory_funcs, "", tstruct, is_exception);
- generate_delphi_struct_type_factory_registration(s_type_factory_registration,
- "",
- tstruct,
- is_exception);
+ generate_delphi_struct_type_factory_registration(s_type_factory_registration, "", tstruct, is_exception);
}
}
-void t_delphi_generator::generate_delphi_struct_impl(ostream& out,
- string cls_prefix,
- t_struct* tstruct,
- bool is_exception,
- bool is_result,
- bool is_x_factory) {
+void t_delphi_generator::generate_delphi_struct_impl( ostream& out, string cls_prefix, t_struct* tstruct, bool is_exception, bool is_result, bool is_x_factory) {
- if (is_exception && (!is_x_factory)) {
- generate_delphi_struct_impl(out, cls_prefix, tstruct, is_exception, is_result, true);
+ if (is_exception && (! is_x_factory)) {
+ generate_delphi_struct_impl( out, cls_prefix, tstruct, is_exception, is_result, true);
}
string cls_nm;
@@ -1398,13 +1205,14 @@ void t_delphi_generator::generate_delphi_struct_impl(ostream& out,
string exception_factory_name;
if (is_exception) {
- exception_factory_name = normalize_clsnm(tstruct->get_name(), "", true) + "Factory";
+ exception_factory_name = normalize_clsnm( tstruct->get_name(), "", true ) + "Factory";
}
if (is_exception) {
- cls_nm = type_name(tstruct, true, (!is_x_factory), is_x_factory, true);
- } else {
- cls_nm = type_name(tstruct, true, false);
+ cls_nm = type_name(tstruct,true,(! is_x_factory),is_x_factory,true);
+ }
+ else {
+ cls_nm = type_name(tstruct,true,false);
}
std::ostringstream vars, code;
@@ -1419,38 +1227,31 @@ void t_delphi_generator::generate_delphi_struct_impl(ostream& out,
t = ((t_typedef*)t)->get_type();
}
if ((*m_iter)->get_value() != NULL) {
- initialize_field(vars,
- code,
- "F" + prop_name((*m_iter)->get_name(), is_exception),
- t,
- (*m_iter)->get_value());
+ initialize_field( vars, code, "F" + prop_name( (*m_iter)->get_name(), is_exception), t, (*m_iter)->get_value());
if ((*m_iter)->get_req() != t_field::T_REQUIRED) {
- indent_impl(code) << "F__isset_" << prop_name((*m_iter), is_exception) << " := True;"
- << endl;
+ indent_impl(code) << "F__isset_" << prop_name((*m_iter), is_exception) << " := True;" << endl;
}
}
}
indent_down_impl();
- indent_impl(out) << "constructor " << cls_prefix << cls_nm << "."
- << "Create;" << endl;
+ indent_impl(out) << "constructor " << cls_prefix << cls_nm << "." << "Create;" << endl;
- if (!vars.str().empty()) {
+ if ( ! vars.str().empty()) {
out << "var" << endl;
out << vars.str();
}
indent_impl(out) << "begin" << endl;
indent_up_impl();
- if (is_exception && (!is_x_factory)) {
+ if (is_exception && (! is_x_factory)) {
indent_impl(out) << "inherited Create('');" << endl;
- indent_impl(out) << "F" << exception_factory_name << " := T" << exception_factory_name
- << "Impl.Create;" << endl;
+ indent_impl(out) << "F" << exception_factory_name << " := T" << exception_factory_name << "Impl.Create;" << endl;
} else {
indent_impl(out) << "inherited;" << endl;
}
- if (!code.str().empty()) {
+ if ( ! code.str().empty()) {
out << code.str();
}
@@ -1458,15 +1259,13 @@ void t_delphi_generator::generate_delphi_struct_impl(ostream& out,
indent_impl(out) << "end;" << endl << endl;
if ((members.size() > 0) && is_exception && (!is_x_factory)) {
- indent_impl(out) << "constructor " << cls_prefix << cls_nm << "."
- << "Create(" << constructor_argument_list(tstruct, indent_impl()) << ");"
- << endl;
+ indent_impl(out) << "constructor " << cls_prefix << cls_nm << "." << "Create(" << constructor_argument_list( tstruct, indent_impl()) << ");" << endl;
indent_impl(out) << "begin" << endl;
indent_up_impl();
indent_impl(out) << "Create;" << endl;
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
string propname = prop_name((*m_iter)->get_name(), is_exception);
- string param_name = constructor_param_name((*m_iter)->get_name());
+ string param_name = constructor_param_name( (*m_iter)->get_name());
indent_impl(out) << propname << " := " << param_name << ";" << endl;
}
indent_impl(out) << "UpdateMessageProperty;" << endl;
@@ -1474,8 +1273,7 @@ void t_delphi_generator::generate_delphi_struct_impl(ostream& out,
indent_impl(out) << "end;" << endl << endl;
}
- indent_impl(out) << "destructor " << cls_prefix << cls_nm << "."
- << "Destroy;" << endl;
+ indent_impl(out) << "destructor " << cls_prefix << cls_nm << "." << "Destroy;" << endl;
indent_impl(out) << "begin" << endl;
indent_up_impl();
@@ -1484,16 +1282,15 @@ void t_delphi_generator::generate_delphi_struct_impl(ostream& out,
while (t->is_typedef()) {
t = ((t_typedef*)t)->get_type();
}
- finalize_field(out, prop_name(*m_iter, is_exception), t, (*m_iter)->get_value());
+ finalize_field( out, prop_name(*m_iter, is_exception), t, (*m_iter)->get_value());
}
indent_impl(out) << "inherited;" << endl;
indent_down_impl();
indent_impl(out) << "end;" << endl << endl;
- if (tstruct->is_union()) {
- indent_impl(out) << "procedure " << cls_prefix << cls_nm << "."
- << "ClearUnionValues;" << endl;
+ if ( tstruct->is_union() ) {
+ indent_impl(out) << "procedure " << cls_prefix << cls_nm << "." << "ClearUnionValues;" << endl;
indent_impl(out) << "begin" << endl;
indent_up_impl();
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
@@ -1502,16 +1299,7 @@ void t_delphi_generator::generate_delphi_struct_impl(ostream& out,
t = ((t_typedef*)t)->get_type();
}
- generate_delphi_clear_union_value(out,
- cls_prefix,
- cls_nm,
- t,
- *m_iter,
- "F",
- is_exception,
- tstruct->is_union(),
- is_x_factory,
- exception_factory_name);
+ generate_delphi_clear_union_value( out, cls_prefix, cls_nm, t, *m_iter, "F", is_exception, tstruct->is_union(), is_x_factory, exception_factory_name);
}
indent_down_impl();
indent_impl(out) << "end;" << endl << endl;
@@ -1522,51 +1310,38 @@ void t_delphi_generator::generate_delphi_struct_impl(ostream& out,
while (t->is_typedef()) {
t = ((t_typedef*)t)->get_type();
}
- generate_delphi_property_reader_impl(out, cls_prefix, cls_nm, t, *m_iter, "F", is_exception);
- generate_delphi_property_writer_impl(out,
- cls_prefix,
- cls_nm,
- t,
- *m_iter,
- "F",
- is_exception,
- tstruct->is_union(),
- is_x_factory,
- exception_factory_name);
+ generate_delphi_property_reader_impl( out, cls_prefix, cls_nm, t, *m_iter, "F", is_exception);
+ generate_delphi_property_writer_impl( out, cls_prefix, cls_nm, t, *m_iter, "F", is_exception, tstruct->is_union(), is_x_factory, exception_factory_name);
if ((*m_iter)->get_req() != t_field::T_REQUIRED) {
- generate_delphi_isset_reader_impl(out, cls_prefix, cls_nm, t, *m_iter, "F", is_exception);
+ generate_delphi_isset_reader_impl( out, cls_prefix, cls_nm, t, *m_iter, "F", is_exception);
}
}
- if ((!is_exception) || is_x_factory) {
- generate_delphi_struct_reader_impl(out, cls_prefix, tstruct, is_exception);
- if (is_result) {
- generate_delphi_struct_result_writer_impl(out, cls_prefix, tstruct, is_exception);
+ if ((! is_exception) || is_x_factory) {
+ generate_delphi_struct_reader_impl( out, cls_prefix, tstruct, is_exception);
+ if ( is_result ) {
+ generate_delphi_struct_result_writer_impl( out, cls_prefix, tstruct, is_exception);
} else {
- generate_delphi_struct_writer_impl(out, cls_prefix, tstruct, is_exception);
+ generate_delphi_struct_writer_impl( out, cls_prefix, tstruct, is_exception);
}
}
- generate_delphi_struct_tostring_impl(out, cls_prefix, tstruct, is_exception, is_x_factory);
+ generate_delphi_struct_tostring_impl( out, cls_prefix, tstruct, is_exception, is_x_factory);
if (is_exception && is_x_factory) {
- generate_delphi_create_exception_impl(out, cls_prefix, tstruct, is_exception);
+ generate_delphi_create_exception_impl( out, cls_prefix, tstruct, is_exception);
}
}
-void t_delphi_generator::print_delphi_struct_type_factory_func(ostream& out, t_struct* tstruct) {
+void t_delphi_generator::print_delphi_struct_type_factory_func( ostream& out, t_struct* tstruct) {
string struct_intf_name = type_name(tstruct);
out << "Create_";
out << struct_intf_name;
out << "_Impl";
}
-void t_delphi_generator::generate_delphi_struct_type_factory(ostream& out,
- string cls_prefix,
- t_struct* tstruct,
- bool is_exception,
- bool is_result,
- bool is_x_factory) {
- (void)cls_prefix;
+
+void t_delphi_generator::generate_delphi_struct_type_factory( ostream& out, string cls_prefix, t_struct* tstruct, bool is_exception, bool is_result, bool is_x_factory) {
+ (void) cls_prefix;
if (is_exception)
return;
if (is_result)
@@ -1575,7 +1350,7 @@ void t_delphi_generator::generate_delphi_struct_type_factory(ostream& out,
return;
string struct_intf_name = type_name(tstruct);
- string cls_nm = type_name(tstruct, true, false);
+ string cls_nm = type_name(tstruct,true,false);
out << "function ";
print_delphi_struct_type_factory_func(out, tstruct);
@@ -1589,13 +1364,8 @@ void t_delphi_generator::generate_delphi_struct_type_factory(ostream& out,
out << "end;" << endl << endl;
}
-void t_delphi_generator::generate_delphi_struct_type_factory_registration(ostream& out,
- string cls_prefix,
- t_struct* tstruct,
- bool is_exception,
- bool is_result,
- bool is_x_factory) {
- (void)cls_prefix;
+void t_delphi_generator::generate_delphi_struct_type_factory_registration( ostream& out, string cls_prefix, t_struct* tstruct, bool is_exception, bool is_result, bool is_x_factory) {
+ (void) cls_prefix;
if (is_exception)
return;
if (is_result)
@@ -1611,12 +1381,7 @@ void t_delphi_generator::generate_delphi_struct_type_factory_registration(ostrea
out << endl;
}
-void t_delphi_generator::generate_delphi_struct_definition(ostream& out,
- t_struct* tstruct,
- bool is_exception,
- bool in_class,
- bool is_result,
- bool is_x_factory) {
+void t_delphi_generator::generate_delphi_struct_definition(ostream &out, t_struct* tstruct, bool is_exception, bool in_class, bool is_result, bool is_x_factory) {
bool is_final = (tstruct->annotations_.find("final") != tstruct->annotations_.end());
string struct_intf_name;
string struct_name;
@@ -1624,35 +1389,38 @@ void t_delphi_generator::generate_delphi_struct_definition(ostream& out,
const vector<t_field*>& members = tstruct->get_members();
vector<t_field*>::const_iterator m_iter;
- string exception_factory_name = normalize_clsnm(tstruct->get_name(), "", true) + "Factory";
+ string exception_factory_name = normalize_clsnm( tstruct->get_name(), "", true ) + "Factory";
if (is_exception) {
- struct_intf_name = type_name(tstruct, false, false, true);
- } else {
+ struct_intf_name = type_name(tstruct,false,false,true);
+ }
+ else {
struct_intf_name = type_name(tstruct);
}
+
if (is_exception) {
- struct_name = type_name(tstruct, true, (!is_x_factory), is_x_factory);
- } else {
- struct_name = type_name(tstruct, true);
+ struct_name = type_name(tstruct, true, (! is_x_factory), is_x_factory);
+ }
+ else {
+ struct_name = type_name(tstruct,true);
}
- if ((!is_exception) || is_x_factory) {
+ if ((! is_exception) || is_x_factory) {
generate_delphi_doc(out, tstruct);
indent(out) << struct_intf_name << " = interface(IBase)" << endl;
indent_up();
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- generate_delphi_property_reader_definition(out, *m_iter, is_exception);
- generate_delphi_property_writer_definition(out, *m_iter, is_exception);
+ generate_delphi_property_reader_definition( out, *m_iter, is_exception);
+ generate_delphi_property_writer_definition( out, *m_iter, is_exception);
}
if (is_x_factory) {
out << endl;
indent(out) << "// Create Exception Object" << endl;
- indent(out) << "function CreateException: " << type_name(tstruct, true, true) << ";" << endl;
+ indent(out) << "function CreateException: " << type_name(tstruct,true,true) << ";" << endl;
}
if (members.size() > 0) {
@@ -1666,7 +1434,7 @@ void t_delphi_generator::generate_delphi_struct_definition(ostream& out,
out << endl;
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
if ((*m_iter)->get_req() != t_field::T_REQUIRED) {
- generate_delphi_isset_reader_definition(out, *m_iter, is_exception);
+ generate_delphi_isset_reader_definition( out, *m_iter, is_exception);
}
}
}
@@ -1676,8 +1444,7 @@ void t_delphi_generator::generate_delphi_struct_definition(ostream& out,
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
if ((*m_iter)->get_req() != t_field::T_REQUIRED) {
isset_name = "__isset_" + prop_name(*m_iter, is_exception);
- indent(out) << "property " << isset_name << ": Boolean read Get" << isset_name << ";"
- << endl;
+ indent(out) << "property " << isset_name << ": Boolean read Get" << isset_name << ";" << endl;
}
}
}
@@ -1692,19 +1459,19 @@ void t_delphi_generator::generate_delphi_struct_definition(ostream& out,
out << "sealed ";
}
out << "class(";
- if (is_exception && (!is_x_factory)) {
+ if ( is_exception && (! is_x_factory)) {
out << "TException";
} else {
out << "TInterfacedObject, IBase, " << struct_intf_name;
}
out << ")" << endl;
- if (is_exception && (!is_x_factory)) {
+ if (is_exception && (! is_x_factory)) {
indent(out) << "public" << endl;
indent_up();
indent(out) << "type" << endl;
indent_up();
- generate_delphi_struct_definition(out, tstruct, is_exception, in_class, is_result, true);
+ generate_delphi_struct_definition( out, tstruct, is_exception, in_class, is_result, true);
indent_down();
indent_down();
}
@@ -1712,7 +1479,7 @@ void t_delphi_generator::generate_delphi_struct_definition(ostream& out,
indent(out) << "private" << endl;
indent_up();
- if (is_exception && (!is_x_factory)) {
+ if (is_exception && (! is_x_factory)) {
indent(out) << "F" << exception_factory_name << " :" << struct_intf_name << ";" << endl << endl;
}
@@ -1733,8 +1500,8 @@ void t_delphi_generator::generate_delphi_struct_definition(ostream& out,
indent(out) << endl;
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- generate_delphi_property_reader_definition(out, *m_iter, is_exception);
- generate_delphi_property_writer_definition(out, *m_iter, is_exception);
+ generate_delphi_property_reader_definition( out, *m_iter, is_exception);
+ generate_delphi_property_writer_definition( out, *m_iter, is_exception);
}
if (tstruct->is_union()) {
@@ -1758,37 +1525,35 @@ void t_delphi_generator::generate_delphi_struct_definition(ostream& out,
indent(out) << "public" << endl;
indent_up();
- if ((members.size() > 0) && is_exception && (!is_x_factory)) {
+ if ((members.size() > 0) && is_exception && (! is_x_factory)) {
indent(out) << "constructor Create; overload;" << endl;
- indent(out) << "constructor Create(" << constructor_argument_list(tstruct, indent())
- << "); overload;" << endl;
+ indent(out) << "constructor Create(" << constructor_argument_list( tstruct, indent()) << "); overload;" << endl;
} else {
indent(out) << "constructor Create;" << endl;
}
indent(out) << "destructor Destroy; override;" << endl;
- out << endl;
+ out << endl;
indent(out) << "function ToString: string; override;" << endl;
- if (is_exception && (!is_x_factory)) {
- out << endl;
+ if (is_exception && (! is_x_factory)) {
+ out << endl;
indent(out) << "// Exception Factory" << endl;
- indent(out) << "property " << exception_factory_name << ": " << struct_intf_name << " read F"
- << exception_factory_name << " write F" << exception_factory_name << ";" << endl;
+ indent(out) << "property " << exception_
<TRUNCATED>