Thrift compiler code cleanup, comments, php inline generation, etc


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664822 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
index 0e97207..837caa5 100644
--- a/compiler/cpp/src/parse/t_base_type.h
+++ b/compiler/cpp/src/parse/t_base_type.h
@@ -4,7 +4,8 @@
 #include "t_type.h"
 
 /**
- * A thrift base type, which must be one of the defined enumerated types.
+ * A thrift base type, which must be one of the defined enumerated types inside
+ * this definition.
  *
  * @author Mark Slee <mcslee@facebook.com>
  */
@@ -25,11 +26,20 @@
   };
 
   t_base_type(std::string name, t_base base) :
-    t_type(name), base_(base) {}
+    t_type(name),
+    base_(base) {}
     
-  t_base get_base() const { return base_; }
-  bool is_void() const { return base_ == TYPE_VOID; }
-  bool is_base_type() const { return true; }
+  t_base get_base() const {
+    return base_;
+  }
+
+  bool is_void() const {
+    return base_ == TYPE_VOID;
+  }
+
+  bool is_base_type() const {
+    return true;
+  }
     
  private:
   t_base base_;
diff --git a/compiler/cpp/src/parse/t_constant.h b/compiler/cpp/src/parse/t_constant.h
index 1f3c868..f502f75 100644
--- a/compiler/cpp/src/parse/t_constant.h
+++ b/compiler/cpp/src/parse/t_constant.h
@@ -3,19 +3,38 @@
 
 #include <string>
 
