Make the Python generator dynamic.
- Modify the Python generator constructor to fit the new generic interface.
- Register the Python genrator with the central registry.
- Deprecate the old way of invoking the Python generator.
- main.cc no longer includes t_py_generator.h.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665612 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 febeafd..461ad13 100644
--- a/compiler/cpp/src/generate/t_py_generator.cc
+++ b/compiler/cpp/src/generate/t_py_generator.cc
@@ -1724,3 +1724,8 @@
throw "INVALID TYPE IN type_to_spec_args: " + ttype->get_name();
}
+
+
+THRIFT_REGISTER_GENERATOR(py, "Python",
+" new_style: Generate new-style classes.\n"
+);
diff --git a/compiler/cpp/src/generate/t_py_generator.h b/compiler/cpp/src/generate/t_py_generator.h
index 4732561..a2d1c47 100644
--- a/compiler/cpp/src/generate/t_py_generator.h
+++ b/compiler/cpp/src/generate/t_py_generator.h
@@ -21,9 +21,16 @@
*/
class t_py_generator : public t_generator {
public:
- t_py_generator(t_program* program, bool gen_newstyle) :
- t_generator(program),
- gen_newstyle_(gen_newstyle) {
+ t_py_generator(
+ t_program* program,
+ const std::map<std::string, std::string>& parsed_options,
+ const std::string& option_string)
+ : t_generator(program)
+ {
+ std::map<std::string, std::string>::const_iterator iter;
+
+ iter = parsed_options.find("new_style");
+ gen_newstyle_ = (iter != parsed_options.end());
out_dir_base_ = "gen-py";
}
diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc
index 0045778..7181d26 100644
--- a/compiler/cpp/src/main.cc
+++ b/compiler/cpp/src/main.cc
@@ -36,7 +36,6 @@
#include "parse/t_program.h"
#include "parse/t_scope.h"
#include "generate/t_php_generator.h"
-#include "generate/t_py_generator.h"
#include "generate/t_rb_generator.h"
#include "generate/t_xsd_generator.h"
#include "generate/t_perl_generator.h"
@@ -602,8 +601,6 @@
fprintf(stderr, " -phpl Generate PHP-lite (with -php)\n");
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");
@@ -870,13 +867,6 @@
delete phpi;
}
- if (gen_py) {
- pverbose("Generating Python\n");
- t_py_generator* py = new t_py_generator(program, gen_py_newstyle);
- py->generate_program();
- delete py;
- }
-
if (gen_rb) {
pverbose("Generating Ruby\n");
t_rb_generator* rb = new t_rb_generator(program);
@@ -1102,6 +1092,10 @@
pwarning(1, "-csharp is deprecated. Use --gen csharp");
generator_strings.push_back("csharp");
}
+ if (gen_py) {
+ pwarning(1, "-py is deprecated. Use --gen py");
+ generator_strings.push_back("py");
+ }
if (gen_cocoa) {
pwarning(1, "-cocoa is deprecated. Use --gen cocoa");
generator_strings.push_back("cocoa");
@@ -1120,7 +1114,7 @@
}
// You gotta generate something!
- if (!gen_php && !gen_phpi && !gen_py && !gen_rb && !gen_xsd && !gen_perl && !gen_erl && generator_strings.empty()) {
+ if (!gen_php && !gen_phpi && !gen_rb && !gen_xsd && !gen_perl && !gen_erl && generator_strings.empty()) {
fprintf(stderr, "!!! No output language(s) specified\n\n");
usage();
}