From: Roger Meier Date: Sun, 15 Jun 2014 19:48:59 +0000 (+0200) Subject: THRIFT-2520 cpp:cob_style generates incorrect .tcc file X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=63fcb7e756a88adca994111e1d9bc0c3c5186c36;p=common%2Fthrift.git THRIFT-2520 cpp:cob_style generates incorrect .tcc file This closes #118 commit 22d266eefaf16f21ffd0ad193a6a54403de65197 Author: N.Sukegawa Date: 2014-05-07T19:36:43Z --- diff --git a/.gitignore b/.gitignore index 9a08cbe7..19386dad 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,8 @@ Makefile Makefile.in autom4te.cache node_modules +compile +test-driver .sonar .DS_Store @@ -84,6 +86,7 @@ node_modules /lib/cpp/test/UnitTests /lib/cpp/test/ZlibTest /lib/cpp/test/concurrency_test +/lib/cpp/test/link_test /lib/cpp/test/processor_test /lib/cpp/test/tests.xml /lib/cpp/concurrency_test diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc index 771af460..c171a53f 100755 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -119,7 +119,7 @@ class t_cpp_generator : public t_oop_generator { bool read=true, bool write=true, bool swap=false); - void generate_struct_definition (std::ofstream& out, t_struct* tstruct, bool setters=true); + void generate_struct_definition (std::ofstream& out, std::ofstream& force_cpp_out, t_struct* tstruct, bool setters=true); void generate_copy_constructor (std::ofstream& out, t_struct* tstruct); void generate_assignment_operator (std::ofstream& out, t_struct* tstruct); void generate_struct_fingerprint (std::ofstream& out, t_struct* tstruct, bool is_definition); @@ -805,7 +805,7 @@ void t_cpp_generator::generate_forward_declaration(t_struct* tstruct) { void t_cpp_generator::generate_cpp_struct(t_struct* tstruct, bool is_exception) { generate_struct_declaration(f_types_, tstruct, is_exception, false, true, true, true); - generate_struct_definition(f_types_impl_, tstruct); + generate_struct_definition(f_types_impl_, f_types_impl_, tstruct); generate_struct_fingerprint(f_types_impl_, tstruct, true); generate_local_reflection(f_types_, tstruct, false); generate_local_reflection(f_types_impl_, tstruct, true); @@ -1138,6 +1138,7 @@ void t_cpp_generator::generate_struct_declaration(ofstream& out, } void t_cpp_generator::generate_struct_definition(ofstream& out, + ofstream& force_cpp_out, t_struct* tstruct, bool setters) { // Get members @@ -1147,13 +1148,13 @@ void t_cpp_generator::generate_struct_definition(ofstream& out, // Destructor if (tstruct->annotations_.find("final") == tstruct->annotations_.end()) { - out << + force_cpp_out << endl << indent() << tstruct->get_name() << "::~" << tstruct->get_name() << "() throw() {" << endl; indent_up(); indent_down(); - out << indent() << "}" << endl << endl; + force_cpp_out << indent() << "}" << endl << endl; } // Create a setter function for each field @@ -1886,12 +1887,12 @@ void t_cpp_generator::generate_service_helpers(t_service* tservice) { // TODO(dreiss): Why is this stuff not in generate_function_helpers? ts->set_name(tservice->get_name() + "_" + (*f_iter)->get_name() + "_args"); generate_struct_declaration(f_header_, ts, false); - generate_struct_definition(out, ts, false); + generate_struct_definition(out, f_service_, ts, false); generate_struct_reader(out, ts); generate_struct_writer(out, ts); ts->set_name(tservice->get_name() + "_" + (*f_iter)->get_name() + "_pargs"); generate_struct_declaration(f_header_, ts, false, true, false, true); - generate_struct_definition(out, ts, false); + generate_struct_definition(out, f_service_, ts, false); generate_struct_writer(out, ts, true); ts->set_name(name_orig); @@ -3343,13 +3344,13 @@ void t_cpp_generator::generate_function_helpers(t_service* tservice, } generate_struct_declaration(f_header_, &result, false); - generate_struct_definition(out, &result, false); + generate_struct_definition(out, f_service_, &result, false); generate_struct_reader(out, &result); generate_struct_result_writer(out, &result); result.set_name(tservice->get_name() + "_" + tfunction->get_name() + "_presult"); generate_struct_declaration(f_header_, &result, false, true, true, gen_cob_style_); - generate_struct_definition(out, &result, false); + generate_struct_definition(out, f_service_, &result, false); generate_struct_reader(out, &result, true); if (gen_cob_style_) { generate_struct_writer(out, &result, true); diff --git a/lib/cpp/test/Makefile.am b/lib/cpp/test/Makefile.am index 7850a168..3c97452f 100755 --- a/lib/cpp/test/Makefile.am +++ b/lib/cpp/test/Makefile.am @@ -63,7 +63,8 @@ check_PROGRAMS = \ TransportTest \ ZlibTest \ TFileTransportTest \ - UnitTests + UnitTests \ + link_test # disable these test ... too strong # processor_test # concurrency_test @@ -195,6 +196,11 @@ concurrency_test_SOURCES = \ concurrency_test_LDADD = \ $(top_builddir)/lib/cpp/libthrift.la +link_test_SOURCES = \ + link/LinkTest.cpp \ + link/TemplatedService1.cpp \ + link/TemplatedService2.cpp + processor_test_SOURCES = \ processor/ProcessorTest.cpp \ processor/EventLog.cpp \ diff --git a/lib/cpp/test/link/LinkTest.cpp b/lib/cpp/test/link/LinkTest.cpp new file mode 100644 index 00000000..18e14d10 --- /dev/null +++ b/lib/cpp/test/link/LinkTest.cpp @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +int main(int, char**) { + return 0; +} diff --git a/lib/cpp/test/link/TemplatedService1.cpp b/lib/cpp/test/link/TemplatedService1.cpp new file mode 100644 index 00000000..da1790be --- /dev/null +++ b/lib/cpp/test/link/TemplatedService1.cpp @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * This file is a part of a link test that makes sure generated + * templated service headers can be included from multiple + * implementation files. + */ + +#include "gen-cpp/ParentService.h" diff --git a/lib/cpp/test/link/TemplatedService2.cpp b/lib/cpp/test/link/TemplatedService2.cpp new file mode 100644 index 00000000..da1790be --- /dev/null +++ b/lib/cpp/test/link/TemplatedService2.cpp @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * This file is a part of a link test that makes sure generated + * templated service headers can be included from multiple + * implementation files. + */ + +#include "gen-cpp/ParentService.h" diff --git a/test/cpp/Makefile.am b/test/cpp/Makefile.am index 347b1756..66f8c1e6 100755 --- a/test/cpp/Makefile.am +++ b/test/cpp/Makefile.am @@ -20,10 +20,12 @@ noinst_LTLIBRARIES = libtestgencpp.la libstresstestgencpp.la nodist_libtestgencpp_la_SOURCES = \ gen-cpp/ThriftTest_constants.cpp \ - gen-cpp/ThriftTest_types.cpp \ gen-cpp/ThriftTest_constants.h \ + gen-cpp/ThriftTest_types.cpp \ gen-cpp/ThriftTest_types.h \ gen-cpp/ThriftTest_types.tcc \ + gen-cpp/ThriftTest.cpp \ + gen-cpp/ThriftTest.h \ gen-cpp/ThriftTest.tcc \ src/ThriftTest_extras.cpp