r1317@opsdev009 (orig r70384): mcslee | 2007-11-16 16:32:36 -0800
[amiethrift.git] / compiler / cpp / src / generate / t_perl_generator.h
blobdcb2e5e3ef1210d327d4378f76f25c63e01952f3
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 #ifndef T_PERL_GENERATOR_H
8 #define T_PERL_GENERATOR_H
10 #include <string>
11 #include <fstream>
12 #include <iostream>
13 #include <vector>
15 #include "t_oop_generator.h"
17 /**
18 * PERL code generator.
20 * @author Jake Luciani <jakers@gmail.com>
22 class t_perl_generator : public t_oop_generator {
23 public:
24 t_perl_generator(t_program* program) :
25 t_oop_generator(program) {
27 out_dir_base_ = "gen-perl";
30 /**
31 * Init and close methods
34 void init_generator();
35 void close_generator();
37 /**
38 * Program-level generation functions
41 void generate_typedef (t_typedef* ttypedef);
42 void generate_enum (t_enum* tenum);
43 void generate_const (t_const* tconst);
44 void generate_struct (t_struct* tstruct);
45 void generate_xception (t_struct* txception);
46 void generate_service (t_service* tservice);
48 std::string render_const_value(t_type* type, t_const_value* value);
50 /**
51 * Structs!
54 void generate_perl_struct(t_struct* tstruct, bool is_exception);
55 void generate_perl_struct_definition(std::ofstream& out, t_struct* tstruct, bool is_xception=false);
56 void generate_perl_struct_reader(std::ofstream& out, t_struct* tstruct);
57 void generate_perl_struct_writer(std::ofstream& out, t_struct* tstruct);
58 void generate_perl_function_helpers(t_function* tfunction);
60 /**
61 * Service-level generation functions
64 void generate_service_helpers (t_service* tservice);
65 void generate_service_interface (t_service* tservice);
66 void generate_service_rest (t_service* tservice);
67 void generate_service_client (t_service* tservice);
68 void generate_service_processor (t_service* tservice);
69 void generate_process_function (t_service* tservice, t_function* tfunction);
71 /**
72 * Serialization constructs
75 void generate_deserialize_field (std::ofstream &out,
76 t_field* tfield,
77 std::string prefix="",
78 bool inclass=false);
80 void generate_deserialize_struct (std::ofstream &out,
81 t_struct* tstruct,
82 std::string prefix="");
84 void generate_deserialize_container (std::ofstream &out,
85 t_type* ttype,
86 std::string prefix="");
88 void generate_deserialize_set_element (std::ofstream &out,
89 t_set* tset,
90 std::string prefix="");
92 void generate_deserialize_map_element (std::ofstream &out,
93 t_map* tmap,
94 std::string prefix="");
96 void generate_deserialize_list_element (std::ofstream &out,
97 t_list* tlist,
98 std::string prefix="");
100 void generate_serialize_field (std::ofstream &out,
101 t_field* tfield,
102 std::string prefix="");
104 void generate_serialize_struct (std::ofstream &out,
105 t_struct* tstruct,
106 std::string prefix="");
108 void generate_serialize_container (std::ofstream &out,
109 t_type* ttype,
110 std::string prefix="");
112 void generate_serialize_map_element (std::ofstream &out,
113 t_map* tmap,
114 std::string kiter,
115 std::string viter);
117 void generate_serialize_set_element (std::ofstream &out,
118 t_set* tmap,
119 std::string iter);
121 void generate_serialize_list_element (std::ofstream &out,
122 t_list* tlist,
123 std::string iter);
126 * Helper rendering functions
129 std::string perl_includes();
130 std::string declare_field(t_field* tfield, bool init=false, bool obj=false);
131 std::string function_signature(t_function* tfunction, std::string prefix="");
132 std::string argument_list(t_struct* tstruct);
133 std::string type_to_enum(t_type* ttype);
135 std::string autogen_comment() {
136 return
137 std::string("#\n") +
138 "# Autogenerated by Thrift\n" +
139 "#\n" +
140 "# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n" +
141 "#\n";
144 std::string perl_namespace(t_program* p) {
145 std::string ns = p->get_perl_package();
146 return ns.empty() ? ns : (ns + "::");
149 private:
152 * File streams
154 std::ofstream f_types_;
155 std::ofstream f_consts_;
156 std::ofstream f_helpers_;
157 std::ofstream f_service_;
161 #endif