blob: f7516a35a72621aad78170fd2d68e726f1db3d9c [file] [log] [blame]
Mark Sleee9ce01c2007-05-16 02:29:53 +00001// 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/
6
Mark Slee31985722006-05-24 21:45:31 +00007#ifndef T_PROGRAM_H
8#define T_PROGRAM_H
9
Mark Sleee8540632006-05-30 09:24:40 +000010#include <map>
Mark Slee31985722006-05-24 21:45:31 +000011#include <string>
12#include <vector>
13
Mark Sleef0712dc2006-10-25 19:03:57 +000014// For program_name()
15#include "main.h"
16
David Reissc2532a92007-07-30 23:46:11 +000017#include "t_doc.h"
Mark Sleef0712dc2006-10-25 19:03:57 +000018#include "t_scope.h"
Mark Slee31985722006-05-24 21:45:31 +000019#include "t_base_type.h"
20#include "t_typedef.h"
21#include "t_enum.h"
Mark Slee30152872006-11-28 01:24:07 +000022#include "t_const.h"
Mark Slee31985722006-05-24 21:45:31 +000023#include "t_struct.h"
24#include "t_service.h"
Mark Sleee8540632006-05-30 09:24:40 +000025#include "t_list.h"
26#include "t_map.h"
27#include "t_set.h"
ccheeverf53b5cf2007-02-05 20:33:11 +000028//#include "t_doc.h"
Mark Slee31985722006-05-24 21:45:31 +000029
30/**
31 * Top level class representing an entire thrift program. A program consists
32 * fundamentally of the following:
33 *
34 * Typedefs
35 * Enumerations
Mark Slee30152872006-11-28 01:24:07 +000036 * Constants
Mark Slee31985722006-05-24 21:45:31 +000037 * Structs
Mark Slee9cb7c612006-09-01 22:17:45 +000038 * Exceptions
Mark Slee31985722006-05-24 21:45:31 +000039 * Services
40 *
Mark Sleef5377b32006-10-10 01:42:59 +000041 * The program module also contains the definitions of the base types.
42 *
Mark Slee31985722006-05-24 21:45:31 +000043 * @author Mark Slee <mcslee@facebook.com>
44 */
David Reissc2532a92007-07-30 23:46:11 +000045class t_program : public t_doc {
Mark Slee31985722006-05-24 21:45:31 +000046 public:
Mark Sleef0712dc2006-10-25 19:03:57 +000047 t_program(std::string path, std::string name) :
Mark Slee2c44d202007-05-16 02:18:07 +000048 path_(path),
Mark Sleef0712dc2006-10-25 19:03:57 +000049 name_(name) {
50 scope_ = new t_scope();
Mark Slee31985722006-05-24 21:45:31 +000051 }
52
Mark Sleef0712dc2006-10-25 19:03:57 +000053 t_program(std::string path) :
54 path_(path) {
55 name_ = program_name(path);
56 scope_ = new t_scope();
Mark Slee31985722006-05-24 21:45:31 +000057 }
58
Mark Slee2c44d202007-05-16 02:18:07 +000059 // Path accessor
Mark Sleef0712dc2006-10-25 19:03:57 +000060 const std::string& get_path() const { return path_; }
61
Mark Slee31985722006-05-24 21:45:31 +000062 // Name accessor
Mark Sleef0712dc2006-10-25 19:03:57 +000063 const std::string& get_name() const { return name_; }
Mark Slee31985722006-05-24 21:45:31 +000064
Mark Slee9cb7c612006-09-01 22:17:45 +000065 // Namespace
Mark Sleef0712dc2006-10-25 19:03:57 +000066 const std::string& get_namespace() const { return namespace_; }
Mark Slee9cb7c612006-09-01 22:17:45 +000067
Mark Slee31985722006-05-24 21:45:31 +000068 // Accessors for program elements
Mark Slee9cb7c612006-09-01 22:17:45 +000069 const std::vector<t_typedef*>& get_typedefs() const { return typedefs_; }
70 const std::vector<t_enum*>& get_enums() const { return enums_; }
Mark Slee30152872006-11-28 01:24:07 +000071 const std::vector<t_const*>& get_consts() const { return consts_; }
Mark Slee9cb7c612006-09-01 22:17:45 +000072 const std::vector<t_struct*>& get_structs() const { return structs_; }
73 const std::vector<t_struct*>& get_xceptions() const { return xceptions_; }
74 const std::vector<t_service*>& get_services() const { return services_; }
Mark Slee31985722006-05-24 21:45:31 +000075
Mark Sleef0712dc2006-10-25 19:03:57 +000076 // Program elements
77 void add_typedef (t_typedef* td) { typedefs_.push_back(td); }
78 void add_enum (t_enum* te) { enums_.push_back(te); }
Mark Slee30152872006-11-28 01:24:07 +000079 void add_const (t_const* tc) { consts_.push_back(tc); }
Mark Sleef0712dc2006-10-25 19:03:57 +000080 void add_struct (t_struct* ts) { structs_.push_back(ts); }
81 void add_xception (t_struct* tx) { xceptions_.push_back(tx); }
82 void add_service (t_service* ts) { services_.push_back(ts); }
Mark Slee31985722006-05-24 21:45:31 +000083
Mark Sleef0712dc2006-10-25 19:03:57 +000084 // Programs to include
85 const std::vector<t_program*>& get_includes() const { return includes_; }
Mark Sleee8540632006-05-30 09:24:40 +000086
Mark Sleef0712dc2006-10-25 19:03:57 +000087 // Scoping and namespacing
Mark Slee9cb7c612006-09-01 22:17:45 +000088 void set_namespace(std::string name) {
89 namespace_ = name;
90 }
91
Mark Sleef0712dc2006-10-25 19:03:57 +000092 // Scope accessor
93 t_scope* scope() {
94 return scope_;
Mark Sleee8540632006-05-30 09:24:40 +000095 }
Mark Sleef5377b32006-10-10 01:42:59 +000096
Mark Sleef0712dc2006-10-25 19:03:57 +000097 // Includes
98
99 void add_include(std::string path) {
100 includes_.push_back(new t_program(path));
Mark Sleee8540632006-05-30 09:24:40 +0000101 }
Mark Sleef5377b32006-10-10 01:42:59 +0000102
Mark Sleef0712dc2006-10-25 19:03:57 +0000103 std::vector<t_program*>& get_includes() {
104 return includes_;
Mark Sleee8540632006-05-30 09:24:40 +0000105 }
Mark Sleef5377b32006-10-10 01:42:59 +0000106
Mark Sleef0712dc2006-10-25 19:03:57 +0000107 // Language specific namespace / packaging
108
109 void set_cpp_namespace(std::string cpp_namespace) {
110 cpp_namespace_ = cpp_namespace;
Mark Slee9cb7c612006-09-01 22:17:45 +0000111 }
Mark Sleef5377b32006-10-10 01:42:59 +0000112
Mark Sleef0712dc2006-10-25 19:03:57 +0000113 const std::string& get_cpp_namespace() const {
114 return cpp_namespace_;
Mark Sleee8540632006-05-30 09:24:40 +0000115 }
116
Mark Sleef0712dc2006-10-25 19:03:57 +0000117 void add_cpp_include(std::string path) {
118 cpp_includes_.push_back(path);
119 }
120
121 const std::vector<std::string>& get_cpp_includes() {
122 return cpp_includes_;
123 }
124
Mark Sleee888b372007-01-12 01:06:24 +0000125 void set_php_namespace(std::string php_namespace) {
126 php_namespace_ = php_namespace;
127 }
128
129 const std::string& get_php_namespace() const {
130 return php_namespace_;
131 }
132
Mark Sleef0712dc2006-10-25 19:03:57 +0000133 void set_java_package(std::string java_package) {
134 java_package_ = java_package;
135 }
136
137 const std::string& get_java_package() const {
138 return java_package_;
139 }
140
Mark Slee0d9199e2007-01-31 02:08:30 +0000141 void set_xsd_namespace(std::string xsd_namespace) {
142 xsd_namespace_ = xsd_namespace;
143 }
144
145 const std::string& get_xsd_namespace() const {
146 return xsd_namespace_;
147 }
Mark Sleef0712dc2006-10-25 19:03:57 +0000148
Mark Slee58dfb4f2007-07-06 02:45:25 +0000149 void set_ruby_namespace(std::string ruby_namespace) {
150 ruby_namespace_ = ruby_namespace;
151 }
Mark Slee27ed6ec2007-08-16 01:26:31 +0000152
Mark Slee58dfb4f2007-07-06 02:45:25 +0000153 const std::string& get_ruby_namespace() const {
154 return ruby_namespace_;
155 }
156
David Reissc6fc3292007-08-30 00:58:43 +0000157 void set_py_module(std::string py_module) {
158 py_module_ = py_module;
159 }
160
161 const std::string& get_py_module() const {
162 return py_module_;
163 }
164
Mark Slee27ed6ec2007-08-16 01:26:31 +0000165 void set_perl_package(std::string perl_package) {
166 perl_package_ = perl_package;
Mark Slee2c44d202007-05-16 02:18:07 +0000167 }
168
Mark Slee27ed6ec2007-08-16 01:26:31 +0000169 const std::string& get_perl_package() const {
170 return perl_package_;
Mark Slee2c44d202007-05-16 02:18:07 +0000171 }
172
Mark Slee7e9eea42007-09-10 21:00:23 +0000173 void set_cocoa_prefix(std::string cocoa_prefix) {
174 cocoa_prefix_ = cocoa_prefix;
175 }
176
177 const std::string& get_cocoa_prefix() const {
178 return cocoa_prefix_;
179 }
180
Mark Slee31985722006-05-24 21:45:31 +0000181 private:
Mark Sleef5377b32006-10-10 01:42:59 +0000182
Mark Sleef0712dc2006-10-25 19:03:57 +0000183 // File path
184 std::string path_;
Mark Slee9cb7c612006-09-01 22:17:45 +0000185
Mark Slee31985722006-05-24 21:45:31 +0000186 // Name
187 std::string name_;
188
Mark Slee9cb7c612006-09-01 22:17:45 +0000189 // Namespace
190 std::string namespace_;
191
Mark Sleef0712dc2006-10-25 19:03:57 +0000192 // Included programs
193 std::vector<t_program*> includes_;
Mark Sleee8540632006-05-30 09:24:40 +0000194
Mark Sleef0712dc2006-10-25 19:03:57 +0000195 // Identifier lookup scope
196 t_scope* scope_;
Mark Sleee8540632006-05-30 09:24:40 +0000197
Mark Sleef0712dc2006-10-25 19:03:57 +0000198 // Components to generate code for
199 std::vector<t_typedef*> typedefs_;
200 std::vector<t_enum*> enums_;
Mark Slee30152872006-11-28 01:24:07 +0000201 std::vector<t_const*> consts_;
Mark Sleef0712dc2006-10-25 19:03:57 +0000202 std::vector<t_struct*> structs_;
203 std::vector<t_struct*> xceptions_;
204 std::vector<t_service*> services_;
205
206 // C++ namespace
207 std::string cpp_namespace_;
208
209 // C++ extra includes
210 std::vector<std::string> cpp_includes_;
211
Mark Sleee888b372007-01-12 01:06:24 +0000212 // PHP namespace
213 std::string php_namespace_;
214
Mark Sleef0712dc2006-10-25 19:03:57 +0000215 // Java package
216 std::string java_package_;
217
Mark Slee0d9199e2007-01-31 02:08:30 +0000218 // XSD namespace
219 std::string xsd_namespace_;
220
Mark Slee58dfb4f2007-07-06 02:45:25 +0000221 // Ruby namespace
222 std::string ruby_namespace_;
223
David Reissc6fc3292007-08-30 00:58:43 +0000224 // Python namespace
225 std::string py_module_;
226
Mark Slee2c44d202007-05-16 02:18:07 +0000227 // Perl namespace
Mark Slee27ed6ec2007-08-16 01:26:31 +0000228 std::string perl_package_;
Mark Slee2c44d202007-05-16 02:18:07 +0000229
Mark Slee7e9eea42007-09-10 21:00:23 +0000230 // Cocoa/Objective-C naming prefix
231 std::string cocoa_prefix_;
232
233
Mark Slee31985722006-05-24 21:45:31 +0000234};
235
236#endif