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 1bbb2ed..6218b0c 100644
--- a/compiler/cpp/src/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/generate/t_cpp_generator.cc
@@ -349,6 +349,7 @@
*/
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 @@
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<t_field*>::const_iterator m_iter;
@@ -544,6 +534,42 @@
}
/**
+ * 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.
*
* @param out Stream to write to
diff --git a/compiler/cpp/src/generate/t_cpp_generator.h b/compiler/cpp/src/generate/t_cpp_generator.h
index 302f270..7d8902c 100644
--- a/compiler/cpp/src/generate/t_cpp_generator.h
+++ b/compiler/cpp/src/generate/t_cpp_generator.h
@@ -56,6 +56,7 @@
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);