|
|
@ -74,24 +74,6 @@ namespace rust { |
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
namespace { |
|
|
|
std::string ToCamelCase(absl::string_view name) { |
|
|
|
|
|
|
|
return cpp::UnderscoresToCamelCase(name, /* upper initial letter */ true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string OneofViewEnumRsName(const OneofDescriptor& oneof) { |
|
|
|
|
|
|
|
return ToCamelCase(oneof.name()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string OneofMutEnumRsName(const OneofDescriptor& oneof) { |
|
|
|
|
|
|
|
return ToCamelCase(oneof.name()) + "Mut"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string OneofCaseEnumName(const OneofDescriptor& oneof) { |
|
|
|
|
|
|
|
// Note: This is the name used for the cpp Case enum, we use it for both
|
|
|
|
|
|
|
|
// the Rust Case enum as well as for the cpp case enum in the cpp thunk.
|
|
|
|
|
|
|
|
return ToCamelCase(oneof.name()) + "Case"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string RsTypeNameView(Context& ctx, const FieldDescriptor& field) { |
|
|
|
std::string RsTypeNameView(Context& ctx, const FieldDescriptor& field) { |
|
|
|
if (field.options().has_ctype()) { |
|
|
|
if (field.options().has_ctype()) { |
|
|
|
return ""; // TODO: b/308792377 - ctype fields not supported yet.
|
|
|
|
return ""; // TODO: b/308792377 - ctype fields not supported yet.
|
|
|
@ -177,7 +159,7 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) { |
|
|
|
if (rs_type.empty()) { |
|
|
|
if (rs_type.empty()) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Emit({{"name", ToCamelCase(field.name())}, |
|
|
|
ctx.Emit({{"name", OneofCaseRsName(field)}, |
|
|
|
{"type", rs_type}, |
|
|
|
{"type", rs_type}, |
|
|
|
{"number", std::to_string(field.number())}}, |
|
|
|
{"number", std::to_string(field.number())}}, |
|
|
|
R"rs($name$($type$) = $number$, |
|
|
|
R"rs($name$($type$) = $number$, |
|
|
@ -192,7 +174,7 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) { |
|
|
|
if (rs_type.empty()) { |
|
|
|
if (rs_type.empty()) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Emit({{"name", ToCamelCase(field.name())}, |
|
|
|
ctx.Emit({{"name", OneofCaseRsName(field)}, |
|
|
|
{"type", rs_type}, |
|
|
|
{"type", rs_type}, |
|
|
|
{"number", std::to_string(field.number())}}, |
|
|
|
{"number", std::to_string(field.number())}}, |
|
|
|
R"rs($name$($type$) = $number$, |
|
|
|
R"rs($name$($type$) = $number$, |
|
|
@ -230,12 +212,12 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) { |
|
|
|
|
|
|
|
|
|
|
|
// Note: This enum is used as the Thunk return type for getting which case is
|
|
|
|
// Note: This enum is used as the Thunk return type for getting which case is
|
|
|
|
// used: it exactly matches the generate case enum that both cpp and upb use.
|
|
|
|
// used: it exactly matches the generate case enum that both cpp and upb use.
|
|
|
|
ctx.Emit({{"case_enum_name", OneofCaseEnumName(oneof)}, |
|
|
|
ctx.Emit({{"case_enum_name", OneofCaseEnumRsName(oneof)}, |
|
|
|
{"cases", |
|
|
|
{"cases", |
|
|
|
[&] { |
|
|
|
[&] { |
|
|
|
for (int i = 0; i < oneof.field_count(); ++i) { |
|
|
|
for (int i = 0; i < oneof.field_count(); ++i) { |
|
|
|
auto& field = *oneof.field(i); |
|
|
|
auto& field = *oneof.field(i); |
|
|
|
ctx.Emit({{"name", ToCamelCase(field.name())}, |
|
|
|
ctx.Emit({{"name", OneofCaseRsName(field)}, |
|
|
|
{"number", std::to_string(field.number())}}, |
|
|
|
{"number", std::to_string(field.number())}}, |
|
|
|
R"rs($name$ = $number$, |
|
|
|
R"rs($name$ = $number$, |
|
|
|
)rs"); |
|
|
|
)rs"); |
|
|
@ -260,7 +242,7 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { |
|
|
|
{{"oneof_name", oneof.name()}, |
|
|
|
{{"oneof_name", oneof.name()}, |
|
|
|
{"view_enum_name", OneofViewEnumRsName(oneof)}, |
|
|
|
{"view_enum_name", OneofViewEnumRsName(oneof)}, |
|
|
|
{"mut_enum_name", OneofMutEnumRsName(oneof)}, |
|
|
|
{"mut_enum_name", OneofMutEnumRsName(oneof)}, |
|
|
|
{"case_enum_name", OneofCaseEnumName(oneof)}, |
|
|
|
{"case_enum_name", OneofCaseEnumRsName(oneof)}, |
|
|
|
{"view_cases", |
|
|
|
{"view_cases", |
|
|
|
[&] { |
|
|
|
[&] { |
|
|
|
for (int i = 0; i < oneof.field_count(); ++i) { |
|
|
|
for (int i = 0; i < oneof.field_count(); ++i) { |
|
|
@ -271,7 +253,7 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Emit( |
|
|
|
ctx.Emit( |
|
|
|
{ |
|
|
|
{ |
|
|
|
{"case", ToCamelCase(field.name())}, |
|
|
|
{"case", OneofCaseRsName(field)}, |
|
|
|
{"rs_getter", field.name()}, |
|
|
|
{"rs_getter", field.name()}, |
|
|
|
{"type", rs_type}, |
|
|
|
{"type", rs_type}, |
|
|
|
}, |
|
|
|
}, |
|
|
@ -290,7 +272,7 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Emit( |
|
|
|
ctx.Emit( |
|
|
|
{{"case", ToCamelCase(field.name())}, |
|
|
|
{{"case", OneofCaseRsName(field)}, |
|
|
|
{"rs_mut_getter", field.name() + "_mut"}, |
|
|
|
{"rs_mut_getter", field.name() + "_mut"}, |
|
|
|
{"type", rs_type}, |
|
|
|
{"type", rs_type}, |
|
|
|
|
|
|
|
|
|
|
@ -341,7 +323,7 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { |
|
|
|
void GenerateOneofExternC(Context& ctx, const OneofDescriptor& oneof) { |
|
|
|
void GenerateOneofExternC(Context& ctx, const OneofDescriptor& oneof) { |
|
|
|
ctx.Emit( |
|
|
|
ctx.Emit( |
|
|
|
{ |
|
|
|
{ |
|
|
|
{"case_enum_rs_name", OneofCaseEnumName(oneof)}, |
|
|
|
{"case_enum_rs_name", OneofCaseEnumRsName(oneof)}, |
|
|
|
{"case_thunk", ThunkName(ctx, oneof, "case")}, |
|
|
|
{"case_thunk", ThunkName(ctx, oneof, "case")}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
R"rs( |
|
|
|
R"rs( |
|
|
@ -353,7 +335,7 @@ void GenerateOneofThunkCc(Context& ctx, const OneofDescriptor& oneof) { |
|
|
|
ctx.Emit( |
|
|
|
ctx.Emit( |
|
|
|
{ |
|
|
|
{ |
|
|
|
{"oneof_name", oneof.name()}, |
|
|
|
{"oneof_name", oneof.name()}, |
|
|
|
{"case_enum_name", OneofCaseEnumName(oneof)}, |
|
|
|
{"case_enum_name", OneofCaseEnumRsName(oneof)}, |
|
|
|
{"case_thunk", ThunkName(ctx, oneof, "case")}, |
|
|
|
{"case_thunk", ThunkName(ctx, oneof, "case")}, |
|
|
|
{"QualifiedMsg", cpp::QualifiedClassName(oneof.containing_type())}, |
|
|
|
{"QualifiedMsg", cpp::QualifiedClassName(oneof.containing_type())}, |
|
|
|
}, |
|
|
|
}, |
|
|
|