Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1 | #ifndef T_PROGRAM_H |
| 2 | #define T_PROGRAM_H |
| 3 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 4 | #include <map> |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 5 | #include <string> |
| 6 | #include <vector> |
| 7 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 8 | // For program_name() |
| 9 | #include "main.h" |
| 10 | |
| 11 | #include "t_scope.h" |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 12 | #include "t_base_type.h" |
| 13 | #include "t_typedef.h" |
| 14 | #include "t_enum.h" |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 15 | #include "t_const.h" |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 16 | #include "t_struct.h" |
| 17 | #include "t_service.h" |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 18 | #include "t_list.h" |
| 19 | #include "t_map.h" |
| 20 | #include "t_set.h" |
ccheever | f53b5cf | 2007-02-05 20:33:11 +0000 | [diff] [blame^] | 21 | //#include "t_doc.h" |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Top level class representing an entire thrift program. A program consists |
| 25 | * fundamentally of the following: |
| 26 | * |
| 27 | * Typedefs |
| 28 | * Enumerations |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 29 | * Constants |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 30 | * Structs |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 31 | * Exceptions |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 32 | * Services |
| 33 | * |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 34 | * The program module also contains the definitions of the base types. |
| 35 | * |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 36 | * @author Mark Slee <mcslee@facebook.com> |
| 37 | */ |
| 38 | class t_program { |
| 39 | public: |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 40 | t_program(std::string path, std::string name) : |
| 41 | path_(path), |
| 42 | name_(name) { |
| 43 | scope_ = new t_scope(); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 46 | t_program(std::string path) : |
| 47 | path_(path) { |
| 48 | name_ = program_name(path); |
| 49 | scope_ = new t_scope(); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 52 | // Path accessor |
| 53 | const std::string& get_path() const { return path_; } |
| 54 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 55 | // Name accessor |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 56 | const std::string& get_name() const { return name_; } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 57 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 58 | // Namespace |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 59 | const std::string& get_namespace() const { return namespace_; } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 60 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 61 | // Accessors for program elements |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 62 | const std::vector<t_typedef*>& get_typedefs() const { return typedefs_; } |
| 63 | const std::vector<t_enum*>& get_enums() const { return enums_; } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 64 | const std::vector<t_const*>& get_consts() const { return consts_; } |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 65 | const std::vector<t_struct*>& get_structs() const { return structs_; } |
| 66 | const std::vector<t_struct*>& get_xceptions() const { return xceptions_; } |
| 67 | const std::vector<t_service*>& get_services() const { return services_; } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 68 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 69 | // Program elements |
| 70 | void add_typedef (t_typedef* td) { typedefs_.push_back(td); } |
| 71 | void add_enum (t_enum* te) { enums_.push_back(te); } |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 72 | void add_const (t_const* tc) { consts_.push_back(tc); } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 73 | void add_struct (t_struct* ts) { structs_.push_back(ts); } |
| 74 | void add_xception (t_struct* tx) { xceptions_.push_back(tx); } |
| 75 | void add_service (t_service* ts) { services_.push_back(ts); } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 76 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 77 | // Programs to include |
| 78 | const std::vector<t_program*>& get_includes() const { return includes_; } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 79 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 80 | // Scoping and namespacing |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 81 | void set_namespace(std::string name) { |
| 82 | namespace_ = name; |
| 83 | } |
| 84 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 85 | // Scope accessor |
| 86 | t_scope* scope() { |
| 87 | return scope_; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 88 | } |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 89 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 90 | // Includes |
| 91 | |
| 92 | void add_include(std::string path) { |
| 93 | includes_.push_back(new t_program(path)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 94 | } |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 95 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 96 | std::vector<t_program*>& get_includes() { |
| 97 | return includes_; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 98 | } |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 99 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 100 | // Language specific namespace / packaging |
| 101 | |
| 102 | void set_cpp_namespace(std::string cpp_namespace) { |
| 103 | cpp_namespace_ = cpp_namespace; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 104 | } |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 105 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 106 | const std::string& get_cpp_namespace() const { |
| 107 | return cpp_namespace_; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 110 | void add_cpp_include(std::string path) { |
| 111 | cpp_includes_.push_back(path); |
| 112 | } |
| 113 | |
| 114 | const std::vector<std::string>& get_cpp_includes() { |
| 115 | return cpp_includes_; |
| 116 | } |
| 117 | |
Mark Slee | e888b37 | 2007-01-12 01:06:24 +0000 | [diff] [blame] | 118 | void set_php_namespace(std::string php_namespace) { |
| 119 | php_namespace_ = php_namespace; |
| 120 | } |
| 121 | |
| 122 | const std::string& get_php_namespace() const { |
| 123 | return php_namespace_; |
| 124 | } |
| 125 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 126 | void set_java_package(std::string java_package) { |
| 127 | java_package_ = java_package; |
| 128 | } |
| 129 | |
| 130 | const std::string& get_java_package() const { |
| 131 | return java_package_; |
| 132 | } |
| 133 | |
Mark Slee | 0d9199e | 2007-01-31 02:08:30 +0000 | [diff] [blame] | 134 | void set_xsd_namespace(std::string xsd_namespace) { |
| 135 | xsd_namespace_ = xsd_namespace; |
| 136 | } |
| 137 | |
| 138 | const std::string& get_xsd_namespace() const { |
| 139 | return xsd_namespace_; |
| 140 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 141 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 142 | private: |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 143 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 144 | // File path |
| 145 | std::string path_; |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 146 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 147 | // Name |
| 148 | std::string name_; |
| 149 | |
Mark Slee | 9cb7c61 | 2006-09-01 22:17:45 +0000 | [diff] [blame] | 150 | // Namespace |
| 151 | std::string namespace_; |
| 152 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 153 | // Included programs |
| 154 | std::vector<t_program*> includes_; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 155 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 156 | // Identifier lookup scope |
| 157 | t_scope* scope_; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 158 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 159 | // Components to generate code for |
| 160 | std::vector<t_typedef*> typedefs_; |
| 161 | std::vector<t_enum*> enums_; |
Mark Slee | 3015287 | 2006-11-28 01:24:07 +0000 | [diff] [blame] | 162 | std::vector<t_const*> consts_; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 163 | std::vector<t_struct*> structs_; |
| 164 | std::vector<t_struct*> xceptions_; |
| 165 | std::vector<t_service*> services_; |
| 166 | |
| 167 | // C++ namespace |
| 168 | std::string cpp_namespace_; |
| 169 | |
| 170 | // C++ extra includes |
| 171 | std::vector<std::string> cpp_includes_; |
| 172 | |
Mark Slee | e888b37 | 2007-01-12 01:06:24 +0000 | [diff] [blame] | 173 | // PHP namespace |
| 174 | std::string php_namespace_; |
| 175 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 176 | // Java package |
| 177 | std::string java_package_; |
| 178 | |
Mark Slee | 0d9199e | 2007-01-31 02:08:30 +0000 | [diff] [blame] | 179 | // XSD namespace |
| 180 | std::string xsd_namespace_; |
| 181 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | #endif |