r1401@opsdev009 (orig r74315): dreiss | 2007-12-13 23:03:03 -0800
[amiethrift.git] / compiler / cpp / src / generate / t_st_generator.h
blobfd20456bffca0bdb17da77da6c2b81c8661b22bb
1 // Copyright (c) 2007- Patrick Collison <patrick@collison.ie>
2 // Copyright (c) 2006- Facebook
3 //
4 // Distributed under the Thrift Software License
5 //
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
12 #include <string>
13 #include <fstream>
14 #include <iostream>
15 #include <vector>
16 #include <boost/tokenizer.hpp>
18 #include "t_oop_generator.h"
20 #define T_ST_DIR "gen-st"
22 /**
23 * Smalltalk code generator.
25 * @author Patrick Collison <patrick@collison.ie>
27 class t_st_generator : public t_oop_generator {
28 public:
29 t_st_generator(t_program* program) :
30 t_oop_generator(program) {}
32 /**
33 * Init and close methods
36 void init_generator();
37 void close_generator();
39 /**
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);
55 /**
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);
62 /**
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);
84 /**
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();
117 private:
120 * File streams
122 int temporary_var;
123 std::ofstream f_;
127 #endif