Thrift compiler improvements, two modes for PHP
Summary: Complete PHP generator and CPP generator to new formats, and offer PHP generator that generates inline code free of any TProtocol abstraction
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664771 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h
index cda24c6..98968ff 100644
--- a/compiler/cpp/src/parse/t_program.h
+++ b/compiler/cpp/src/parse/t_program.h
@@ -21,6 +21,7 @@
* Typedefs
* Enumerations
* Structs
+ * Exceptions
* Services
*
* @author Mark Slee <mcslee@facebook.com>
@@ -28,52 +29,54 @@
class t_program {
public:
t_program(std::string name) :
- name_(name) {
+ name_(name), namespace_() {
type_void = new t_base_type("void", t_base_type::TYPE_VOID);
type_string = new t_base_type("string", t_base_type::TYPE_STRING);
type_byte = new t_base_type("byte", t_base_type::TYPE_BYTE);
+ type_i16 = new t_base_type("i16", t_base_type::TYPE_I16);
type_i32 = new t_base_type("i32", t_base_type::TYPE_I32);
- type_u32 = new t_base_type("u32", t_base_type::TYPE_U32);
type_i64 = new t_base_type("i64", t_base_type::TYPE_I64);
- type_u64 = new t_base_type("u64", t_base_type::TYPE_U64);
}
~t_program() {
delete type_string;
delete type_byte;
+ delete type_i16;
delete type_i32;
- delete type_u32;
delete type_i64;
- delete type_u64;
}
// Name accessor
const std::string& get_name() const { return name_; }
+ // Namespace
+ const std::string& get_namespace() const { return namespace_; }
+
// Accessors for program elements
- const std::vector<t_typedef*>& get_typedefs() const { return typedefs_; }
- const std::vector<t_enum*>& get_enums() const { return enums_; }
- const std::vector<t_struct*>& get_structs() const { return structs_; }
- const std::vector<t_service*>& get_services() const { return services_; }
+ const std::vector<t_typedef*>& get_typedefs() const { return typedefs_; }
+ const std::vector<t_enum*>& get_enums() const { return enums_; }
+ const std::vector<t_struct*>& get_structs() const { return structs_; }
+ const std::vector<t_struct*>& get_xceptions() const { return xceptions_; }
+ const std::vector<t_service*>& get_services() const { return services_; }
// Accessors for global types
t_type* get_void_type() const { return type_void; }
t_type* get_string_type() const { return type_string; }
t_type* get_byte_type() const { return type_byte; }
+ t_type* get_i16_type() const { return type_i16; }
t_type* get_i32_type() const { return type_i32; }
- t_type* get_u32_type() const { return type_u32; }
t_type* get_i64_type() const { return type_i64; }
- t_type* get_u64_type() const { return type_u64; }
// Custom data type lookup
- void add_custom_type(std::string name, t_type* type) {
- custom_types_[name] = type;
- }
t_type* get_custom_type(std::string name) {
return custom_types_[name];
}
// New program element addition
+ void set_namespace(std::string name) {
+ namespace_ = name;
+ }
+
void add_typedef(t_typedef* td) {
typedefs_.push_back(td);
add_custom_type(td->get_symbolic(), td);
@@ -86,19 +89,32 @@
structs_.push_back(ts);
add_custom_type(ts->get_name(), ts);
}
+ void add_xception(t_struct* tx) {
+ xceptions_.push_back(tx);
+ add_custom_type(tx->get_name(), tx);
+ }
void add_service(t_service* ts) {
services_.push_back(ts);
}
private:
+ // Add custom type for lookup
+ void add_custom_type(std::string name, t_type* type) {
+ custom_types_[name] = type;
+ }
+
// Name
std::string name_;
+ // Namespace
+ std::string namespace_;
+
// Components
- std::vector<t_typedef*> typedefs_;
- std::vector<t_enum*> enums_;
- std::vector<t_struct*> structs_;
- std::vector<t_service*> services_;
+ std::vector<t_typedef*> typedefs_;
+ std::vector<t_enum*> enums_;
+ std::vector<t_struct*> structs_;
+ std::vector<t_struct*> xceptions_;
+ std::vector<t_service*> services_;
// Type map
std::map<std::string, t_type*> custom_types_;
@@ -107,10 +123,9 @@
t_type* type_void;
t_type* type_string;
t_type* type_byte;
+ t_type* type_i16;
t_type* type_i32;
- t_type* type_u32;
t_type* type_i64;
- t_type* type_u64;
};
#endif