Thrift: Optional support for new-style classes.

Reviewed By: mcslee

Test Plan: Thrifted ThriftTest.thrift and looked at the output.

Revert Plan: ok

Other Notes:
Based on a patch from Jon Dugan.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665399 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc
index d682bee..7f3507f 100644
--- a/compiler/cpp/src/generate/t_py_generator.cc
+++ b/compiler/cpp/src/generate/t_py_generator.cc
@@ -149,7 +149,9 @@
  */
 void t_py_generator::generate_enum(t_enum* tenum) {
   f_types_ <<
-    "class " << tenum->get_name() << ":" << endl;
+    "class " << tenum->get_name() <<
+    (gen_newstyle_ ? "(object)" : "") <<
+    ":" << endl;
   indent_up();
 
   vector<t_enum_value*> constants = tenum->get_constants();
@@ -326,9 +328,7 @@
 };
 
 /**
- * Generates a struct definition for a thrift data type. This is nothing in PHP
- * where the objects are all just associative arrays (unless of course we
- * decide to start using objects for them...)
+ * Generates a struct definition for a thrift data type.
  *
  * @param tstruct The struct definition
  */
@@ -346,6 +346,8 @@
     "class " << tstruct->get_name();
   if (is_exception) {
     out << "(Exception)";
+  } else if (gen_newstyle_) {
+    out << "(object)";
   }
   out <<
     ":" << endl;
diff --git a/compiler/cpp/src/generate/t_py_generator.h b/compiler/cpp/src/generate/t_py_generator.h
index c2eed8d..4732561 100644
--- a/compiler/cpp/src/generate/t_py_generator.h
+++ b/compiler/cpp/src/generate/t_py_generator.h
@@ -21,8 +21,10 @@
  */
 class t_py_generator : public t_generator {
  public:
-  t_py_generator(t_program* program) :
-    t_generator(program) {
+  t_py_generator(t_program* program, bool gen_newstyle) :
+    t_generator(program),
+    gen_newstyle_(gen_newstyle) {
+
     out_dir_base_ = "gen-py";
   }
 
@@ -147,6 +149,11 @@
  private:
 
   /**
+   * True iff we should generate new-style classes.
+   */
+  bool gen_newstyle_;
+
+  /**
    * File streams
    */
 
diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc
index 0a47e53..ac5fa04 100644
--- a/compiler/cpp/src/main.cc
+++ b/compiler/cpp/src/main.cc
@@ -133,10 +133,12 @@
  * Flags to control code generation
  */
 bool gen_cpp = false;
+bool gen_dense = false;
 bool gen_java = false;
 bool gen_javabean = false;
 bool gen_rb = false;
 bool gen_py = false;
+bool gen_py_newstyle = false;
 bool gen_xsd = false;
 bool gen_php = false;
 bool gen_phpi = false;
@@ -150,7 +152,6 @@
 bool gen_hs = false;
 bool gen_cocoa = false;
 bool gen_st = false;
-bool gen_dense = false;
 bool gen_recurse = false;
 
 /**
@@ -569,6 +570,7 @@
   fprintf(stderr, "  -phpa       Generate PHP with autoload (with -php)\n");
   fprintf(stderr, "  -phpo       Generate PHP with object oriented subclasses (with -php)\n");
   fprintf(stderr, "  -py         Generate Python output files\n");
+  fprintf(stderr, "  -pyns       Generate Python new-style classes (with -py)\n");
   fprintf(stderr, "  -rb         Generate Ruby output files\n");
   fprintf(stderr, "  -xsd        Generate XSD output files\n");
   fprintf(stderr, "  -perl       Generate Perl output files\n");
@@ -834,7 +836,7 @@
 
     if (gen_py) {
       pverbose("Generating Python\n");
-      t_py_generator* py = new t_py_generator(program);
+      t_py_generator* py = new t_py_generator(program, gen_py_newstyle);
       py->generate_program();
       delete py;
     }
@@ -958,30 +960,25 @@
       } else if (strcmp(arg, "-phpi") == 0) {
         gen_phpi = true;
       } else if (strcmp(arg, "-phps") == 0) {
-        if (!gen_php) {
-          gen_php = true;
-        }
+        gen_php = true;
         gen_phps = true;
       } else if (strcmp(arg, "-phpl") == 0) {
-        if (!gen_php) {
-          gen_php = true;
-        }
+        gen_php = true;
         gen_phps = false;
       } else if (strcmp(arg, "-phpa") == 0) {
-        if (!gen_php) {
-          gen_php = true;
-          gen_phps = false;
-        }
+        gen_php = true;
+        gen_phps = false;
         gen_phpa = true;
       } else if (strcmp(arg, "-phpo") == 0) {
-        if (!gen_php) {
-          gen_php = true;
-        }
+        gen_php = true;
         gen_phpo = true;
       } else if (strcmp(arg, "-rest") == 0) {
         gen_rest = true;
       } else if (strcmp(arg, "-py") == 0) {
         gen_py = true;
+      } else if (strcmp(arg, "-pyns") == 0) {
+        gen_py = true;
+        gen_py_newstyle = true;
       } else if (strcmp(arg, "-rb") == 0) {
         gen_rb = true;
       } else if (strcmp(arg, "-xsd") == 0) {