Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit b353fcdbb677473d0806587d7ac4792f28f22707 1 parent 0fb1cd1
dreiss authored
10 compiler/cpp/src/generate/t_cpp_generator.cc
@@ -297,8 +297,8 @@ void t_cpp_generator::init_generator() {
297 297 }
298 298
299 299 // Open namespace
300   - ns_open_ = namespace_open(program_->get_cpp_namespace());
301   - ns_close_ = namespace_close(program_->get_cpp_namespace());
  300 + ns_open_ = namespace_open(program_->get_namespace("cpp"));
  301 + ns_close_ = namespace_close(program_->get_namespace("cpp"));
302 302
303 303 f_types_ <<
304 304 ns_open_ << endl <<
@@ -2293,7 +2293,7 @@ void t_cpp_generator::generate_service_skeleton(t_service* tservice) {
2293 2293 // Service implementation file includes
2294 2294 string f_skeleton_name = get_out_dir()+svcname+"_server.skeleton.cpp";
2295 2295
2296   - string ns = namespace_prefix(tservice->get_program()->get_cpp_namespace());
  2296 + string ns = namespace_prefix(tservice->get_program()->get_namespace("cpp"));
2297 2297
2298 2298 ofstream f_skeleton;
2299 2299 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) {
2885 2885 if (program != NULL && program != program_) {
2886 2886 pname =
2887 2887 class_prefix +
2888   - namespace_prefix(program->get_cpp_namespace()) +
  2888 + namespace_prefix(program->get_namespace("cpp")) +
2889 2889 ttype->get_name();
2890 2890 } else {
2891 2891 pname = class_prefix + ttype->get_name();
@@ -3119,7 +3119,7 @@ string t_cpp_generator::local_reflection_name(const char* prefix, t_type* ttype,
3119 3119 if (external &&
3120 3120 ttype->get_program() != NULL &&
3121 3121 ttype->get_program() != program_) {
3122   - nspace = namespace_prefix(ttype->get_program()->get_cpp_namespace());
  3122 + nspace = namespace_prefix(ttype->get_program()->get_namespace("cpp"));
3123 3123 }
3124 3124
3125 3125 return nspace + "trlo_" + prefix + "_" + prog + "_" + name;
11 compiler/cpp/src/parse/t_program.h
@@ -160,14 +160,6 @@ class t_program : public t_doc {
160 160
161 161 // Language specific namespace / packaging
162 162
163   - void set_cpp_namespace(std::string cpp_namespace) {
164   - cpp_namespace_ = cpp_namespace;
165   - }
166   -
167   - const std::string& get_cpp_namespace() const {
168   - return cpp_namespace_;
169   - }
170   -
171 163 void add_cpp_include(std::string path) {
172 164 cpp_includes_.push_back(path);
173 165 }
@@ -291,9 +283,6 @@ class t_program : public t_doc {
291 283 // Dynamic namespaces
292 284 std::map<std::string, std::string> namespaces_;
293 285
294   - // C++ namespace
295   - std::string cpp_namespace_;
296   -
297 286 // C++ extra includes
298 287 std::vector<std::string> cpp_includes_;
299 288
4 compiler/cpp/src/thrifty.yy
@@ -254,11 +254,13 @@ Header:
254 254 g_program->set_namespace($2, $3);
255 255 }
256 256 }
  257 +/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
257 258 | tok_cpp_namespace tok_identifier
258 259 {
  260 + pwarning(1, "'cpp_namespace' is deprecated. Use 'namespace cpp' instead");
259 261 pdebug("Header -> tok_cpp_namespace tok_identifier");
260 262 if (g_parse_mode == PROGRAM) {
261   - g_program->set_cpp_namespace($2);
  263 + g_program->set_namespace("cpp", $2);
262 264 }
263 265 }
264 266 | tok_cpp_include tok_literal
2  test/ConstantsDemo.thrift
... ... @@ -1,4 +1,4 @@
1   -cpp_namespace yozone
  1 +namespace cpp yozone
2 2
3 3 struct thing {
4 4 1: i32 hello,
2  test/DebugProtoTest.thrift
... ... @@ -1,4 +1,4 @@
1   -cpp_namespace thrift.test
  1 +namespace cpp thrift.test
2 2
3 3 struct Doubles {
4 4 1: double nan,
2  test/DenseLinkingTest.thrift
@@ -14,7 +14,7 @@ If I messed up the naming of the reflection local typespecs,
14 14 then compiling this should give errors because of doubly defined symbols.
15 15 */
16 16
17   -cpp_namespace thrift.test
  17 +namespace cpp thrift.test
18 18
19 19 struct OneOfEachZZ {
20 20 1: bool im_true,
2  test/DocTest.thrift
@@ -5,7 +5,7 @@
5 5 */
6 6
7 7 java_package thrift.test
8   -cpp_namespace thrift.test
  8 +namespace cpp thrift.test
9 9
10 10 // C++ comment
11 11 /* c style comment */
2  test/OptionalRequiredTest.thrift
... ... @@ -1,4 +1,4 @@
1   -cpp_namespace thrift.test
  1 +namespace cpp thrift.test
2 2
3 3 struct OldSchool {
4 4 1: i16 im_int;
2  test/StressTest.thrift
... ... @@ -1,4 +1,4 @@
1   -cpp_namespace test.stress
  1 +namespace cpp test.stress
2 2
3 3 service Service {
4 4
4 test/ThriftTest.thrift
... ... @@ -1,5 +1,5 @@
1 1 java_package thrift.test
2   -cpp_namespace thrift.test
  2 +namespace cpp thrift.test
3 3 ruby_namespace Thrift.Test
4 4 perl_package ThriftTest
5 5 csharp_namespace Thrift.Test
@@ -119,4 +119,4 @@ struct VersioningTestV2 {
119 119 10: map<i32, i32> newmap,
120 120 11: string newstring,
121 121 12: i32 end_in_both
122   -}
  122 +}
2  thrift.el
@@ -10,7 +10,7 @@
10 10 (defconst thrift-font-lock-keywords
11 11 (list
12 12 '("#.*$" . font-lock-comment-face) ;; perl style comments
13   - '("\\<\\(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
  13 + '("\\<\\(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
14 14 '("\\<\\(bool\\|byte\\|i16\\|i32\\|i64\\|double\\|string\\|binary\\|map\\|list\\|set\\)\\>" . font-lock-type-face) ;; built-in types
15 15 '("\\<\\([0-9]+\\)\\>" . font-lock-variable-name-face) ;; ordinals
16 16 '("\\<\\(\\w+\\)\\s-*(" (1 font-lock-function-name-face)) ;; functions
2  thrift.vim
@@ -30,7 +30,7 @@ syn region thriftStringDouble matchgroup=None start=+"+ end=+"+
30 30 syn match thriftNumber "-\=\<\d\+\>" contained
31 31
32 32 " Keywords
33   -syn keyword thriftKeyword namespace cpp_namespace java_package cocoa_prefix
  33 +syn keyword thriftKeyword namespace java_package cocoa_prefix
34 34 syn keyword thriftKeyword csharp_namespace smalltalk_category smalltalk_prefix
35 35 syn keyword thriftKeyword php_namespace ruby_namespace py_module perl_package
36 36 syn keyword thriftKeyword xsd_all xsd_optional xsd_nillable xsd_namespace xsd_attrs
2  tutorial/shared.thrift
@@ -5,7 +5,7 @@
5 5 * these definitions.
6 6 */
7 7
8   -cpp_namespace shared
  8 +namespace cpp shared
9 9 java_package shared
10 10 perl_package shared
11 11
2  tutorial/tutorial.thrift
@@ -44,7 +44,7 @@ include "shared.thrift"
44 44 * Thrift files can namespace, package, or prefix their output in various
45 45 * target languages.
46 46 */
47   -cpp_namespace tutorial
  47 +namespace cpp tutorial
48 48 java_package tutorial
49 49 php_namespace tutorial
50 50 perl_package tutorial

0 comments on commit b353fcd

Please sign in to comment.
Something went wrong with that request. Please try again.