From: David Reiss Date: Wed, 27 Feb 2008 01:55:13 +0000 (+0000) Subject: Infrastructure for a language-neutral namespace declaration. X-Git-Tag: 0.2.0~960 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=79eca14125c391c6011f4ffb14bfea898bc6c2f9;p=common%2Fthrift.git Infrastructure for a language-neutral namespace declaration. Altered the once-deprecated "namespace" directive in .thrift files to take two identifiers: the language and the namespace. They are stored in a map inside of the program object. Future changes will convert specific generators to use this map and deprecate the old language-specific tokens. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665512 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h index 7b369d66..d788e2b8 100644 --- a/compiler/cpp/src/parse/t_program.h +++ b/compiler/cpp/src/parse/t_program.h @@ -145,6 +145,19 @@ class t_program : public t_doc { } } + // Language neutral namespace / packaging + void set_namespace(std::string language, std::string name_space) { + namespaces_[language] = name_space; + } + + std::string get_namespace(std::string language) const { + std::map::const_iterator iter = namespaces_.find(language); + if (iter == namespaces_.end()) { + return std::string(); + } + return iter->second; + } + // Language specific namespace / packaging void set_cpp_namespace(std::string cpp_namespace) { @@ -275,6 +288,9 @@ class t_program : public t_doc { std::vector xceptions_; std::vector services_; + // Dynamic namespaces + std::map namespaces_; + // C++ namespace std::string cpp_namespace_; diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy index c104a818..7bd189f6 100644 --- a/compiler/cpp/src/thrifty.yy +++ b/compiler/cpp/src/thrifty.yy @@ -247,12 +247,11 @@ Header: { pdebug("Header -> Include"); } -| tok_namespace tok_identifier +| tok_namespace tok_identifier tok_identifier { - pwarning(1, "'namespace' is deprecated. Use 'cpp_namespace' and/or 'java_package' instead"); + pdebug("Header -> tok_namespace tok_identifier tok_identifier"); if (g_parse_mode == PROGRAM) { - g_program->set_cpp_namespace($2); - g_program->set_java_package($2); + g_program->set_namespace($2, $3); } } | tok_cpp_namespace tok_identifier