From: David Reiss Date: Fri, 8 Feb 2008 21:58:06 +0000 (+0000) Subject: Thrift: Fix a bug in local reflection generation. X-Git-Tag: 0.2.0~1004 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=3c5d2fd9a87f3bdb07aac7afa2c50e5e90d88fa8;p=common%2Fthrift.git Thrift: Fix a bug in local reflection generation. Summary: The problem was that in generate_local_reflection, we refused to generate reflections for types defined in another program, including enums. But in local_reflection_name, we treated enums like base types, assuming that their reflections were always defined in this program. One solution would be to treat enums like base types everywhere, and always generate their reflections in the program where they were being used. But this change takes the opposite approach. We now always generate fingerprints for enums in the program in which they are defined, even if they are not used there. Reviewed By: mcslee Test Plan: Got the following files to build and link correctly with -dense. dreiss@dreiss-vmware:reflection:thrift/test$ tail test[12].thrift ==> test1.thrift <== enum foo { bar } ==> test2.thrift <== include "test1.thrift" struct baz { 1: test1.foo qux } Revert Plan: ok git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665468 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 3871e056..adb1028a 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -160,6 +160,9 @@ void t_cpp_generator::generate_enum(t_enum* tenum) { endl << "};" << endl << endl; + + generate_local_reflection(f_types_, tenum, false); + generate_local_reflection(f_types_impl_, tenum, true); } /** @@ -2869,12 +2872,11 @@ string t_cpp_generator::local_reflection_name(const char* prefix, t_type* ttype) // and put them in Thrift.{h,cpp} ? if (ttype->is_base_type()) { - //name = ttype->get_name(); prog = program_->get_name(); name = ttype->get_ascii_fingerprint(); } else if (ttype->is_enum()) { - //name = "enum"; - prog = program_->get_name(); + assert(ttype->get_program() != NULL); + prog = ttype->get_program()->get_name(); name = ttype->get_ascii_fingerprint(); } else if (ttype->is_container()) { prog = program_->get_name(); diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc index 9f3eb731..b2aaeb4f 100644 --- a/compiler/cpp/src/main.cc +++ b/compiler/cpp/src/main.cc @@ -560,7 +560,7 @@ void dump_docstrings(t_program* program) { } /** - * Call generate_fingerprint for every structure. + * Call generate_fingerprint for every structure and enum. */ void generate_all_fingerprints(t_program* program) { const vector& structs = program->get_structs(); @@ -577,6 +577,13 @@ void generate_all_fingerprints(t_program* program) { st->generate_fingerprint(); } + const vector& enums = program->get_enums(); + vector::const_iterator e_iter; + for (e_iter = enums.begin(); e_iter != enums.end(); ++e_iter) { + t_enum* e = *e_iter; + e->generate_fingerprint(); + } + g_type_void->generate_fingerprint(); // If you want to generate fingerprints for implicit structures, start here.