Rev 2 of Thrift, the Pillar successor

Summary: End-to-end communications and serialization in C++ is working

Reviewed By: aditya

Test Plan: See the new top-level test/ folder. It vaguely resembles a unit test, though it could be more automated.

Revert Plan: Revertible

Notes: Still a LOT of optimization work to be done on the generated C++ code, which should be using dynamic memory in a number of places. Next major task is writing the PHP/Java/Python generators.




git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664712 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/src/generate/t_generator.h b/compiler/src/generate/t_generator.h
index 71d0318..be0b83e 100644
--- a/compiler/src/generate/t_generator.h
+++ b/compiler/src/generate/t_generator.h
@@ -3,6 +3,7 @@
 
 #include <string>
 #include <iostream>
+#include <sstream>
 #include "parse/t_program.h"
 
 /**
@@ -14,7 +15,7 @@
  */
 class t_generator {
  public:
-  t_generator() {}
+  t_generator() { tmp_ = 0; }
   virtual ~t_generator() {}
 
   /**
@@ -26,16 +27,37 @@
 
  protected:
   /** Optional methods that may be imlemented by subclasses. */
+
   virtual void init_generator    (t_program*  tprogram) {}
   virtual void close_generator   () {}
 
   /** Pure virtual methods implemented by the generator subclasses. */
+
   virtual void generate_typedef  (t_typedef*  ttypedef) = 0;
   virtual void generate_enum     (t_enum*     tenum)    = 0;
   virtual void generate_struct   (t_struct*   tstruct)  = 0;
   virtual void generate_service  (t_service*  tservice) = 0;
 
+  /** Method to get the program name, may be overridden */
+
+  virtual std::string get_program_name(t_program* tprogram) {
+    return tprogram->get_name();
+  }
+
+  /** Method to get the service name, may be overridden */
+  virtual std::string get_service_name(t_service* tservice) {
+    return tservice->get_name();
+  }
+
+  /** Creates a unique temporary variable name. */
+  std::string tmp(std::string name) {
+    std::ostringstream out;
+    out << name << tmp_++;
+    return out.str();
+  }
+
   /** Indentation level modifiers */
+
   void indent_up()   { ++indent_; }
   void indent_down() { --indent_; }
 
@@ -49,15 +71,24 @@
     return ind;
   }
 
-  /** Indentation wrapper */
+  /** Indentation utility wrapper */
   std::ostream& indent(std::ostream &os) {
     return os << indent();
   }
 
+ protected:
+  /** Quick accessor for formatted program name */
+  std::string program_name_;
+
+  /** Quick accessor for formatted service name */
+  std::string service_name_;
+
  private:
   /** Indentation level */
   int indent_;
 
+  /** Temporary variable counter */
+  int tmp_;
 };
 
 #endif