You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by br...@apache.org on 2010/07/29 18:24:42 UTC

svn commit: r980498 - in /incubator/thrift/trunk/compiler/cpp/src: generate/t_generator.h generate/t_generator_registry.h parse/t_program.h

Author: bryanduxbury
Date: Thu Jul 29 16:24:41 2010
New Revision: 980498

URL: http://svn.apache.org/viewvc?rev=980498&view=rev
Log:
THRIFT-133. 'namespace ruby' should error out, or be an alias to 'namespace rb'

This patch causes 'namespace ruby' (or any unrecognized generator name) to produce an error.

Added:
    incubator/thrift/trunk/compiler/cpp/src/generate/t_generator_registry.h
Modified:
    incubator/thrift/trunk/compiler/cpp/src/generate/t_generator.h
    incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h

Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_generator.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_generator.h?rev=980498&r1=980497&r2=980498&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_generator.h (original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_generator.h Thu Jul 29 16:24:41 2010
@@ -26,6 +26,7 @@
 #include <sstream>
 #include "parse/t_program.h"
 #include "globals.h"
+#include "t_generator_registry.h"
 
 /**
  * Base class for a thrift code generator. This class defines the basic
@@ -272,83 +273,4 @@ class t_generator {
   int tmp_;
 };
 
-
-/**
- * A factory for producing generator classes of a particular language.
- *
- * This class is also responsible for:
- *  - Registering itself with the generator registry.
- *  - Providing documentation for the generators it produces.
- */
-class t_generator_factory {
- public:
-  t_generator_factory(const std::string& short_name,
-                      const std::string& long_name,
-                      const std::string& documentation);
-
-  virtual ~t_generator_factory() {}
-
-  virtual t_generator* get_generator(
-      // The program to generate.
-      t_program* program,
-      // Note: parsed_options will not exist beyond the call to get_generator.
-      const std::map<std::string, std::string>& parsed_options,
-      // Note: option_string might not exist beyond the call to get_generator.
-      const std::string& option_string)
-    = 0;
-
-  std::string get_short_name() { return short_name_; }
-  std::string get_long_name() { return long_name_; }
-  std::string get_documentation() { return documentation_; }
-
- private:
-  std::string short_name_;
-  std::string long_name_;
-  std::string documentation_;
-};
-
-template <typename generator>
-class t_generator_factory_impl : public t_generator_factory {
- public:
-  t_generator_factory_impl(const std::string& short_name,
-                           const std::string& long_name,
-                           const std::string& documentation)
-    : t_generator_factory(short_name, long_name, documentation)
-  {}
-
-  virtual t_generator* get_generator(
-      t_program* program,
-      const std::map<std::string, std::string>& parsed_options,
-      const std::string& option_string) {
-    return new generator(program, parsed_options, option_string);
-  }
-};
-
-class t_generator_registry {
- public:
-  static void register_generator(t_generator_factory* factory);
-
-  static t_generator* get_generator(t_program* program,
-                                    const std::string& options);
-
-  typedef std::map<std::string, t_generator_factory*> gen_map_t;
-  static gen_map_t& get_generator_map();
-
- private:
-  t_generator_registry();
-  t_generator_registry(const t_generator_registry&);
-};
-
-#define THRIFT_REGISTER_GENERATOR(language, long_name, doc)        \
-  class t_##language##_generator_factory_impl                      \
-    : public t_generator_factory_impl<t_##language##_generator>    \
-  {                                                                \
-   public:                                                         \
-    t_##language##_generator_factory_impl()                        \
-      : t_generator_factory_impl<t_##language##_generator>(        \
-          #language, long_name, doc)                               \
-    {}                                                             \
-  };                                                               \
-  static t_##language##_generator_factory_impl _registerer;
-
 #endif

Added: incubator/thrift/trunk/compiler/cpp/src/generate/t_generator_registry.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_generator_registry.h?rev=980498&view=auto
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_generator_registry.h (added)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_generator_registry.h Thu Jul 29 16:24:41 2010
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef T_GENERATOR_REGISTRY_H
+#define T_GENERATOR_REGISTRY_H
+
+class t_generator;
+
+/**
+ * A factory for producing generator classes of a particular language.
+ *
+ * This class is also responsible for:
+ *  - Registering itself with the generator registry.
+ *  - Providing documentation for the generators it produces.
+ */
+class t_generator_factory {
+ public:
+  t_generator_factory(const std::string& short_name,
+                      const std::string& long_name,
+                      const std::string& documentation);
+
+  virtual ~t_generator_factory() {}
+
+  virtual t_generator* get_generator(
+      // The program to generate.
+      t_program* program,
+      // Note: parsed_options will not exist beyond the call to get_generator.
+      const std::map<std::string, std::string>& parsed_options,
+      // Note: option_string might not exist beyond the call to get_generator.
+      const std::string& option_string)
+    = 0;
+
+  std::string get_short_name() { return short_name_; }
+  std::string get_long_name() { return long_name_; }
+  std::string get_documentation() { return documentation_; }
+
+ private:
+  std::string short_name_;
+  std::string long_name_;
+  std::string documentation_;
+};
+
+template <typename generator>
+class t_generator_factory_impl : public t_generator_factory {
+ public:
+  t_generator_factory_impl(const std::string& short_name,
+                           const std::string& long_name,
+                           const std::string& documentation)
+    : t_generator_factory(short_name, long_name, documentation)
+  {}
+
+  virtual t_generator* get_generator(
+      t_program* program,
+      const std::map<std::string, std::string>& parsed_options,
+      const std::string& option_string) {
+    return new generator(program, parsed_options, option_string);
+  }
+};
+
+class t_generator_registry {
+ public:
+  static void register_generator(t_generator_factory* factory);
+
+  static t_generator* get_generator(t_program* program,
+                                    const std::string& options);
+
+  typedef std::map<std::string, t_generator_factory*> gen_map_t;
+  static gen_map_t& get_generator_map();
+
+ private:
+  t_generator_registry();
+  t_generator_registry(const t_generator_registry&);
+};
+
+#define THRIFT_REGISTER_GENERATOR(language, long_name, doc)        \
+  class t_##language##_generator_factory_impl                      \
+    : public t_generator_factory_impl<t_##language##_generator>    \
+  {                                                                \
+   public:                                                         \
+    t_##language##_generator_factory_impl()                        \
+      : t_generator_factory_impl<t_##language##_generator>(        \
+          #language, long_name, doc)                               \
+    {}                                                             \
+  };                                                               \
+  static t_##language##_generator_factory_impl _registerer;
+
+#endif
\ No newline at end of file

Modified: incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h?rev=980498&r1=980497&r2=980498&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h (original)
+++ incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h Thu Jul 29 16:24:41 2010
@@ -38,6 +38,7 @@
 #include "t_list.h"
 #include "t_map.h"
 #include "t_set.h"
+#include "generate/t_generator_registry.h"
 //#include "t_doc.h"
 
 /**
@@ -159,6 +160,14 @@ class t_program : public t_doc {
 
   // Language neutral namespace / packaging
   void set_namespace(std::string language, std::string name_space) {
+    t_generator_registry::gen_map_t my_copy = t_generator_registry::get_generator_map();
+
+    t_generator_registry::gen_map_t::iterator it;
+    it=my_copy.find(language);
+
+    if (it == my_copy.end()) {
+      throw "No generator named '" + language + "' could be found!";
+    }
     namespaces_[language] = name_space;
   }