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/main.cc b/compiler/cpp/src/main.cc
index 9f3eb73..b2aaeb4 100644
--- a/compiler/cpp/src/main.cc
+++ b/compiler/cpp/src/main.cc
@@ -560,7 +560,7 @@
}
/**
- * Call generate_fingerprint for every structure.
+ * Call generate_fingerprint for every structure and enum.
*/
void generate_all_fingerprints(t_program* program) {
const vector<t_struct*>& structs = program->get_structs();
@@ -577,6 +577,13 @@
st->generate_fingerprint();
}
+ const vector<t_enum*>& enums = program->get_enums();
+ vector<t_enum*>::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.