1 // Copyright (c) 2007- Patrick Collison <patrick@collison.ie>
2 // Copyright (c) 2006- Facebook
4 // Distributed under the Thrift Software License
6 // See accompanying file LICENSE or visit the Thrift site at:
7 // http://developers.facebook.com/thrift/
9 #ifndef T_ST_GENERATOR_H
10 #define T_ST_GENERATOR_H
16 #include <boost/tokenizer.hpp>
18 #include "t_oop_generator.h"
20 #define T_ST_DIR "gen-st"
23 * Smalltalk code generator.
25 * @author Patrick Collison <patrick@collison.ie>
27 class t_st_generator
: public t_oop_generator
{
29 t_st_generator(t_program
* program
) :
30 t_oop_generator(program
) {}
33 * Init and close methods
36 void init_generator();
37 void close_generator();
40 * Program-level generation functions
43 void generate_typedef (t_typedef
* ttypedef
);
44 void generate_enum (t_enum
* tenum
);
45 void generate_const (t_const
* tconst
);
46 void generate_struct (t_struct
* tstruct
);
47 void generate_xception (t_struct
* txception
);
48 void generate_service (t_service
* tservice
);
49 void generate_class_side_definition ();
50 void generate_force_consts ();
53 std::string
render_const_value(t_type
* type
, t_const_value
* value
);
56 * Struct generation code
59 void generate_st_struct (std::ofstream
& out
, t_struct
* tstruct
, bool is_exception
);
60 void generate_accessors (std::ofstream
& out
, t_struct
* tstruct
);
63 * Service-level generation functions
66 void generate_service_client (t_service
* tservice
);
68 void generate_send_method (t_function
* tfunction
);
69 void generate_recv_method (t_function
* tfunction
);
71 std::string
map_reader (t_map
*tmap
);
72 std::string
list_reader (t_list
*tlist
);
73 std::string
set_reader (t_set
*tset
);
74 std::string
struct_reader (t_struct
*tstruct
, std::string clsName
);
76 std::string
map_writer (t_map
*tmap
, std::string name
);
77 std::string
list_writer (t_list
*tlist
, std::string name
);
78 std::string
set_writer (t_set
*tset
, std::string name
);
79 std::string
struct_writer (t_struct
*tstruct
, std::string fname
);
81 std::string
write_val (t_type
*t
, std::string fname
);
82 std::string
read_val (t_type
*t
);
85 * Helper rendering functions
88 std::string
st_autogen_comment();
90 void st_class_def(std::ofstream
&out
, std::string name
);
91 void st_method(std::ofstream
&out
, std::string cls
, std::string name
);
92 void st_method(std::ofstream
&out
, std::string cls
, std::string name
, std::string category
);
93 void st_close_method(std::ofstream
&out
);
94 void st_class_method(std::ofstream
&out
, std::string cls
, std::string name
);
95 void st_class_method(std::ofstream
&out
, std::string cls
, std::string name
, std::string category
);
96 void st_setter(std::ofstream
&out
, std::string cls
, std::string name
, std::string type
);
97 void st_getter(std::ofstream
&out
, std::string cls
, std::string name
);
98 void st_accessors(std::ofstream
&out
, std::string cls
, std::string name
, std::string type
);
100 std::string
class_name();
101 std::string
client_class_name();
102 std::string
prefix(std::string name
);
103 std::string
declare_field(t_field
* tfield
);
104 std::string
sanitize(std::string s
);
105 std::string
type_name(t_type
* ttype
);
107 std::string
function_signature(t_function
* tfunction
);
108 std::string
argument_list(t_struct
* tstruct
);
109 std::string
function_types_comment(t_function
* fn
);
111 std::string
type_to_enum(t_type
* ttype
);
112 std::string
a_type(t_type
* type
);
113 bool is_vowel(char c
);
114 std::string
temp_name();
115 std::string
generated_category();