From: David Reiss Date: Tue, 28 Aug 2007 22:18:22 +0000 (+0000) Subject: Thrift: Fix a compile error. X-Git-Tag: 0.2.0~1243 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=1746e30c913d76681ad5ec788cd5ab82f67ecbd0;p=common%2Fthrift.git Thrift: Fix a compile error. Summary: The fingerprint code was generating invalid C++ code. Blame Rev: 57192 Reviewed By: mcslee Test Plan: Recompiled thrift. Thrifted DebugProtoTest with new compiler. Compiled and rand DebugProtoTest. Revert Plan: ok git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665229 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 1bbb2ede..6218b0cb 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -349,6 +349,7 @@ string t_cpp_generator::render_const_value(ofstream& out, string name, t_type* t */ void t_cpp_generator::generate_cpp_struct(t_struct* tstruct, bool is_exception) { generate_struct_definition(f_types_, tstruct, is_exception); + generate_struct_fingerprint(f_types_impl_, tstruct, true); generate_struct_reader(f_types_impl_, tstruct); generate_struct_writer(f_types_impl_, tstruct); } @@ -378,18 +379,7 @@ void t_cpp_generator::generate_struct_definition(ofstream& out, indent_up(); // Put the fingerprint up top for all to see. - if (tstruct->has_fingerprint()) { - out << - indent() << "static char* ascii_fingerprint = \"" << - tstruct->get_ascii_fingerprint() << "\";" << endl << - indent() << "static char binary_fingerprint[] = {"; - char* comma = ""; - for (int i = 0; i < t_struct::fingerprint_len; i++) { - out << comma << "0x" << t_struct::byte_to_hex(tstruct->get_binary_fingerprint()[i]); - comma = ","; - } - out << "};" << endl << endl; - } + generate_struct_fingerprint(out, tstruct, false); // Get members vector::const_iterator m_iter; @@ -543,6 +533,42 @@ void t_cpp_generator::generate_struct_definition(ofstream& out, endl; } +/** + * Writes the fingerprint of a struct to either the header or implementation. + * + * @param out Output stream + * @param tstruct The struct + */ +void t_cpp_generator::generate_struct_fingerprint(ofstream& out, + t_struct* tstruct, + bool is_definition) { + string stat, nspace, comment; + if (is_definition) { + stat = ""; + nspace = tstruct->get_name() + "::"; + comment = " "; + } else { + stat = "static "; + nspace = ""; + comment = "; // "; + } + + if (tstruct->has_fingerprint()) { + out << + indent() << stat << "char* " << nspace + << "ascii_fingerprint" << comment << "= \"" << + tstruct->get_ascii_fingerprint() << "\";" << endl << + indent() << stat << "char " << nspace << + "binary_fingerprint[" << t_struct::fingerprint_len << "]" << comment << "= {"; + char* comma = ""; + for (int i = 0; i < t_struct::fingerprint_len; i++) { + out << comma << "0x" << t_struct::byte_to_hex(tstruct->get_binary_fingerprint()[i]); + comma = ","; + } + out << "};" << endl << endl; + } +} + /** * Makes a helper function to gen a struct reader. * diff --git a/compiler/cpp/src/generate/t_cpp_generator.h b/compiler/cpp/src/generate/t_cpp_generator.h index 302f2706..7d8902c3 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.h +++ b/compiler/cpp/src/generate/t_cpp_generator.h @@ -56,6 +56,7 @@ class t_cpp_generator : public t_oop_generator { std::string render_const_value(std::ofstream& out, std::string name, t_type* type, t_const_value* value); void generate_struct_definition (std::ofstream& out, t_struct* tstruct, bool is_exception=false, bool pointers=false, bool read=true, bool write=true); + void generate_struct_fingerprint (std::ofstream& out, t_struct* tstruct, bool is_definition); void generate_struct_reader (std::ofstream& out, t_struct* tstruct, bool pointers=false); void generate_struct_writer (std::ofstream& out, t_struct* tstruct, bool pointers=false); void generate_struct_result_writer (std::ofstream& out, t_struct* tstruct, bool pointers=false);