This is an automated email from the ASF dual-hosted git repository.

jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new 24ab31f  THRIFT-5067 Invalid generated Cpp code from valid Thrift IDL 
with dots in file names for nested namespaces Client: cpp Patch: zeshuai007 
<[email protected]>
24ab31f is described below

commit 24ab31fc5738532b082c7b0638bfcd2a7a26d7c5
Author: zeshuai007 <[email protected]>
AuthorDate: Sat Mar 14 16:04:21 2020 +0800

    THRIFT-5067 Invalid generated Cpp code from valid Thrift IDL with dots in 
file names for nested namespaces
    Client: cpp
    Patch: zeshuai007 <[email protected]>
    
    This closes #2060
---
 .../cpp/src/thrift/generate/t_cpp_generator.cc     | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/compiler/cpp/src/thrift/generate/t_cpp_generator.cc 
b/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
index 896c43f..372014d 100644
--- a/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
@@ -299,6 +299,13 @@ private:
   std::string get_include_prefix(const t_program& program) const;
 
   /**
+   * Returns the legal program name to use for a file generated by program, if 
the
+   * program name contains dots then replace it with underscores, otherwise 
return the 
+   * original program name.
+   */
+  std::string get_legal_program_name(std::string program_name);
+
+  /**
    * True if we should generate pure enums for Thrift enums, instead of 
wrapper classes.
    */
   bool gen_pure_enums_;
@@ -386,6 +393,8 @@ void t_cpp_generator::init_generator() {
   // Make output directory
   MKDIR(get_out_dir().c_str());
 
+  program_name_ = get_legal_program_name(program_name_);
+
   // Make output file
   string f_types_name = get_out_dir() + program_name_ + "_types.h";
   f_types_.open(f_types_name);
@@ -4550,6 +4559,23 @@ string t_cpp_generator::get_include_prefix(const 
t_program& program) const {
   return "";
 }
 
+string t_cpp_generator::get_legal_program_name(std::string program_name)
+{
+  std::size_t found = 0;
+
+  while(true) {
+    found = program_name.find('.');
+
+    if(found != string::npos) {
+      program_name = program_name.replace(found, 1, "_");
+    } else {
+      break;
+    }
+  }
+
+  return program_name;
+}
+
 THRIFT_REGISTER_GENERATOR(
     cpp,
     "C++",

Reply via email to