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/08/20 18:42:04 UTC
svn commit: r987565 - in /incubator/thrift/trunk/compiler/cpp/src:
generate/t_generator.h generate/t_generator_registry.h
generate/t_st_generator.cc parse/t_program.h
Author: bryanduxbury
Date: Fri Aug 20 16:42:04 2010
New Revision: 987565
URL: http://svn.apache.org/viewvc?rev=987565&view=rev
Log:
compiler: make a standard way for language generators to accept sub-namespaces
This patch adds a new method to t_generator that allows the compiler to avoid special cases in checking for sub-namespaces in the Thrift IDL.
Patch: Bruce Lowekamp
Modified:
incubator/thrift/trunk/compiler/cpp/src/generate/t_generator.h
incubator/thrift/trunk/compiler/cpp/src/generate/t_generator_registry.h
incubator/thrift/trunk/compiler/cpp/src/generate/t_st_generator.cc
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=987565&r1=987564&r2=987565&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_generator.h (original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_generator.h Fri Aug 20 16:42:04 2010
@@ -66,6 +66,16 @@ class t_generator {
const std::string& comment_end);
/**
+ * check whether sub-namespace declaraction is used by generator.
+ * e.g. allow
+ * namespace py.twisted bar
+ * to specify namespace to use when -gen py:twisted is specified.
+ * Will be called with subnamespace, i.e. is_valid_namespace("twisted")
+ * will be called for the above example.
+ */
+ static bool is_valid_namespace(const std::string& sub_namespace) { return false; }
+
+ /**
* Escape string to use one in generated sources.
*/
virtual std::string escape_string(const std::string &in) const;
Modified: 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=987565&r1=987564&r2=987565&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_generator_registry.h (original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_generator_registry.h Fri Aug 20 16:42:04 2010
@@ -46,6 +46,8 @@ class t_generator_factory {
const std::string& option_string)
= 0;
+ virtual bool is_valid_namespace(const std::string& sub_namespace) = 0;
+
std::string get_short_name() { return short_name_; }
std::string get_long_name() { return long_name_; }
std::string get_documentation() { return documentation_; }
@@ -71,6 +73,10 @@ class t_generator_factory_impl : public
const std::string& option_string) {
return new generator(program, parsed_options, option_string);
}
+
+ bool is_valid_namespace(const std::string& sub_namespace){
+ return generator::is_valid_namespace(sub_namespace);
+ }
};
class t_generator_registry {
Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_st_generator.cc
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_st_generator.cc?rev=987565&r1=987564&r2=987565&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_st_generator.cc (original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_st_generator.cc Fri Aug 20 16:42:04 2010
@@ -181,6 +181,10 @@ string t_st_generator::class_name() {
return capitalize(program_name_);
}
+static bool is_valid_namespace(const std::string& sub_namespace) {
+ return sub_namespace == "prefix" || sub_namespace == "category";
+}
+
string t_st_generator::prefix(string class_name) {
string prefix = program_->get_namespace("smalltalk.prefix");
string name = capitalize(class_name);
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=987565&r1=987564&r2=987565&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h (original)
+++ incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h Fri Aug 20 16:42:04 2010
@@ -160,16 +160,26 @@ class t_program : public t_doc {
// Language neutral namespace / packaging
void set_namespace(std::string language, std::string name_space) {
+ size_t sub_index = language.find('.');
+ std::string base_language = language.substr(0, sub_index);
+ std::string sub_namespace;
+
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);
+ it=my_copy.find(base_language);
if (it == my_copy.end()) {
- if (language != "smalltalk.prefix" && language != "smalltalk.package") {
- throw "No generator named '" + language + "' could be found!";
- }
+ throw "No generator named '" + base_language + "' could be found!";
}
+
+ if (sub_index != std::string::npos) {
+ std::string sub_namespace = language.substr(sub_index+1);
+ if(! it->second->is_valid_namespace(sub_namespace)) {
+ throw base_language +" generator does not accept '" + sub_namespace + "' as sub-namespace!";
+ }
+ }
+
namespaces_[language] = name_space;
}