From: David Reiss Date: Wed, 27 Feb 2008 01:55:17 +0000 (+0000) Subject: Make the C++ generator use non-hardcoded namespaces. X-Git-Tag: 0.2.0~959 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=9a08dc6184cd0c3fd3d774fcf3f0a4233e28975f;p=common%2Fthrift.git Make the C++ generator use non-hardcoded namespaces. - Make the C++ generator use program->get_namespace("cpp") instead of program->get_cpp_namespace() - Eliminate the explicit "cpp_namespace" in t_program. - Deprecate the cpp_namespace token. - Update example .thrift files and syntax files. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665513 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc index b43a4bc6..0f77b905 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -297,8 +297,8 @@ void t_cpp_generator::init_generator() { } // Open namespace - ns_open_ = namespace_open(program_->get_cpp_namespace()); - ns_close_ = namespace_close(program_->get_cpp_namespace()); + ns_open_ = namespace_open(program_->get_namespace("cpp")); + ns_close_ = namespace_close(program_->get_namespace("cpp")); f_types_ << ns_open_ << endl << @@ -2293,7 +2293,7 @@ void t_cpp_generator::generate_service_skeleton(t_service* tservice) { // Service implementation file includes string f_skeleton_name = get_out_dir()+svcname+"_server.skeleton.cpp"; - string ns = namespace_prefix(tservice->get_program()->get_cpp_namespace()); + string ns = namespace_prefix(tservice->get_program()->get_namespace("cpp")); ofstream f_skeleton; f_skeleton.open(f_skeleton_name.c_str()); @@ -2885,7 +2885,7 @@ string t_cpp_generator::type_name(t_type* ttype, bool in_typedef, bool arg) { if (program != NULL && program != program_) { pname = class_prefix + - namespace_prefix(program->get_cpp_namespace()) + + namespace_prefix(program->get_namespace("cpp")) + ttype->get_name(); } else { pname = class_prefix + ttype->get_name(); @@ -3119,7 +3119,7 @@ string t_cpp_generator::local_reflection_name(const char* prefix, t_type* ttype, if (external && ttype->get_program() != NULL && ttype->get_program() != program_) { - nspace = namespace_prefix(ttype->get_program()->get_cpp_namespace()); + nspace = namespace_prefix(ttype->get_program()->get_namespace("cpp")); } return nspace + "trlo_" + prefix + "_" + prog + "_" + name; diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h index d788e2b8..ef9db496 100644 --- a/compiler/cpp/src/parse/t_program.h +++ b/compiler/cpp/src/parse/t_program.h @@ -160,14 +160,6 @@ class t_program : public t_doc { // Language specific namespace / packaging - void set_cpp_namespace(std::string cpp_namespace) { - cpp_namespace_ = cpp_namespace; - } - - const std::string& get_cpp_namespace() const { - return cpp_namespace_; - } - void add_cpp_include(std::string path) { cpp_includes_.push_back(path); } @@ -291,9 +283,6 @@ class t_program : public t_doc { // Dynamic namespaces std::map namespaces_; - // C++ namespace - std::string cpp_namespace_; - // C++ extra includes std::vector cpp_includes_; diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy index 7bd189f6..bb683585 100644 --- a/compiler/cpp/src/thrifty.yy +++ b/compiler/cpp/src/thrifty.yy @@ -254,11 +254,13 @@ Header: g_program->set_namespace($2, $3); } } +/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */ | tok_cpp_namespace tok_identifier { + pwarning(1, "'cpp_namespace' is deprecated. Use 'namespace cpp' instead"); pdebug("Header -> tok_cpp_namespace tok_identifier"); if (g_parse_mode == PROGRAM) { - g_program->set_cpp_namespace($2); + g_program->set_namespace("cpp", $2); } } | tok_cpp_include tok_literal diff --git a/test/ConstantsDemo.thrift b/test/ConstantsDemo.thrift index 8cc6a1f7..0b9d8396 100644 --- a/test/ConstantsDemo.thrift +++ b/test/ConstantsDemo.thrift @@ -1,4 +1,4 @@ -cpp_namespace yozone +namespace cpp yozone struct thing { 1: i32 hello, diff --git a/test/DebugProtoTest.thrift b/test/DebugProtoTest.thrift index bd13d445..cdbea2a9 100644 --- a/test/DebugProtoTest.thrift +++ b/test/DebugProtoTest.thrift @@ -1,4 +1,4 @@ -cpp_namespace thrift.test +namespace cpp thrift.test struct Doubles { 1: double nan, diff --git a/test/DenseLinkingTest.thrift b/test/DenseLinkingTest.thrift index 9414bd54..787c5010 100644 --- a/test/DenseLinkingTest.thrift +++ b/test/DenseLinkingTest.thrift @@ -14,7 +14,7 @@ If I messed up the naming of the reflection local typespecs, then compiling this should give errors because of doubly defined symbols. */ -cpp_namespace thrift.test +namespace cpp thrift.test struct OneOfEachZZ { 1: bool im_true, diff --git a/test/DocTest.thrift b/test/DocTest.thrift index 5749fdab..d760d9e0 100755 --- a/test/DocTest.thrift +++ b/test/DocTest.thrift @@ -5,7 +5,7 @@ */ java_package thrift.test -cpp_namespace thrift.test +namespace cpp thrift.test // C++ comment /* c style comment */ diff --git a/test/OptionalRequiredTest.thrift b/test/OptionalRequiredTest.thrift index 42e78790..a6358139 100644 --- a/test/OptionalRequiredTest.thrift +++ b/test/OptionalRequiredTest.thrift @@ -1,4 +1,4 @@ -cpp_namespace thrift.test +namespace cpp thrift.test struct OldSchool { 1: i16 im_int; diff --git a/test/StressTest.thrift b/test/StressTest.thrift index 1b2b7c8e..f23aa004 100644 --- a/test/StressTest.thrift +++ b/test/StressTest.thrift @@ -1,4 +1,4 @@ -cpp_namespace test.stress +namespace cpp test.stress service Service { diff --git a/test/ThriftTest.thrift b/test/ThriftTest.thrift index a549fa71..6339f4d6 100644 --- a/test/ThriftTest.thrift +++ b/test/ThriftTest.thrift @@ -1,5 +1,5 @@ java_package thrift.test -cpp_namespace thrift.test +namespace cpp thrift.test ruby_namespace Thrift.Test perl_package ThriftTest csharp_namespace Thrift.Test @@ -119,4 +119,4 @@ struct VersioningTestV2 { 10: map newmap, 11: string newstring, 12: i32 end_in_both -} \ No newline at end of file +} diff --git a/thrift.el b/thrift.el index bb0968ae..c094a145 100644 --- a/thrift.el +++ b/thrift.el @@ -10,7 +10,7 @@ (defconst thrift-font-lock-keywords (list '("#.*$" . font-lock-comment-face) ;; perl style comments - '("\\<\\(include\\|struct\\|exception\\|typedef\\|cpp_namespace\\|java_package\\|cocoa_prefix\\|csharp_namespace\\|php_namespace\\|ruby_namespace\\|py_module\\|perl_package\\|smalltalk_category\\|smalltalk_prefix\\|const\\|enum\\|service\\|extends\\|void\\|async\\|throws\\|optional\\|required\\)\\>" . font-lock-keyword-face) ;; keywords + '("\\<\\(include\\|struct\\|exception\\|typedef\\|java_package\\|cocoa_prefix\\|csharp_namespace\\|php_namespace\\|ruby_namespace\\|py_module\\|perl_package\\|smalltalk_category\\|smalltalk_prefix\\|const\\|enum\\|service\\|extends\\|void\\|async\\|throws\\|optional\\|required\\)\\>" . font-lock-keyword-face) ;; keywords '("\\<\\(bool\\|byte\\|i16\\|i32\\|i64\\|double\\|string\\|binary\\|map\\|list\\|set\\)\\>" . font-lock-type-face) ;; built-in types '("\\<\\([0-9]+\\)\\>" . font-lock-variable-name-face) ;; ordinals '("\\<\\(\\w+\\)\\s-*(" (1 font-lock-function-name-face)) ;; functions diff --git a/thrift.vim b/thrift.vim index bb849a30..bf6414b7 100644 --- a/thrift.vim +++ b/thrift.vim @@ -30,7 +30,7 @@ syn region thriftStringDouble matchgroup=None start=+"+ end=+"+ syn match thriftNumber "-\=\<\d\+\>" contained " Keywords -syn keyword thriftKeyword namespace cpp_namespace java_package cocoa_prefix +syn keyword thriftKeyword namespace java_package cocoa_prefix syn keyword thriftKeyword csharp_namespace smalltalk_category smalltalk_prefix syn keyword thriftKeyword php_namespace ruby_namespace py_module perl_package syn keyword thriftKeyword xsd_all xsd_optional xsd_nillable xsd_namespace xsd_attrs diff --git a/tutorial/shared.thrift b/tutorial/shared.thrift index 1ecfb0a5..0d50bfa0 100755 --- a/tutorial/shared.thrift +++ b/tutorial/shared.thrift @@ -5,7 +5,7 @@ * these definitions. */ -cpp_namespace shared +namespace cpp shared java_package shared perl_package shared diff --git a/tutorial/tutorial.thrift b/tutorial/tutorial.thrift index 323c96ab..575afcbf 100755 --- a/tutorial/tutorial.thrift +++ b/tutorial/tutorial.thrift @@ -44,7 +44,7 @@ include "shared.thrift" * Thrift files can namespace, package, or prefix their output in various * target languages. */ -cpp_namespace tutorial +namespace cpp tutorial java_package tutorial php_namespace tutorial perl_package tutorial