diff options
author | Jens Geyer <jensg@apache.org> | 2022-03-16 23:26:37 +0100 |
---|---|---|
committer | Jens Geyer <Jens-G@users.noreply.github.com> | 2022-03-17 09:48:29 +0100 |
commit | 19f60f200ba7cc67244e64905b53663d6e43046c (patch) | |
tree | 5996e962f30bb9dfa1918216c4a68928797ad933 | |
parent | 37f26bbd1143a586134acfbaab6d2b816143a966 (diff) | |
download | thrift-19f60f200ba7cc67244e64905b53663d6e43046c.tar.gz |
THRIFT-5540 Can't use a typedef for a container type containing enums in a constant
Patch: Jens Geyer
-rw-r--r-- | compiler/cpp/src/thrift/main.cc | 3 | ||||
-rw-r--r-- | compiler/cpp/src/thrift/parse/t_scope.h | 14 |
2 files changed, 17 insertions, 0 deletions
diff --git a/compiler/cpp/src/thrift/main.cc b/compiler/cpp/src/thrift/main.cc index 50bdcea46..c5aa65f32 100644 --- a/compiler/cpp/src/thrift/main.cc +++ b/compiler/cpp/src/thrift/main.cc @@ -1000,6 +1000,9 @@ void generate(t_program* program, const vector<string>& generator_strings) { dump_docstrings(program); } + // make sure all symbolic constants are properly resolved + program->scope()->resolve_all_consts(); + vector<string>::const_iterator iter; for (iter = generator_strings.begin(); iter != generator_strings.end(); ++iter) { t_generator* generator = t_generator_registry::get_generator(program, *iter); diff --git a/compiler/cpp/src/thrift/parse/t_scope.h b/compiler/cpp/src/thrift/parse/t_scope.h index a12c4df5e..17a360f08 100644 --- a/compiler/cpp/src/thrift/parse/t_scope.h +++ b/compiler/cpp/src/thrift/parse/t_scope.h @@ -25,6 +25,7 @@ #include <sstream> #include "thrift/parse/t_type.h" +#include "thrift/parse/t_typedef.h" #include "thrift/parse/t_service.h" #include "thrift/parse/t_const.h" #include "thrift/parse/t_const_value.h" @@ -96,7 +97,20 @@ public: } } + void resolve_all_consts() { + std::map<std::string, t_const*>::iterator iter; + for (iter = constants_.begin(); iter != constants_.end(); ++iter) { + t_const_value* cval = iter->second->get_value(); + t_type* ttype = iter->second->get_type(); + resolve_const_value(cval, ttype); + } + } + void resolve_const_value(t_const_value* const_val, t_type* ttype) { + while (ttype->is_typedef()) { + ttype = ((t_typedef*)ttype)->get_type(); + } + if (ttype->is_map()) { const std::map<t_const_value*, t_const_value*, t_const_value::value_compare>& map = const_val->get_map(); std::map<t_const_value*, t_const_value*, t_const_value::value_compare>::const_iterator v_iter; |