|
17 | 17 | #include <thrift/compiler/generate/cpp/util.h> |
18 | 18 |
|
19 | 19 | #include <algorithm> |
| 20 | +#include <cassert> |
20 | 21 | #include <functional> |
21 | 22 | #include <memory> |
22 | 23 | #include <queue> |
@@ -120,6 +121,38 @@ bool is_custom_type(const t_field& field) { |
120 | 121 | is_custom_type(*field.type()); |
121 | 122 | } |
122 | 123 |
|
| 124 | +namespace { |
| 125 | +bool has_adapted_level(const t_type& type) { |
| 126 | + if (t_typedef::get_first_structured_annotation_or_null( |
| 127 | + &type, kCppAdapterUri) != nullptr) { |
| 128 | + return true; |
| 129 | + } |
| 130 | + const t_type* true_type = type.get_true_type(); |
| 131 | + assert(true_type != nullptr); |
| 132 | + if (const auto* list = true_type->try_as<t_list>()) { |
| 133 | + return has_adapted_level(*list->elem_type()); |
| 134 | + } |
| 135 | + if (const auto* set = true_type->try_as<t_set>()) { |
| 136 | + return has_adapted_level(*set->elem_type()); |
| 137 | + } |
| 138 | + if (const auto* map = true_type->try_as<t_map>()) { |
| 139 | + return has_adapted_level(*map->key_type()) || |
| 140 | + has_adapted_level(*map->val_type()); |
| 141 | + } |
| 142 | + return false; |
| 143 | +} |
| 144 | +} // namespace |
| 145 | + |
| 146 | +bool is_arena_supported(const t_field& field) { |
| 147 | + const t_type* type = field.type()->get_true_type(); |
| 148 | + assert(type != nullptr); |
| 149 | + return (type->is_string_or_binary() || type->is<t_container>()) && |
| 150 | + field.default_value() == nullptr && !is_ref(&field) && !is_lazy(&field) && |
| 151 | + !is_binary_iobuf(field) && |
| 152 | + !field.has_structured_annotation(kCppAdapterUri) && |
| 153 | + !has_adapted_level(*field.type()); |
| 154 | +} |
| 155 | + |
123 | 156 | bool container_supports_incomplete_params(const t_type& type) { |
124 | 157 | if (t_typedef::get_first_structured_annotation_or_null( |
125 | 158 | &type, |
|
0 commit comments