r1317@opsdev009 (orig r70384): mcslee | 2007-11-16 16:32:36 -0800
[amiethrift.git] / compiler / cpp / src / generate / t_generator.cc
blob068822c520774d651fc6d329c45f7b502b82499d
1 // Copyright (c) 2006- Facebook
2 // Distributed under the Thrift Software License
3 //
4 // See accompanying file LICENSE or visit the Thrift site at:
5 // http://developers.facebook.com/thrift/
7 #include "t_generator.h"
8 using namespace std;
10 /**
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
20 init_generator();
22 // Generate enums
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);
29 // Generate typedefs
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);
36 // Generate constants
37 vector<t_const*> consts = program_->get_consts();
38 generate_consts(consts);
40 // Generate structs
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);
47 // Generate xceptions
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);
54 // Generate services
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
63 close_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);