Thrift now a TLP - INFRA-3116
git-svn-id: https://svn.apache.org/repos/asf/thrift/branches/0.1.x@1028168 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/parse/t_base_type.h b/compiler/cpp/src/parse/t_base_type.h
new file mode 100644
index 0000000..1751df9
--- /dev/null
+++ b/compiler/cpp/src/parse/t_base_type.h
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_BASE_TYPE_H
+#define T_BASE_TYPE_H
+
+#include <cstdlib>
+#include "t_type.h"
+
+/**
+ * A thrift base type, which must be one of the defined enumerated types inside
+ * this definition.
+ *
+ */
+class t_base_type : public t_type {
+ public:
+ /**
+ * Enumeration of thrift base types
+ */
+ enum t_base {
+ TYPE_VOID,
+ TYPE_STRING,
+ TYPE_BOOL,
+ TYPE_BYTE,
+ TYPE_I16,
+ TYPE_I32,
+ TYPE_I64,
+ TYPE_DOUBLE
+ };
+
+ t_base_type(std::string name, t_base base) :
+ t_type(name),
+ base_(base),
+ string_list_(false),
+ binary_(false),
+ string_enum_(false){}
+
+ t_base get_base() const {
+ return base_;
+ }
+
+ bool is_void() const {
+ return base_ == TYPE_VOID;
+ }
+
+ bool is_string() const {
+ return base_ == TYPE_STRING;
+ }
+
+ bool is_bool() const {
+ return base_ == TYPE_BOOL;
+ }
+
+ void set_string_list(bool val) {
+ string_list_ = val;
+ }
+
+ bool is_string_list() const {
+ return (base_ == TYPE_STRING) && string_list_;
+ }
+
+ void set_binary(bool val) {
+ binary_ = val;
+ }
+
+ bool is_binary() const {
+ return (base_ == TYPE_STRING) && binary_;
+ }
+
+ void set_string_enum(bool val) {
+ string_enum_ = true;
+ }
+
+ bool is_string_enum() const {
+ return base_ == TYPE_STRING && string_enum_;
+ }
+
+ void add_string_enum_val(std::string val) {
+ string_enum_vals_.push_back(val);
+ }
+
+ const std::vector<std::string>& get_string_enum_vals() const {
+ return string_enum_vals_;
+ }
+
+ bool is_base_type() const {
+ return true;
+ }
+
+ virtual std::string get_fingerprint_material() const {
+ std::string rv = t_base_name(base_);
+ if (rv == "(unknown)") {
+ throw "BUG: Can't get fingerprint material for this base type.";
+ }
+ return rv;
+ }
+
+ static std::string t_base_name(t_base tbase) {
+ switch (tbase) {
+ case TYPE_VOID : return "void"; break;
+ case TYPE_STRING : return "string"; break;
+ case TYPE_BOOL : return "bool"; break;
+ case TYPE_BYTE : return "byte"; break;
+ case TYPE_I16 : return "i16"; break;
+ case TYPE_I32 : return "i32"; break;
+ case TYPE_I64 : return "i64"; break;
+ case TYPE_DOUBLE : return "double"; break;
+ default : return "(unknown)"; break;
+ }
+ }
+
+ private:
+ t_base base_;
+
+ bool string_list_;
+ bool binary_;
+ bool string_enum_;
+ std::vector<std::string> string_enum_vals_;
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_const.h b/compiler/cpp/src/parse/t_const.h
new file mode 100644
index 0000000..7fd81bd
--- /dev/null
+++ b/compiler/cpp/src/parse/t_const.h
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_CONST_H
+#define T_CONST_H
+
+#include "t_type.h"
+#include "t_const_value.h"
+
+/**
+ * A const is a constant value defined across languages that has a type and
+ * a value. The trick here is that the declared type might not match the type
+ * of the value object, since that is not determined until after parsing the
+ * whole thing out.
+ *
+ */
+class t_const : public t_doc {
+ public:
+ t_const(t_type* type, std::string name, t_const_value* value) :
+ type_(type),
+ name_(name),
+ value_(value) {}
+
+ t_type* get_type() const {
+ return type_;
+ }
+
+ std::string get_name() const {
+ return name_;
+ }
+
+ t_const_value* get_value() const {
+ return value_;
+ }
+
+ private:
+ t_type* type_;
+ std::string name_;
+ t_const_value* value_;
+};
+
+#endif
+
diff --git a/compiler/cpp/src/parse/t_const_value.h b/compiler/cpp/src/parse/t_const_value.h
new file mode 100644
index 0000000..a7d6e31
--- /dev/null
+++ b/compiler/cpp/src/parse/t_const_value.h
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_CONST_VALUE_H
+#define T_CONST_VALUE_H
+
+#include "t_const.h"
+#include <stdint.h>
+#include <map>
+#include <vector>
+
+/**
+ * A const value is something parsed that could be a map, set, list, struct
+ * or whatever.
+ *
+ */
+class t_const_value {
+ public:
+
+ enum t_const_value_type {
+ CV_INTEGER,
+ CV_DOUBLE,
+ CV_STRING,
+ CV_MAP,
+ CV_LIST
+ };
+
+ t_const_value() {}
+
+ t_const_value(int64_t val) {
+ set_integer(val);
+ }
+
+ t_const_value(std::string val) {
+ set_string(val);
+ }
+
+ void set_string(std::string val) {
+ valType_ = CV_STRING;
+ stringVal_ = val;
+ }
+
+ std::string get_string() const {
+ return stringVal_;
+ }
+
+ void set_integer(int64_t val) {
+ valType_ = CV_INTEGER;
+ intVal_ = val;
+ }
+
+ int64_t get_integer() const {
+ return intVal_;
+ }
+
+ void set_double(double val) {
+ valType_ = CV_DOUBLE;
+ doubleVal_ = val;
+ }
+
+ double get_double() const {
+ return doubleVal_;
+ }
+
+ void set_map() {
+ valType_ = CV_MAP;
+ }
+
+ void add_map(t_const_value* key, t_const_value* val) {
+ mapVal_[key] = val;
+ }
+
+ const std::map<t_const_value*, t_const_value*>& get_map() const {
+ return mapVal_;
+ }
+
+ void set_list() {
+ valType_ = CV_LIST;
+ }
+
+ void add_list(t_const_value* val) {
+ listVal_.push_back(val);
+ }
+
+ const std::vector<t_const_value*>& get_list() const {
+ return listVal_;
+ }
+
+ t_const_value_type get_type() const {
+ return valType_;
+ }
+
+ private:
+ std::map<t_const_value*, t_const_value*> mapVal_;
+ std::vector<t_const_value*> listVal_;
+ std::string stringVal_;
+ int64_t intVal_;
+ double doubleVal_;
+
+ t_const_value_type valType_;
+
+};
+
+#endif
+
diff --git a/compiler/cpp/src/parse/t_container.h b/compiler/cpp/src/parse/t_container.h
new file mode 100644
index 0000000..6753493
--- /dev/null
+++ b/compiler/cpp/src/parse/t_container.h
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_CONTAINER_H
+#define T_CONTAINER_H
+
+#include "t_type.h"
+
+class t_container : public t_type {
+ public:
+ t_container() :
+ cpp_name_(),
+ has_cpp_name_(false) {}
+
+ virtual ~t_container() {}
+
+ void set_cpp_name(std::string cpp_name) {
+ cpp_name_ = cpp_name;
+ has_cpp_name_ = true;
+ }
+
+ bool has_cpp_name() {
+ return has_cpp_name_;
+ }
+
+ std::string get_cpp_name() {
+ return cpp_name_;
+ }
+
+ bool is_container() const {
+ return true;
+ }
+
+ private:
+ std::string cpp_name_;
+ bool has_cpp_name_;
+
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_doc.h b/compiler/cpp/src/parse/t_doc.h
new file mode 100644
index 0000000..e52068c
--- /dev/null
+++ b/compiler/cpp/src/parse/t_doc.h
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_DOC_H
+#define T_DOC_H
+
+/**
+ * Documentation stubs
+ *
+ */
+class t_doc {
+
+ public:
+ t_doc() : has_doc_(false) {}
+
+ void set_doc(const std::string& doc) {
+ doc_ = doc;
+ has_doc_ = true;
+ }
+
+ const std::string& get_doc() const {
+ return doc_;
+ }
+
+ bool has_doc() {
+ return has_doc_;
+ }
+
+ private:
+ std::string doc_;
+ bool has_doc_;
+
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_enum.h b/compiler/cpp/src/parse/t_enum.h
new file mode 100644
index 0000000..740f95c
--- /dev/null
+++ b/compiler/cpp/src/parse/t_enum.h
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_ENUM_H
+#define T_ENUM_H
+
+#include "t_enum_value.h"
+#include <vector>
+
+/**
+ * An enumerated type. A list of constant objects with a name for the type.
+ *
+ */
+class t_enum : public t_type {
+ public:
+ t_enum(t_program* program) :
+ t_type(program) {}
+
+ void set_name(const std::string& name) {
+ name_ = name;
+ }
+
+ void append(t_enum_value* constant) {
+ constants_.push_back(constant);
+ }
+
+ const std::vector<t_enum_value*>& get_constants() {
+ return constants_;
+ }
+
+ bool is_enum() const {
+ return true;
+ }
+
+ virtual std::string get_fingerprint_material() const {
+ return "enum";
+ }
+
+ private:
+ std::vector<t_enum_value*> constants_;
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_enum_value.h b/compiler/cpp/src/parse/t_enum_value.h
new file mode 100644
index 0000000..68e905b
--- /dev/null
+++ b/compiler/cpp/src/parse/t_enum_value.h
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_ENUM_VALUE_H
+#define T_ENUM_VALUE_H
+
+#include <string>
+#include "t_doc.h"
+
+/**
+ * A constant. These are used inside of enum definitions. Constants are just
+ * symbol identifiers that may or may not have an explicit value associated
+ * with them.
+ *
+ */
+class t_enum_value : public t_doc {
+ public:
+ t_enum_value(std::string name) :
+ name_(name),
+ has_value_(false),
+ value_(0) {}
+
+ t_enum_value(std::string name, int value) :
+ name_(name),
+ has_value_(true),
+ value_(value) {}
+
+ ~t_enum_value() {}
+
+ const std::string& get_name() {
+ return name_;
+ }
+
+ bool has_value() {
+ return has_value_;
+ }
+
+ int get_value() {
+ return value_;
+ }
+
+ private:
+ std::string name_;
+ bool has_value_;
+ int value_;
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_field.h b/compiler/cpp/src/parse/t_field.h
new file mode 100644
index 0000000..67a2125
--- /dev/null
+++ b/compiler/cpp/src/parse/t_field.h
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_FIELD_H
+#define T_FIELD_H
+
+#include <string>
+#include <boost/lexical_cast.hpp>
+
+#include "t_doc.h"
+
+// Forward declare for xsd_attrs
+class t_struct;
+
+/**
+ * Class to represent a field in a thrift structure. A field has a data type,
+ * a symbolic name, and a numeric identifier.
+ *
+ */
+class t_field : public t_doc {
+ public:
+ t_field(t_type* type, std::string name) :
+ type_(type),
+ name_(name),
+ key_(0),
+ value_(NULL),
+ xsd_optional_(false),
+ xsd_nillable_(false),
+ xsd_attrs_(NULL) {}
+
+ t_field(t_type* type, std::string name, int32_t key) :
+ type_(type),
+ name_(name),
+ key_(key),
+ req_(T_OPT_IN_REQ_OUT),
+ value_(NULL),
+ xsd_optional_(false),
+ xsd_nillable_(false),
+ xsd_attrs_(NULL) {}
+
+ ~t_field() {}
+
+ t_type* get_type() const {
+ return type_;
+ }
+
+ const std::string& get_name() const {
+ return name_;
+ }
+
+ int32_t get_key() const {
+ return key_;
+ }
+
+ enum e_req {
+ T_REQUIRED,
+ T_OPTIONAL,
+ T_OPT_IN_REQ_OUT,
+ };
+
+ void set_req(e_req req) {
+ req_ = req;
+ }
+
+ e_req get_req() const {
+ return req_;
+ }
+
+ void set_value(t_const_value* value) {
+ value_ = value;
+ }
+
+ t_const_value* get_value() {
+ return value_;
+ }
+
+ void set_xsd_optional(bool xsd_optional) {
+ xsd_optional_ = xsd_optional;
+ }
+
+ bool get_xsd_optional() const {
+ return xsd_optional_;
+ }
+
+ void set_xsd_nillable(bool xsd_nillable) {
+ xsd_nillable_ = xsd_nillable;
+ }
+
+ bool get_xsd_nillable() const {
+ return xsd_nillable_;
+ }
+
+ void set_xsd_attrs(t_struct* xsd_attrs) {
+ xsd_attrs_ = xsd_attrs;
+ }
+
+ t_struct* get_xsd_attrs() {
+ return xsd_attrs_;
+ }
+
+ // This is not the same function as t_type::get_fingerprint_material,
+ // but it does the same thing.
+ std::string get_fingerprint_material() const {
+ return boost::lexical_cast<std::string>(key_) + ":" +
+ ((req_ == T_OPTIONAL) ? "opt-" : "") +
+ type_->get_fingerprint_material();
+ }
+
+ /**
+ * Comparator to sort fields in ascending order by key.
+ * Make this a functor instead of a function to help GCC inline it.
+ * The arguments are (const) references to const pointers to const t_fields.
+ */
+ struct key_compare {
+ bool operator()(t_field const * const & a, t_field const * const & b) {
+ return a->get_key() < b->get_key();
+ }
+ };
+
+
+ private:
+ t_type* type_;
+ std::string name_;
+ int32_t key_;
+ e_req req_;
+ t_const_value* value_;
+
+ bool xsd_optional_;
+ bool xsd_nillable_;
+ t_struct* xsd_attrs_;
+
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_function.h b/compiler/cpp/src/parse/t_function.h
new file mode 100644
index 0000000..a72aa6c
--- /dev/null
+++ b/compiler/cpp/src/parse/t_function.h
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_FUNCTION_H
+#define T_FUNCTION_H
+
+#include <string>
+#include "t_type.h"
+#include "t_struct.h"
+#include "t_doc.h"
+
+/**
+ * Representation of a function. Key parts are return type, function name,
+ * optional modifiers, and an argument list, which is implemented as a thrift
+ * struct.
+ *
+ */
+class t_function : public t_doc {
+ public:
+ t_function(t_type* returntype,
+ std::string name,
+ t_struct* arglist,
+ bool oneway=false) :
+ returntype_(returntype),
+ name_(name),
+ arglist_(arglist),
+ oneway_(oneway) {
+ xceptions_ = new t_struct(NULL);
+ }
+
+ t_function(t_type* returntype,
+ std::string name,
+ t_struct* arglist,
+ t_struct* xceptions,
+ bool oneway=false) :
+ returntype_(returntype),
+ name_(name),
+ arglist_(arglist),
+ xceptions_(xceptions),
+ oneway_(oneway)
+ {
+ if (oneway_ && !xceptions_->get_members().empty()) {
+ throw std::string("Oneway methods can't throw exceptions.");
+ }
+ }
+
+ ~t_function() {}
+
+ t_type* get_returntype() const {
+ return returntype_;
+ }
+
+ const std::string& get_name() const {
+ return name_;
+ }
+
+ t_struct* get_arglist() const {
+ return arglist_;
+ }
+
+ t_struct* get_xceptions() const {
+ return xceptions_;
+ }
+
+ bool is_oneway() const {
+ return oneway_;
+ }
+
+ private:
+ t_type* returntype_;
+ std::string name_;
+ t_struct* arglist_;
+ t_struct* xceptions_;
+ bool oneway_;
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_list.h b/compiler/cpp/src/parse/t_list.h
new file mode 100644
index 0000000..21a9625
--- /dev/null
+++ b/compiler/cpp/src/parse/t_list.h
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_LIST_H
+#define T_LIST_H
+
+#include "t_container.h"
+
+/**
+ * A list is a lightweight container type that just wraps another data type.
+ *
+ */
+class t_list : public t_container {
+ public:
+ t_list(t_type* elem_type) :
+ elem_type_(elem_type) {}
+
+ t_type* get_elem_type() const {
+ return elem_type_;
+ }
+
+ bool is_list() const {
+ return true;
+ }
+
+ virtual std::string get_fingerprint_material() const {
+ return "list<" + elem_type_->get_fingerprint_material() + ">";
+ }
+
+ virtual void generate_fingerprint() {
+ t_type::generate_fingerprint();
+ elem_type_->generate_fingerprint();
+ }
+
+ private:
+ t_type* elem_type_;
+};
+
+#endif
+
diff --git a/compiler/cpp/src/parse/t_map.h b/compiler/cpp/src/parse/t_map.h
new file mode 100644
index 0000000..c4e358f
--- /dev/null
+++ b/compiler/cpp/src/parse/t_map.h
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_MAP_H
+#define T_MAP_H
+
+#include "t_container.h"
+
+/**
+ * A map is a lightweight container type that just wraps another two data
+ * types.
+ *
+ */
+class t_map : public t_container {
+ public:
+ t_map(t_type* key_type, t_type* val_type) :
+ key_type_(key_type),
+ val_type_(val_type) {}
+
+ t_type* get_key_type() const {
+ return key_type_;
+ }
+
+ t_type* get_val_type() const {
+ return val_type_;
+ }
+
+ bool is_map() const {
+ return true;
+ }
+
+ virtual std::string get_fingerprint_material() const {
+ return "map<" + key_type_->get_fingerprint_material() +
+ "," + val_type_->get_fingerprint_material() + ">";
+ }
+
+ virtual void generate_fingerprint() {
+ t_type::generate_fingerprint();
+ key_type_->generate_fingerprint();
+ val_type_->generate_fingerprint();
+ }
+
+ private:
+ t_type* key_type_;
+ t_type* val_type_;
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h
new file mode 100644
index 0000000..4e1ab6a
--- /dev/null
+++ b/compiler/cpp/src/parse/t_program.h
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_PROGRAM_H
+#define T_PROGRAM_H
+
+#include <map>
+#include <string>
+#include <vector>
+
+// For program_name()
+#include "main.h"
+
+#include "t_doc.h"
+#include "t_scope.h"
+#include "t_base_type.h"
+#include "t_typedef.h"
+#include "t_enum.h"
+#include "t_const.h"
+#include "t_struct.h"
+#include "t_service.h"
+#include "t_list.h"
+#include "t_map.h"
+#include "t_set.h"
+//#include "t_doc.h"
+
+/**
+ * Top level class representing an entire thrift program. A program consists
+ * fundamentally of the following:
+ *
+ * Typedefs
+ * Enumerations
+ * Constants
+ * Structs
+ * Exceptions
+ * Services
+ *
+ * The program module also contains the definitions of the base types.
+ *
+ */
+class t_program : public t_doc {
+ public:
+ t_program(std::string path, std::string name) :
+ path_(path),
+ name_(name),
+ out_path_("./") {
+ scope_ = new t_scope();
+ }
+
+ t_program(std::string path) :
+ path_(path),
+ out_path_("./") {
+ name_ = program_name(path);
+ scope_ = new t_scope();
+ }
+
+ // Path accessor
+ const std::string& get_path() const { return path_; }
+
+ // Output path accessor
+ const std::string& get_out_path() const { return out_path_; }
+
+ // Name accessor
+ const std::string& get_name() const { return name_; }
+
+ // Namespace
+ const std::string& get_namespace() const { return namespace_; }
+
+ // Include prefix accessor
+ const std::string& get_include_prefix() const { return include_prefix_; }
+
+ // 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_const*>& get_consts() const { return consts_; }
+ const std::vector<t_struct*>& get_structs() const { return structs_; }
+ const std::vector<t_struct*>& get_xceptions() const { return xceptions_; }
+ const std::vector<t_struct*>& get_objects() const { return objects_; }
+ const std::vector<t_service*>& get_services() const { return services_; }
+
+ // Program elements
+ void add_typedef (t_typedef* td) { typedefs_.push_back(td); }
+ void add_enum (t_enum* te) { enums_.push_back(te); }
+ void add_const (t_const* tc) { consts_.push_back(tc); }
+ void add_struct (t_struct* ts) { objects_.push_back(ts);
+ structs_.push_back(ts); }
+ void add_xception (t_struct* tx) { objects_.push_back(tx);
+ xceptions_.push_back(tx); }
+ void add_service (t_service* ts) { services_.push_back(ts); }
+
+ // Programs to include
+ const std::vector<t_program*>& get_includes() const { return includes_; }
+
+ void set_out_path(std::string out_path) {
+ out_path_ = out_path;
+ // Ensure that it ends with a trailing '/' (or '\' for windows machines)
+ char c = out_path_.at(out_path_.size() - 1);
+ if (!(c == '/' || c == '\\')) {
+ out_path_.push_back('/');
+ }
+ }
+
+ // Scoping and namespacing
+ void set_namespace(std::string name) {
+ namespace_ = name;
+ }
+
+ // Scope accessor
+ t_scope* scope() {
+ return scope_;
+ }
+
+ // Includes
+
+ void add_include(std::string path, std::string include_site) {
+ t_program* program = new t_program(path);
+
+ // include prefix for this program is the site at which it was included
+ // (minus the filename)
+ std::string include_prefix;
+ std::string::size_type last_slash = std::string::npos;
+ if ((last_slash = include_site.rfind("/")) != std::string::npos) {
+ include_prefix = include_site.substr(0, last_slash);
+ }
+
+ program->set_include_prefix(include_prefix);
+ includes_.push_back(program);
+ }
+
+ std::vector<t_program*>& get_includes() {
+ return includes_;
+ }
+
+ void set_include_prefix(std::string include_prefix) {
+ include_prefix_ = include_prefix;
+
+ // this is intended to be a directory; add a trailing slash if necessary
+ int len = include_prefix_.size();
+ if (len > 0 && include_prefix_[len - 1] != '/') {
+ include_prefix_ += '/';
+ }
+ }
+
+ // Language neutral namespace / packaging
+ void set_namespace(std::string language, std::string name_space) {
+ namespaces_[language] = name_space;
+ }
+
+ std::string get_namespace(std::string language) const {
+ std::map<std::string, std::string>::const_iterator iter = namespaces_.find(language);
+ if (iter == namespaces_.end()) {
+ return std::string();
+ }
+ return iter->second;
+ }
+
+ // Language specific namespace / packaging
+
+ void add_cpp_include(std::string path) {
+ cpp_includes_.push_back(path);
+ }
+
+ const std::vector<std::string>& get_cpp_includes() {
+ return cpp_includes_;
+ }
+
+ private:
+
+ // File path
+ std::string path_;
+
+ // Name
+ std::string name_;
+
+ // Output directory
+ std::string out_path_;
+
+ // Namespace
+ std::string namespace_;
+
+ // Included programs
+ std::vector<t_program*> includes_;
+
+ // Include prefix for this program, if any
+ std::string include_prefix_;
+
+ // Identifier lookup scope
+ t_scope* scope_;
+
+ // Components to generate code for
+ std::vector<t_typedef*> typedefs_;
+ std::vector<t_enum*> enums_;
+ std::vector<t_const*> consts_;
+ std::vector<t_struct*> objects_;
+ std::vector<t_struct*> structs_;
+ std::vector<t_struct*> xceptions_;
+ std::vector<t_service*> services_;
+
+ // Dynamic namespaces
+ std::map<std::string, std::string> namespaces_;
+
+ // C++ extra includes
+ std::vector<std::string> cpp_includes_;
+
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_scope.h b/compiler/cpp/src/parse/t_scope.h
new file mode 100644
index 0000000..122e325
--- /dev/null
+++ b/compiler/cpp/src/parse/t_scope.h
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_SCOPE_H
+#define T_SCOPE_H
+
+#include <map>
+#include <string>
+
+#include "t_type.h"
+#include "t_service.h"
+
+/**
+ * This represents a variable scope used for looking up predefined types and
+ * services. Typically, a scope is associated with a t_program. Scopes are not
+ * used to determine code generation, but rather to resolve identifiers at
+ * parse time.
+ *
+ */
+class t_scope {
+ public:
+ t_scope() {}
+
+ void add_type(std::string name, t_type* type) {
+ types_[name] = type;
+ }
+
+ t_type* get_type(std::string name) {
+ return types_[name];
+ }
+
+ void add_service(std::string name, t_service* service) {
+ services_[name] = service;
+ }
+
+ t_service* get_service(std::string name) {
+ return services_[name];
+ }
+
+ void add_constant(std::string name, t_const* constant) {
+ constants_[name] = constant;
+ }
+
+ t_const* get_constant(std::string name) {
+ return constants_[name];
+ }
+
+ void print() {
+ std::map<std::string, t_type*>::iterator iter;
+ for (iter = types_.begin(); iter != types_.end(); ++iter) {
+ printf("%s => %s\n",
+ iter->first.c_str(),
+ iter->second->get_name().c_str());
+ }
+ }
+
+ private:
+
+ // Map of names to types
+ std::map<std::string, t_type*> types_;
+
+ // Map of names to constants
+ std::map<std::string, t_const*> constants_;
+
+ // Map of names to services
+ std::map<std::string, t_service*> services_;
+
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_service.h b/compiler/cpp/src/parse/t_service.h
new file mode 100644
index 0000000..eee2dac
--- /dev/null
+++ b/compiler/cpp/src/parse/t_service.h
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_SERVICE_H
+#define T_SERVICE_H
+
+#include "t_function.h"
+#include <vector>
+
+class t_program;
+
+/**
+ * A service consists of a set of functions.
+ *
+ */
+class t_service : public t_type {
+ public:
+ t_service(t_program* program) :
+ t_type(program),
+ extends_(NULL) {}
+
+ bool is_service() const {
+ return true;
+ }
+
+ void set_extends(t_service* extends) {
+ extends_ = extends;
+ }
+
+ void add_function(t_function* func) {
+ functions_.push_back(func);
+ }
+
+ const std::vector<t_function*>& get_functions() const {
+ return functions_;
+ }
+
+ t_service* get_extends() {
+ return extends_;
+ }
+
+ virtual std::string get_fingerprint_material() const {
+ // Services should never be used in fingerprints.
+ throw "BUG: Can't get fingerprint material for service.";
+ }
+
+ private:
+ std::vector<t_function*> functions_;
+ t_service* extends_;
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_set.h b/compiler/cpp/src/parse/t_set.h
new file mode 100644
index 0000000..d198357
--- /dev/null
+++ b/compiler/cpp/src/parse/t_set.h
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_SET_H
+#define T_SET_H
+
+#include "t_container.h"
+
+/**
+ * A set is a lightweight container type that just wraps another data type.
+ *
+ */
+class t_set : public t_container {
+ public:
+ t_set(t_type* elem_type) :
+ elem_type_(elem_type) {}
+
+ t_type* get_elem_type() const {
+ return elem_type_;
+ }
+
+ bool is_set() const {
+ return true;
+ }
+
+ virtual std::string get_fingerprint_material() const {
+ return "set<" + elem_type_->get_fingerprint_material() + ">";
+ }
+
+ virtual void generate_fingerprint() {
+ t_type::generate_fingerprint();
+ elem_type_->generate_fingerprint();
+ }
+
+ private:
+ t_type* elem_type_;
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_struct.h b/compiler/cpp/src/parse/t_struct.h
new file mode 100644
index 0000000..7980f80
--- /dev/null
+++ b/compiler/cpp/src/parse/t_struct.h
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_STRUCT_H
+#define T_STRUCT_H
+
+#include <algorithm>
+#include <vector>
+#include <utility>
+#include <string>
+
+#include "t_type.h"
+#include "t_field.h"
+
+// Forward declare that puppy
+class t_program;
+
+/**
+ * A struct is a container for a set of member fields that has a name. Structs
+ * are also used to implement exception types.
+ *
+ */
+class t_struct : public t_type {
+ public:
+ typedef std::vector<t_field*> members_type;
+
+ t_struct(t_program* program) :
+ t_type(program),
+ is_xception_(false),
+ xsd_all_(false) {}
+
+ t_struct(t_program* program, const std::string& name) :
+ t_type(program, name),
+ is_xception_(false),
+ xsd_all_(false) {}
+
+ void set_name(const std::string& name) {
+ name_ = name;
+ }
+
+ void set_xception(bool is_xception) {
+ is_xception_ = is_xception;
+ }
+
+ void set_xsd_all(bool xsd_all) {
+ xsd_all_ = xsd_all;
+ }
+
+ bool get_xsd_all() const {
+ return xsd_all_;
+ }
+
+ bool append(t_field* elem) {
+ members_.push_back(elem);
+
+ typedef members_type::iterator iter_type;
+ std::pair<iter_type, iter_type> bounds = std::equal_range(
+ members_in_id_order_.begin(), members_in_id_order_.end(), elem, t_field::key_compare()
+ );
+ if (bounds.first != bounds.second) {
+ return false;
+ }
+ members_in_id_order_.insert(bounds.second, elem);
+ return true;
+ }
+
+ const members_type& get_members() {
+ return members_;
+ }
+
+ const members_type& get_sorted_members() {
+ return members_in_id_order_;
+ }
+
+ bool is_struct() const {
+ return !is_xception_;
+ }
+
+ bool is_xception() const {
+ return is_xception_;
+ }
+
+ virtual std::string get_fingerprint_material() const {
+ std::string rv = "{";
+ members_type::const_iterator m_iter;
+ for (m_iter = members_in_id_order_.begin(); m_iter != members_in_id_order_.end(); ++m_iter) {
+ rv += (*m_iter)->get_fingerprint_material();
+ rv += ";";
+ }
+ rv += "}";
+ return rv;
+ }
+
+ virtual void generate_fingerprint() {
+ t_type::generate_fingerprint();
+ members_type::const_iterator m_iter;
+ for (m_iter = members_in_id_order_.begin(); m_iter != members_in_id_order_.end(); ++m_iter) {
+ (*m_iter)->get_type()->generate_fingerprint();
+ }
+ }
+
+ private:
+
+ members_type members_;
+ members_type members_in_id_order_;
+ bool is_xception_;
+
+ bool xsd_all_;
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_type.h b/compiler/cpp/src/parse/t_type.h
new file mode 100644
index 0000000..4ce2eda
--- /dev/null
+++ b/compiler/cpp/src/parse/t_type.h
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_TYPE_H
+#define T_TYPE_H
+
+#include <string>
+#include <map>
+#include <cstring>
+#include <stdint.h>
+#include "t_doc.h"
+
+// What's worse? This, or making a src/parse/non_inlined.cc?
+#include "md5.h"
+
+class t_program;
+
+/**
+ * Generic representation of a thrift type. These objects are used by the
+ * parser module to build up a tree of object that are all explicitly typed.
+ * The generic t_type class exports a variety of useful methods that are
+ * used by the code generator to branch based upon different handling for the
+ * various types.
+ *
+ */
+class t_type : public t_doc {
+ public:
+ virtual ~t_type() {}
+
+ virtual void set_name(const std::string& name) {
+ name_ = name;
+ }
+
+ virtual const std::string& get_name() const {
+ return name_;
+ }
+
+ virtual bool is_void() const { return false; }
+ virtual bool is_base_type() const { return false; }
+ virtual bool is_string() const { return false; }
+ virtual bool is_bool() const { return false; }
+ virtual bool is_typedef() const { return false; }
+ virtual bool is_enum() const { return false; }
+ virtual bool is_struct() const { return false; }
+ virtual bool is_xception() const { return false; }
+ virtual bool is_container() const { return false; }
+ virtual bool is_list() const { return false; }
+ virtual bool is_set() const { return false; }
+ virtual bool is_map() const { return false; }
+ virtual bool is_service() const { return false; }
+
+ t_program* get_program() {
+ return program_;
+ }
+
+
+ // Return a string that uniquely identifies this type
+ // from any other thrift type in the world, as far as
+ // TDenseProtocol is concerned.
+ // We don't cache this, which is a little sloppy,
+ // but the compiler is so fast that it doesn't really matter.
+ virtual std::string get_fingerprint_material() const = 0;
+
+ // Fingerprint should change whenever (and only when)
+ // the encoding via TDenseProtocol changes.
+ static const int fingerprint_len = 16;
+
+ // Call this before trying get_*_fingerprint().
+ virtual void generate_fingerprint() {
+ std::string material = get_fingerprint_material();
+ md5_state_t ctx;
+ md5_init(&ctx);
+ md5_append(&ctx, (md5_byte_t*)(material.data()), (int)material.size());
+ md5_finish(&ctx, (md5_byte_t*)fingerprint_);
+ }
+
+ bool has_fingerprint() const {
+ for (int i = 0; i < fingerprint_len; i++) {
+ if (fingerprint_[i] != 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ const uint8_t* get_binary_fingerprint() const {
+ return fingerprint_;
+ }
+
+ std::string get_ascii_fingerprint() const {
+ std::string rv;
+ const uint8_t* fp = get_binary_fingerprint();
+ for (int i = 0; i < fingerprint_len; i++) {
+ rv += byte_to_hex(fp[i]);
+ }
+ return rv;
+ }
+
+ // This function will break (maybe badly) unless 0 <= num <= 16.
+ static char nybble_to_xdigit(int num) {
+ if (num < 10) {
+ return '0' + num;
+ } else {
+ return 'A' + num - 10;
+ }
+ }
+
+ static std::string byte_to_hex(uint8_t byte) {
+ std::string rv;
+ rv += nybble_to_xdigit(byte >> 4);
+ rv += nybble_to_xdigit(byte & 0x0f);
+ return rv;
+ }
+
+ std::map<std::string, std::string> annotations_;
+
+ protected:
+ t_type() :
+ program_(NULL)
+ {
+ memset(fingerprint_, 0, sizeof(fingerprint_));
+ }
+
+ t_type(t_program* program) :
+ program_(program)
+ {
+ memset(fingerprint_, 0, sizeof(fingerprint_));
+ }
+
+ t_type(t_program* program, std::string name) :
+ program_(program),
+ name_(name)
+ {
+ memset(fingerprint_, 0, sizeof(fingerprint_));
+ }
+
+ t_type(std::string name) :
+ program_(NULL),
+ name_(name)
+ {
+ memset(fingerprint_, 0, sizeof(fingerprint_));
+ }
+
+ t_program* program_;
+ std::string name_;
+
+ uint8_t fingerprint_[fingerprint_len];
+};
+
+
+/**
+ * Placeholder struct for returning the key and value of an annotation
+ * during parsing.
+ */
+struct t_annotation {
+ std::string key;
+ std::string val;
+};
+
+#endif
diff --git a/compiler/cpp/src/parse/t_typedef.h b/compiler/cpp/src/parse/t_typedef.h
new file mode 100644
index 0000000..4c77d97
--- /dev/null
+++ b/compiler/cpp/src/parse/t_typedef.h
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_TYPEDEF_H
+#define T_TYPEDEF_H
+
+#include <string>
+#include "t_type.h"
+
+/**
+ * A typedef is a mapping from a symbolic name to another type. In dymanically
+ * typed languages (i.e. php/python) the code generator can actually usually
+ * ignore typedefs and just use the underlying type directly, though in C++
+ * the symbolic naming can be quite useful for code clarity.
+ *
+ */
+class t_typedef : public t_type {
+ public:
+ t_typedef(t_program* program, t_type* type, std::string symbolic) :
+ t_type(program, symbolic),
+ type_(type),
+ symbolic_(symbolic) {}
+
+ ~t_typedef() {}
+
+ t_type* get_type() const {
+ return type_;
+ }
+
+ const std::string& get_symbolic() const {
+ return symbolic_;
+ }
+
+ bool is_typedef() const {
+ return true;
+ }
+
+ virtual std::string get_fingerprint_material() const {
+ return type_->get_fingerprint_material();
+ }
+
+ virtual void generate_fingerprint() {
+ t_type::generate_fingerprint();
+ if (!type_->has_fingerprint()) {
+ type_->generate_fingerprint();
+ }
+ }
+
+ private:
+ t_type* type_;
+ std::string symbolic_;
+};
+
+#endif