This is an automated email from the ASF dual-hosted git repository.
jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git
The following commit(s) were added to refs/heads/master by this push:
new 19f60f2 THRIFT-5540 Can't use a typedef for a container type
containing enums in a constant Patch: Jens Geyer
19f60f2 is described below
commit 19f60f200ba7cc67244e64905b53663d6e43046c
Author: Jens Geyer <[email protected]>
AuthorDate: Wed Mar 16 23:26:37 2022 +0100
THRIFT-5540 Can't use a typedef for a container type containing enums in a
constant
Patch: Jens Geyer
---
compiler/cpp/src/thrift/main.cc | 3 +++
compiler/cpp/src/thrift/parse/t_scope.h | 14 ++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/compiler/cpp/src/thrift/main.cc b/compiler/cpp/src/thrift/main.cc
index 50bdcea..c5aa65f 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 a12c4df..17a360f 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;