Baseline commit for thrift, which is pillar v2
Reviewed By: aditya
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664711 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/src/generate/t_generator.h b/compiler/src/generate/t_generator.h
new file mode 100644
index 0000000..71d0318
--- /dev/null
+++ b/compiler/src/generate/t_generator.h
@@ -0,0 +1,63 @@
+#ifndef T_GENERATOR_H
+#define T_GENERATOR_H
+
+#include <string>
+#include <iostream>
+#include "parse/t_program.h"
+
+/**
+ * Base class for a thrift code generator. This class defines the basic
+ * routines for code generation and contains the top level method that
+ * dispatches code generation across various components.
+ *
+ * @author Mark Slee <mcslee@facebook.com>
+ */
+class t_generator {
+ public:
+ t_generator() {}
+ virtual ~t_generator() {}
+
+ /**
+ * Framework generator method that iterates over all the parts of a program
+ * and performs general actions. This is implemented by the base class and
+ * should not be overwritten in the subclasses.
+ */
+ void generate_program (t_program* tprogram);
+
+ 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;
+
+ /** Indentation level modifiers */
+ void indent_up() { ++indent_; }
+ void indent_down() { --indent_; }
+
+ /** Indentation print function */
+ std::string indent() {
+ std::string ind = "";
+ int i;
+ for (i = 0; i < indent_; ++i) {
+ ind += " ";
+ }
+ return ind;
+ }
+
+ /** Indentation wrapper */
+ std::ostream& indent(std::ostream &os) {
+ return os << indent();
+ }
+
+ private:
+ /** Indentation level */
+ int indent_;
+
+};
+
+#endif