1 // Copyright (c) 2006- Facebook
2 // Distributed under the Thrift Software License
4 // See accompanying file LICENSE or visit the Thrift site at:
5 // http://developers.facebook.com/thrift/
7 #include "t_generator.h"
11 * Top level program generation function. Calls the generator subclass methods
12 * for preparing file streams etc. then iterates over all the parts of the
13 * program to perform the correct actions.
15 * @param program The thrift program to compile into C++ source
16 * @author Mark Slee <mcslee@facebook.com>
18 void t_generator::generate_program() {
19 // Initialize the generator
23 vector
<t_enum
*> enums
= program_
->get_enums();
24 vector
<t_enum
*>::iterator en_iter
;
25 for (en_iter
= enums
.begin(); en_iter
!= enums
.end(); ++en_iter
) {
26 generate_enum(*en_iter
);
30 vector
<t_typedef
*> typedefs
= program_
->get_typedefs();
31 vector
<t_typedef
*>::iterator td_iter
;
32 for (td_iter
= typedefs
.begin(); td_iter
!= typedefs
.end(); ++td_iter
) {
33 generate_typedef(*td_iter
);
37 vector
<t_const
*> consts
= program_
->get_consts();
38 generate_consts(consts
);
41 vector
<t_struct
*> structs
= program_
->get_structs();
42 vector
<t_struct
*>::iterator st_iter
;
43 for (st_iter
= structs
.begin(); st_iter
!= structs
.end(); ++st_iter
) {
44 generate_struct(*st_iter
);
48 vector
<t_struct
*> xceptions
= program_
->get_xceptions();
49 vector
<t_struct
*>::iterator x_iter
;
50 for (x_iter
= xceptions
.begin(); x_iter
!= xceptions
.end(); ++x_iter
) {
51 generate_xception(*x_iter
);
55 vector
<t_service
*> services
= program_
->get_services();
56 vector
<t_service
*>::iterator sv_iter
;
57 for (sv_iter
= services
.begin(); sv_iter
!= services
.end(); ++sv_iter
) {
58 service_name_
= get_service_name(*sv_iter
);
59 generate_service(*sv_iter
);
62 // Close the generator
66 void t_generator::generate_consts(vector
<t_const
*> consts
) {
67 vector
<t_const
*>::iterator c_iter
;
68 for (c_iter
= consts
.begin(); c_iter
!= consts
.end(); ++c_iter
) {
69 generate_const(*c_iter
);