Skip to content

Commit bf08d23

Browse files
Mizuchifacebook-github-bot
authored andcommitted
Generate StructMetadata from schema.thrift
Summary: Similar to previous diff, but for StructMetadata . Reviewed By: praihan Differential Revision: D82022267 fbshipit-source-id: e6980928fcfb972da9defe73a42f17534a692b42
1 parent 4952dfa commit bf08d23

File tree

81 files changed

+2027
-2407
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2027
-2407
lines changed

third-party/thrift/src/thrift/compiler/generate/templates/cpp2/module_metadata.cpp.mustache

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ void EnumMetadata<::{{program:qualified_namespace}}::{{enum:cpp_name}}>::gen(Thr
5454
{{#program:structs}}
5555
const ::apache::thrift::metadata::ThriftStruct&
5656
StructMetadata<{{struct:cpp_fullname}}>::gen(ThriftMetadata& metadata) {
57-
auto res = metadata.structs()->emplace("{{program:name}}.{{struct:name}}", ::apache::thrift::metadata::ThriftStruct{});
58-
if (!res.second) {
59-
return res.first->second;
57+
auto res = genStructMetadata<{{struct:cpp_fullname}}>(metadata);
58+
if (res.preExists) {
59+
return res.metadata;
6060
}
61-
::apache::thrift::metadata::ThriftStruct& {{struct:metadata_name}} = res.first->second;
62-
{{struct:metadata_name}}.name() = "{{program:name}}.{{struct:name}}";
61+
::apache::thrift::metadata::ThriftStruct& {{struct:metadata_name}} = res.metadata;
6362
{{struct:metadata_name}}.is_union() = {{struct:union?}};
6463
{{#struct:fields?}}
6564
static const auto* const
@@ -83,7 +82,7 @@ StructMetadata<{{struct:cpp_fullname}}>::gen(ThriftMetadata& metadata) {
8382
{{struct:metadata_name}}.structured_annotations()->push_back({{> metadata/const_struct}});
8483
{{/constant:type.self.structured?}}
8584
{{/struct:structured_annotations}}
86-
return res.first->second;
85+
return res.metadata;
8786
}
8887
{{/program:structs}}
8988

third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/cpp2/gen-cpp2/module_metadata.cpp

Lines changed: 170 additions & 204 deletions
Large diffs are not rendered by default.

third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/cpp2_no_uri/gen-cpp2/module_no_uri_metadata.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ using ThriftFunctionGenerator = void (*)(ThriftMetadata&, ThriftService&);
2828

2929
const ::apache::thrift::metadata::ThriftStruct&
3030
StructMetadata<::cpp2::RefUnion>::gen(ThriftMetadata& metadata) {
31-
auto res = metadata.structs()->emplace("module_no_uri.RefUnion", ::apache::thrift::metadata::ThriftStruct{});
32-
if (!res.second) {
33-
return res.first->second;
31+
auto res = genStructMetadata<::cpp2::RefUnion>(metadata);
32+
if (res.preExists) {
33+
return res.metadata;
3434
}
35-
::apache::thrift::metadata::ThriftStruct& module_no_uri_RefUnion = res.first->second;
36-
module_no_uri_RefUnion.name() = "module_no_uri.RefUnion";
35+
::apache::thrift::metadata::ThriftStruct& module_no_uri_RefUnion = res.metadata;
3736
module_no_uri_RefUnion.is_union() = true;
3837
static const auto* const
3938
module_no_uri_RefUnion_fields = new std::array<EncodedThriftField, 1>{ {
@@ -47,7 +46,7 @@ StructMetadata<::cpp2::RefUnion>::gen(ThriftMetadata& metadata) {
4746
field.structured_annotations() = f.structured_annotations;
4847
module_no_uri_RefUnion.fields()->push_back(std::move(field));
4948
}
50-
return res.first->second;
49+
return res.metadata;
5150
}
5251

5352
} // namespace md

third-party/thrift/src/thrift/compiler/test/fixtures/aliasing/out/cpp2/gen-cpp2/module_metadata.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ using ThriftFunctionGenerator = void (*)(ThriftMetadata&, ThriftService&);
2828

2929
const ::apache::thrift::metadata::ThriftStruct&
3030
StructMetadata<::facebook::thrift::compiler::test::fixtures::aliasing::Foo>::gen(ThriftMetadata& metadata) {
31-
auto res = metadata.structs()->emplace("module.Foo", ::apache::thrift::metadata::ThriftStruct{});
32-
if (!res.second) {
33-
return res.first->second;
31+
auto res = genStructMetadata<::facebook::thrift::compiler::test::fixtures::aliasing::Foo>(metadata);
32+
if (res.preExists) {
33+
return res.metadata;
3434
}
35-
::apache::thrift::metadata::ThriftStruct& module_Foo = res.first->second;
36-
module_Foo.name() = "module.Foo";
35+
::apache::thrift::metadata::ThriftStruct& module_Foo = res.metadata;
3736
module_Foo.is_union() = false;
3837
static const auto* const
3938
module_Foo_fields = new std::array<EncodedThriftField, 2>{ {
@@ -47,7 +46,7 @@ StructMetadata<::facebook::thrift::compiler::test::fixtures::aliasing::Foo>::gen
4746
field.structured_annotations() = f.structured_annotations;
4847
module_Foo.fields()->push_back(std::move(field));
4948
}
50-
return res.first->second;
49+
return res.metadata;
5150
}
5251

5352
} // namespace md

third-party/thrift/src/thrift/compiler/test/fixtures/any/out/cpp2/gen-cpp2/module_metadata.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ using ThriftFunctionGenerator = void (*)(ThriftMetadata&, ThriftService&);
2828

2929
const ::apache::thrift::metadata::ThriftStruct&
3030
StructMetadata<::facebook::thrift::compiler::test::fixtures::any::detail::MyStruct>::gen(ThriftMetadata& metadata) {
31-
auto res = metadata.structs()->emplace("module.MyStruct", ::apache::thrift::metadata::ThriftStruct{});
32-
if (!res.second) {
33-
return res.first->second;
31+
auto res = genStructMetadata<::facebook::thrift::compiler::test::fixtures::any::detail::MyStruct>(metadata);
32+
if (res.preExists) {
33+
return res.metadata;
3434
}
35-
::apache::thrift::metadata::ThriftStruct& module_MyStruct = res.first->second;
36-
module_MyStruct.name() = "module.MyStruct";
35+
::apache::thrift::metadata::ThriftStruct& module_MyStruct = res.metadata;
3736
module_MyStruct.is_union() = false;
3837
static const auto* const
3938
module_MyStruct_fields = new std::array<EncodedThriftField, 1>{ {
@@ -48,16 +47,15 @@ StructMetadata<::facebook::thrift::compiler::test::fixtures::any::detail::MyStru
4847
module_MyStruct.fields()->push_back(std::move(field));
4948
}
5049
module_MyStruct.structured_annotations()->push_back(*cvStruct("cpp.Adapter", { {"name", cvString("::my::Adapter1") } }).cv_struct());
51-
return res.first->second;
50+
return res.metadata;
5251
}
5352
const ::apache::thrift::metadata::ThriftStruct&
5453
StructMetadata<::facebook::thrift::compiler::test::fixtures::any::MyUnion>::gen(ThriftMetadata& metadata) {
55-
auto res = metadata.structs()->emplace("module.MyUnion", ::apache::thrift::metadata::ThriftStruct{});
56-
if (!res.second) {
57-
return res.first->second;
54+
auto res = genStructMetadata<::facebook::thrift::compiler::test::fixtures::any::MyUnion>(metadata);
55+
if (res.preExists) {
56+
return res.metadata;
5857
}
59-
::apache::thrift::metadata::ThriftStruct& module_MyUnion = res.first->second;
60-
module_MyUnion.name() = "module.MyUnion";
58+
::apache::thrift::metadata::ThriftStruct& module_MyUnion = res.metadata;
6159
module_MyUnion.is_union() = true;
6260
static const auto* const
6361
module_MyUnion_fields = new std::array<EncodedThriftField, 1>{ {
@@ -71,16 +69,15 @@ StructMetadata<::facebook::thrift::compiler::test::fixtures::any::MyUnion>::gen(
7169
field.structured_annotations() = f.structured_annotations;
7270
module_MyUnion.fields()->push_back(std::move(field));
7371
}
74-
return res.first->second;
72+
return res.metadata;
7573
}
7674
const ::apache::thrift::metadata::ThriftStruct&
7775
StructMetadata<::facebook::thrift::compiler::test::fixtures::any::MyException>::gen(ThriftMetadata& metadata) {
78-
auto res = metadata.structs()->emplace("module.MyException", ::apache::thrift::metadata::ThriftStruct{});
79-
if (!res.second) {
80-
return res.first->second;
76+
auto res = genStructMetadata<::facebook::thrift::compiler::test::fixtures::any::MyException>(metadata);
77+
if (res.preExists) {
78+
return res.metadata;
8179
}
82-
::apache::thrift::metadata::ThriftStruct& module_MyException = res.first->second;
83-
module_MyException.name() = "module.MyException";
80+
::apache::thrift::metadata::ThriftStruct& module_MyException = res.metadata;
8481
module_MyException.is_union() = false;
8582
static const auto* const
8683
module_MyException_fields = new std::array<EncodedThriftField, 1>{ {
@@ -94,7 +91,7 @@ StructMetadata<::facebook::thrift::compiler::test::fixtures::any::MyException>::
9491
field.structured_annotations() = f.structured_annotations;
9592
module_MyException.fields()->push_back(std::move(field));
9693
}
97-
return res.first->second;
94+
return res.metadata;
9895
}
9996

10097
void ExceptionMetadata<::facebook::thrift::compiler::test::fixtures::any::MyException>::gen(ThriftMetadata& metadata) {

third-party/thrift/src/thrift/compiler/test/fixtures/basic-annotations/out/cpp2/gen-cpp2/module_metadata.cpp

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ void EnumMetadata<::cpp2::YourEnum>::gen(ThriftMetadata& metadata) {
3535

3636
const ::apache::thrift::metadata::ThriftStruct&
3737
StructMetadata<::cpp2::MyStructNestedAnnotation>::gen(ThriftMetadata& metadata) {
38-
auto res = metadata.structs()->emplace("module.MyStructNestedAnnotation", ::apache::thrift::metadata::ThriftStruct{});
39-
if (!res.second) {
40-
return res.first->second;
38+
auto res = genStructMetadata<::cpp2::MyStructNestedAnnotation>(metadata);
39+
if (res.preExists) {
40+
return res.metadata;
4141
}
42-
::apache::thrift::metadata::ThriftStruct& module_MyStructNestedAnnotation = res.first->second;
43-
module_MyStructNestedAnnotation.name() = "module.MyStructNestedAnnotation";
42+
::apache::thrift::metadata::ThriftStruct& module_MyStructNestedAnnotation = res.metadata;
4443
module_MyStructNestedAnnotation.is_union() = false;
4544
static const auto* const
4645
module_MyStructNestedAnnotation_fields = new std::array<EncodedThriftField, 1>{ {
@@ -54,42 +53,39 @@ StructMetadata<::cpp2::MyStructNestedAnnotation>::gen(ThriftMetadata& metadata)
5453
field.structured_annotations() = f.structured_annotations;
5554
module_MyStructNestedAnnotation.fields()->push_back(std::move(field));
5655
}
57-
return res.first->second;
56+
return res.metadata;
5857
}
5958
const ::apache::thrift::metadata::ThriftStruct&
6059
StructMetadata<::cpp2::detail::YourUnion>::gen(ThriftMetadata& metadata) {
61-
auto res = metadata.structs()->emplace("module.MyUnion", ::apache::thrift::metadata::ThriftStruct{});
62-
if (!res.second) {
63-
return res.first->second;
60+
auto res = genStructMetadata<::cpp2::detail::YourUnion>(metadata);
61+
if (res.preExists) {
62+
return res.metadata;
6463
}
65-
::apache::thrift::metadata::ThriftStruct& module_MyUnion = res.first->second;
66-
module_MyUnion.name() = "module.MyUnion";
64+
::apache::thrift::metadata::ThriftStruct& module_MyUnion = res.metadata;
6765
module_MyUnion.is_union() = true;
6866
module_MyUnion.structured_annotations()->push_back(*cvStruct("cpp.Adapter", { {"name", cvString("::StaticCast") } }).cv_struct());
6967
module_MyUnion.structured_annotations()->push_back(*cvStruct("cpp.Name", { {"value", cvString("YourUnion") } }).cv_struct());
70-
return res.first->second;
68+
return res.metadata;
7169
}
7270
const ::apache::thrift::metadata::ThriftStruct&
7371
StructMetadata<::cpp2::detail::YourException>::gen(ThriftMetadata& metadata) {
74-
auto res = metadata.structs()->emplace("module.MyException", ::apache::thrift::metadata::ThriftStruct{});
75-
if (!res.second) {
76-
return res.first->second;
72+
auto res = genStructMetadata<::cpp2::detail::YourException>(metadata);
73+
if (res.preExists) {
74+
return res.metadata;
7775
}
78-
::apache::thrift::metadata::ThriftStruct& module_MyException = res.first->second;
79-
module_MyException.name() = "module.MyException";
76+
::apache::thrift::metadata::ThriftStruct& module_MyException = res.metadata;
8077
module_MyException.is_union() = false;
8178
module_MyException.structured_annotations()->push_back(*cvStruct("cpp.Name", { {"value", cvString("YourException") } }).cv_struct());
8279
module_MyException.structured_annotations()->push_back(*cvStruct("cpp.Adapter", { {"name", cvString("::StaticCast") } }).cv_struct());
83-
return res.first->second;
80+
return res.metadata;
8481
}
8582
const ::apache::thrift::metadata::ThriftStruct&
8683
StructMetadata<::cpp2::detail::YourStruct>::gen(ThriftMetadata& metadata) {
87-
auto res = metadata.structs()->emplace("module.MyStruct", ::apache::thrift::metadata::ThriftStruct{});
88-
if (!res.second) {
89-
return res.first->second;
84+
auto res = genStructMetadata<::cpp2::detail::YourStruct>(metadata);
85+
if (res.preExists) {
86+
return res.metadata;
9087
}
91-
::apache::thrift::metadata::ThriftStruct& module_MyStruct = res.first->second;
92-
module_MyStruct.name() = "module.MyStruct";
88+
::apache::thrift::metadata::ThriftStruct& module_MyStruct = res.metadata;
9389
module_MyStruct.is_union() = false;
9490
static const auto* const
9591
module_MyStruct_fields = new std::array<EncodedThriftField, 9>{ {
@@ -106,16 +102,15 @@ StructMetadata<::cpp2::detail::YourStruct>::gen(ThriftMetadata& metadata) {
106102
module_MyStruct.structured_annotations()->push_back(*cvStruct("cpp.Name", { {"value", cvString("YourStruct") } }).cv_struct());
107103
module_MyStruct.structured_annotations()->push_back(*cvStruct("hack.Attributes", { {"attributes", cvList({ cvString("\\SomeClass(\\AnotherClass::class)") }) } }).cv_struct());
108104
module_MyStruct.structured_annotations()->push_back(*cvStruct("cpp.Adapter", { {"name", cvString("::StaticCast") } }).cv_struct());
109-
return res.first->second;
105+
return res.metadata;
110106
}
111107
const ::apache::thrift::metadata::ThriftStruct&
112108
StructMetadata<::cpp2::SecretStruct>::gen(ThriftMetadata& metadata) {
113-
auto res = metadata.structs()->emplace("module.SecretStruct", ::apache::thrift::metadata::ThriftStruct{});
114-
if (!res.second) {
115-
return res.first->second;
109+
auto res = genStructMetadata<::cpp2::SecretStruct>(metadata);
110+
if (res.preExists) {
111+
return res.metadata;
116112
}
117-
::apache::thrift::metadata::ThriftStruct& module_SecretStruct = res.first->second;
118-
module_SecretStruct.name() = "module.SecretStruct";
113+
::apache::thrift::metadata::ThriftStruct& module_SecretStruct = res.metadata;
119114
module_SecretStruct.is_union() = false;
120115
static const auto* const
121116
module_SecretStruct_fields = new std::array<EncodedThriftField, 2>{ {
@@ -129,7 +124,7 @@ StructMetadata<::cpp2::SecretStruct>::gen(ThriftMetadata& metadata) {
129124
field.structured_annotations() = f.structured_annotations;
130125
module_SecretStruct.fields()->push_back(std::move(field));
131126
}
132-
return res.first->second;
127+
return res.metadata;
133128
}
134129

135130
void ExceptionMetadata<::cpp2::detail::YourException>::gen(ThriftMetadata& metadata) {

third-party/thrift/src/thrift/compiler/test/fixtures/basic-enum/out/cpp2/gen-cpp2/module_metadata.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ void EnumMetadata<::test::fixtures::enumstrict::MyBigEnum>::gen(ThriftMetadata&
5353

5454
const ::apache::thrift::metadata::ThriftStruct&
5555
StructMetadata<::test::fixtures::enumstrict::MyStruct>::gen(ThriftMetadata& metadata) {
56-
auto res = metadata.structs()->emplace("module.MyStruct", ::apache::thrift::metadata::ThriftStruct{});
57-
if (!res.second) {
58-
return res.first->second;
56+
auto res = genStructMetadata<::test::fixtures::enumstrict::MyStruct>(metadata);
57+
if (res.preExists) {
58+
return res.metadata;
5959
}
60-
::apache::thrift::metadata::ThriftStruct& module_MyStruct = res.first->second;
61-
module_MyStruct.name() = "module.MyStruct";
60+
::apache::thrift::metadata::ThriftStruct& module_MyStruct = res.metadata;
6261
module_MyStruct.is_union() = false;
6362
static const auto* const
6463
module_MyStruct_fields = new std::array<EncodedThriftField, 2>{ {
@@ -72,7 +71,7 @@ StructMetadata<::test::fixtures::enumstrict::MyStruct>::gen(ThriftMetadata& meta
7271
field.structured_annotations() = f.structured_annotations;
7372
module_MyStruct.fields()->push_back(std::move(field));
7473
}
75-
return res.first->second;
74+
return res.metadata;
7675
}
7776

7877
} // namespace md

third-party/thrift/src/thrift/compiler/test/fixtures/basic-stack-arguments/out/cpp2/gen-cpp2/module_metadata.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ void EnumMetadata<::cpp2::MyEnum>::gen(ThriftMetadata& metadata) {
3434

3535
const ::apache::thrift::metadata::ThriftStruct&
3636
StructMetadata<::cpp2::MyStruct>::gen(ThriftMetadata& metadata) {
37-
auto res = metadata.structs()->emplace("module.MyStruct", ::apache::thrift::metadata::ThriftStruct{});
38-
if (!res.second) {
39-
return res.first->second;
37+
auto res = genStructMetadata<::cpp2::MyStruct>(metadata);
38+
if (res.preExists) {
39+
return res.metadata;
4040
}
41-
::apache::thrift::metadata::ThriftStruct& module_MyStruct = res.first->second;
42-
module_MyStruct.name() = "module.MyStruct";
41+
::apache::thrift::metadata::ThriftStruct& module_MyStruct = res.metadata;
4342
module_MyStruct.is_union() = false;
4443
static const auto* const
4544
module_MyStruct_fields = new std::array<EncodedThriftField, 2>{ {
@@ -53,7 +52,7 @@ StructMetadata<::cpp2::MyStruct>::gen(ThriftMetadata& metadata) {
5352
field.structured_annotations() = f.structured_annotations;
5453
module_MyStruct.fields()->push_back(std::move(field));
5554
}
56-
return res.first->second;
55+
return res.metadata;
5756
}
5857

5958
void ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::MyService>>::gen_hasDataById([[maybe_unused]] ThriftMetadata& metadata, ThriftService& service) {

0 commit comments

Comments
 (0)