mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-10 23:17:27 +00:00
fix union type names (#5902)
* fix union type names * fix up generation and test * format * update codegen
This commit is contained in:
@@ -473,17 +473,20 @@ class DartGenerator : public BaseGenerator {
|
||||
(*namespace_code)[object_namespace] += code;
|
||||
}
|
||||
|
||||
std::string NamespaceAliasFromUnionType(const std::string &in) {
|
||||
if (in.find('_') == std::string::npos) { return in; }
|
||||
std::string NamespaceAliasFromUnionType(Namespace *root_namespace,
|
||||
const Type &type) {
|
||||
const std::vector<std::string> qualified_name_parts =
|
||||
type.struct_def->defined_namespace->components;
|
||||
if (std::equal(root_namespace->components.begin(),
|
||||
root_namespace->components.end(),
|
||||
qualified_name_parts.begin())) {
|
||||
return type.struct_def->name;
|
||||
}
|
||||
|
||||
std::stringstream ss(in);
|
||||
std::string item;
|
||||
std::vector<std::string> parts;
|
||||
std::string ns;
|
||||
|
||||
while (std::getline(ss, item, '_')) { parts.push_back(item); }
|
||||
|
||||
for (auto it = parts.begin(); it != parts.end() - 1; ++it) {
|
||||
for (auto it = qualified_name_parts.begin();
|
||||
it != qualified_name_parts.end(); ++it) {
|
||||
auto &part = *it;
|
||||
|
||||
for (size_t i = 0; i < part.length(); i++) {
|
||||
@@ -495,10 +498,10 @@ class DartGenerator : public BaseGenerator {
|
||||
ns += static_cast<char>(tolower(part[i]));
|
||||
}
|
||||
}
|
||||
if (it != parts.end() - 2) { ns += "_"; }
|
||||
if (it != qualified_name_parts.end() - 1) { ns += "_"; }
|
||||
}
|
||||
|
||||
return ns + "." + parts.back();
|
||||
return ns + "." + type.struct_def->name;
|
||||
}
|
||||
|
||||
void GenImplementationGetters(
|
||||
@@ -527,7 +530,8 @@ class DartGenerator : public BaseGenerator {
|
||||
en_it != enum_def.Vals().end(); ++en_it) {
|
||||
auto &ev = **en_it;
|
||||
|
||||
auto enum_name = NamespaceAliasFromUnionType(ev.name);
|
||||
auto enum_name = NamespaceAliasFromUnionType(
|
||||
enum_def.defined_namespace, ev.union_type);
|
||||
code += " case " + enum_def.ToString(ev) + ": return " +
|
||||
enum_name + ".reader.vTableGet(_bc, _bcOffset, " +
|
||||
NumToString(field.value.offset) + ", null);\n";
|
||||
|
||||
Reference in New Issue
Block a user