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
This commit is contained in:
David Reiss 2007-08-28 22:18:22 +00:00
parent dd7796fd8b
commit 1746e30c91
2 changed files with 39 additions and 12 deletions

View File

@ -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<t_field*>::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.
*

View File

@ -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);