+/**
+ * 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.
+ *
+ * @author Mark Slee <mcslee@facebook.com>
+ */
 class t_constant {
  public:
   t_constant(std::string name) :
-    name_(name), has_value_(false), value_(0) {}
+    name_(name),
+    has_value_(false),
+    value_(0) {}
 
   t_constant(std::string name, int value) :
-    name_(name), has_value_(true), value_(value) {}
+    name_(name),
+    has_value_(true),
+    value_(value) {}
 
   ~t_constant() {}
 
-  const std::string& get_name() { return name_; }
-  bool has_value() { return has_value_; }
-  int get_value() { return value_; }
+  const std::string& get_name() {
+    return name_;
+  }
+  
+  bool has_value() {
+    return has_value_;
+  }
+  
+  int get_value() {
+    return value_;
+  }
   
  private:
   std::string name_;
diff --git a/compiler/cpp/src/parse/t_enum.h b/compiler/cpp/src/parse/t_enum.h
index f089150..4b6fe36 100644
--- a/compiler/cpp/src/parse/t_enum.h
+++ b/compiler/cpp/src/parse/t_enum.h
@@ -4,16 +4,30 @@
 #include "t_constant.h"
 #include <vector>
 
+/**
+ * An enumerated type. A list of t_constant objects with a name for the type.
+ *
+ * @author Mark Slee <mcslee@facebook.com>
+ */
 class t_enum : public t_type {
  public:
   t_enum() {}
-  ~t_enum() {}
 
-  void set_name(std::string name) { name_ = name; }
-  void append(t_constant* constant) { constants_.push_back(constant); }
+  void set_name(std::string name) {
+    name_ = name;
+  }
+  
+  void append(t_constant* constant) {
+    constants_.push_back(constant);
+  }
 
-  const std::vector<t_constant*>& get_constants() { return constants_; }
-  bool is_enum() const { return true; }
+  const std::vector<t_constant*>& get_constants() {
+    return constants_;
+  }
+
+  bool is_enum() const {
+    return true;
+  }
 
  private:
   std::vector<t_constant*> constants_;
diff --git a/compiler/cpp/src/parse/t_field.h b/compiler/cpp/src/parse/t_field.h
index 7f4d0e9..93e14d8 100644
--- a/compiler/cpp/src/parse/t_field.h
+++ b/compiler/cpp/src/parse/t_field.h
@@ -4,24 +4,36 @@
 #include <string>
 
 /**
- * Class to represent a field in a thrift structure or in a set of arguments
- * to a thrift function.
+ * Class to represent a field in a thrift structure. A field has a data type,
+ * a symbolic name, and a numeric identifier.
  *
  * @author Mark Slee <mcslee@facebook.com>
  */
 class t_field {
  public:
   t_field(t_type* type, std::string name) :
-    type_(type), name_(name), key_(0) {}
+    type_(type),
+    name_(name),
+    key_(0) {}
 
   t_field(t_type* type, std::string name, int32_t key) :
-    type_(type), name_(name), key_(key) {}
+    type_(type),
+    name_(name),
+    key_(key) {}
 
   ~t_field() {}
 
-  t_type* get_type() const { return type_; }
-  const std::string& get_name() const { return name_; }
-  int32_t get_key() const { return key_; }
+  t_type* get_type() const {
+    return type_;
+  }
+
+  const std::string& get_name() const {
+    return name_;
+  }
+
+  int32_t get_key() const {
+    return key_;
+  }
 
  private:
   t_type* type_;
diff --git a/compiler/cpp/src/parse/t_function.h b/compiler/cpp/src/parse/t_function.h
index 58667d8..3d07171 100644
--- a/compiler/cpp/src/parse/t_function.h
+++ b/compiler/cpp/src/parse/t_function.h
@@ -6,8 +6,9 @@
 #include "t_struct.h"
 
 /**
- * Representation of a function. Key parst are return type, function name,
- * optional modifiers, and an argument list.
+ * Representation of a function. Key parts are return type, function name,
+ * optional modifiers, and an argument list, which is implemented as a thrift
+ * struct.
  *
  * @author Mark Slee <mcslee@facebook.com>
  */
@@ -24,7 +25,6 @@
     xceptions_ = new t_struct;
   }
 
-
   t_function(t_type* returntype,
              std::string name,
              t_struct* arglist,
@@ -38,11 +38,25 @@
 
   ~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_async()       const { return async_; }
+  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_async() const {
+    return async_;
+  }
 
  private:
   t_type* returntype_;
diff --git a/compiler/cpp/src/parse/t_list.h b/compiler/cpp/src/parse/t_list.h
index 65874cc..5f9b5aa 100644
--- a/compiler/cpp/src/parse/t_list.h
+++ b/compiler/cpp/src/parse/t_list.h
@@ -3,13 +3,23 @@
 
 #include "t_type.h"
 
+/**
+ * A list is a lightweight container type that just wraps another data type.
+ *
+ * @author Mark Slee <mcslee@facebook.com>
+ */
 class t_list : public t_type {
  public:
-  t_list(t_type* elem_type) : elem_type_(elem_type) {}
-  ~t_list() {}
+  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; }
+  t_type* get_elem_type() const {
+    return elem_type_;
+  }
+  
+  bool is_list() const {
+    return true;
+  }
 
  private:
   t_type* elem_type_;
diff --git a/compiler/cpp/src/parse/t_map.h b/compiler/cpp/src/parse/t_map.h
index 1f61843..ff1c569 100644
--- a/compiler/cpp/src/parse/t_map.h
+++ b/compiler/cpp/src/parse/t_map.h
@@ -1,15 +1,29 @@
 #ifndef T_MAP_H
 #define T_MAP_H
 
+/**
+ * A map is a lightweight container type that just wraps another two data
+ * types.
+ *
+ * @author Mark Slee <mcslee@facebook.com>
+ */
 class t_map : public t_type {
  public:
   t_map(t_type* key_type, t_type* val_type) :
-    key_type_(key_type), val_type_(val_type) {}
-  ~t_map() {}
+    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; }
+  t_type* get_key_type() const {
+    return key_type_;
+  }
+
+  t_type* get_val_type() const {
+    return val_type_;
+  }
+
+  bool is_map() const {
+    return true;
+  }
 
  private:
   t_type* key_type_;
diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h
index 74b9360..5e58654 100644
--- a/compiler/cpp/src/parse/t_program.h
+++ b/compiler/cpp/src/parse/t_program.h
@@ -24,12 +24,15 @@
  *   Exceptions
  *   Services
  *
+ * The program module also contains the definitions of the base types.
+ *
  * @author Mark Slee <mcslee@facebook.com>
  */
 class t_program {
  public:
   t_program(std::string name) :
-    name_(name), namespace_() {
+    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_bool   = new t_base_type("bool",   t_base_type::TYPE_BOOL);
@@ -51,10 +54,14 @@
   }
 
   // Name accessor
-  const std::string& get_name() const { return name_; }
+  const std::string& get_name() const {
+    return name_;
+  }
 
   // Namespace
-  const std::string& get_namespace() const { return namespace_; }
+  const std::string& get_namespace() const {
+    return namespace_;
+  }
 
   // Accessors for program elements
   const std::vector<t_typedef*>& get_typedefs()  const { return typedefs_;  }
@@ -79,6 +86,7 @@
   }
 
   // New program element addition
+
   void set_namespace(std::string name) {
     namespace_ = name;
   }
@@ -87,23 +95,28 @@
     typedefs_.push_back(td);
     add_custom_type(td->get_symbolic(), td);
   }
+
   void add_enum(t_enum* te) {
     enums_.push_back(te);
     add_custom_type(te->get_name(), te);
   }
+
   void add_struct(t_struct* ts) {
     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;
diff --git a/compiler/cpp/src/parse/t_service.h b/compiler/cpp/src/parse/t_service.h
index 92e59b2..6bb5e5d 100644
--- a/compiler/cpp/src/parse/t_service.h
+++ b/compiler/cpp/src/parse/t_service.h
@@ -4,16 +4,30 @@
 #include "t_function.h"
 #include <vector>
 
+/**
+ * A service consists of a set of functions.
+ *
+ * @author Mark Slee <mcslee@facebook.com>
+ */
 class t_service {
  public:
   t_service() {}
-  ~t_service() {}
 
-  void set_name(std::string name) { name_ = name; }
-  void add_function(t_function* func) { functions_.push_back(func); }
+  void set_name(std::string name) {
+    name_ = name;
+  }
 
-  const std::string& get_name() const { return name_; }
-  const std::vector<t_function*>& get_functions() const { return functions_; }
+  void add_function(t_function* func) {
+    functions_.push_back(func);
+  }
+
+  const std::string& get_name() const {
+    return name_;
+  }
+
+  const std::vector<t_function*>& get_functions() const {
+    return functions_;
+  }
 
  private:
   std::string name_;
diff --git a/compiler/cpp/src/parse/t_set.h b/compiler/cpp/src/parse/t_set.h
index 3d34ace..e39e420 100644
--- a/compiler/cpp/src/parse/t_set.h
+++ b/compiler/cpp/src/parse/t_set.h
@@ -3,13 +3,23 @@
 
 #include "t_type.h"
 
+/**
+ * A set is a lightweight container type that just wraps another data type.
+ *
+ * @author Mark Slee <mcslee@facebook.com>
+ */
 class t_set : public t_type {
  public:
-  t_set(t_type* elem_type) : elem_type_(elem_type) {}
-  ~t_set() {}
+  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; }
+  t_type* get_elem_type() const {
+    return elem_type_;
+  }
+
+  bool is_set() const {
+    return true;
+  }
 
  private:
   t_type* elem_type_;
diff --git a/compiler/cpp/src/parse/t_struct.h b/compiler/cpp/src/parse/t_struct.h
index a365cd4..8768c5f 100644
--- a/compiler/cpp/src/parse/t_struct.h
+++ b/compiler/cpp/src/parse/t_struct.h
@@ -7,24 +7,29 @@
 #include "t_type.h"
 #include "t_field.h"
 
+/**
+ * A struct is a container for a set of member fields that has a name. Structs
+ * are also used to implement exception types.
+ *
+ * @author Mark Slee <mcslee@facebook.com>
+ */
 class t_struct : public t_type {
  public:
-  t_struct() : is_xception_(false) {}
-  t_struct(const std::string& name) : t_type(name), is_xception_(false) {}
+  t_struct() :
+    is_xception_(false) {}
 
-  ~t_struct() {}
+  t_struct(const std::string& name) :
+    t_type(name),
+    is_xception_(false) {}
 
-  /** Set the struct name */
   void set_name(const std::string& name) {
     name_ = name;
   }
 
-  /** Mark as an exception */
   void set_xception(bool is_xception) {
     is_xception_ = is_xception;
   }
 
-  /** Add a new field to the list */
   void append(t_field* elem) {
     members_.push_back(elem);
   }
diff --git a/compiler/cpp/src/parse/t_type.h b/compiler/cpp/src/parse/t_type.h
index 6328961..27b85a5 100644
--- a/compiler/cpp/src/parse/t_type.h
+++ b/compiler/cpp/src/parse/t_type.h
@@ -4,7 +4,11 @@
 #include <string>
 
 /**
- * Generic representation of a thrift type.
+ * 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.
  *
  * @author Mark Slee <mcslee@facebook.com>
  */
@@ -24,7 +28,9 @@
   virtual bool is_set()       const { return false; }
   virtual bool is_map()       const { return false; }
 
-  bool is_container() const { return is_map() || is_set() || is_list(); }
+  bool is_container() const {
+    return is_map() || is_set() || is_list();
+  }
 
  protected:
   t_type() {}
diff --git a/compiler/cpp/src/parse/t_typedef.h b/compiler/cpp/src/parse/t_typedef.h
index 97284be..8973201 100644
--- a/compiler/cpp/src/parse/t_typedef.h
+++ b/compiler/cpp/src/parse/t_typedef.h
@@ -5,26 +5,36 @@
 #include "t_type.h"
 
 /**
- * A typedef is a mapping from a symbolic name to another type.
+ * 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.
  *
  * @author Mark Slee <mcslee@facebook.com>
  */
 class t_typedef : public t_type {
  public:
   t_typedef(t_type* type, std::string symbolic) :
-    t_type(symbolic), type_(type), symbolic_(symbolic) {}
+    t_type(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; }
+  t_type* get_type() const {
+    return type_;
+  }
+
+  const std::string& get_symbolic() const {
+    return symbolic_;
+  }
+
+  bool is_typedef() const {
+    return true;
+  }
 
  private:
-  /** Type that this definition inherits from */
   t_type* type_;
-
-  /** Symbolic name for this type */
   std::string symbolic_;
 };