Skip to content

Commit

Permalink
fbcode/common/
Browse files Browse the repository at this point in the history
Reviewed By: iahs

Differential Revision: D51362577

fbshipit-source-id: a3986008d0ea398974ff2068c270927a47129eb9
  • Loading branch information
generatedunixname226714639793621 authored and facebook-github-bot committed Nov 15, 2023
1 parent a088b39 commit 78f4b10
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 101 deletions.
9 changes: 6 additions & 3 deletions exactprint/tests/fbthrift-tests/coroutines/src/module.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
* limitations under the License.
*/

include "thrift/annotation/cpp.thrift"

service MyService {
void ping() (cpp.coroutine);
void ping();
string getRandomData();
bool hasDataById(1: i64 id) (cpp.coroutine);
string getDataById(1: i64 id) (cpp.coroutine, thread = 'eb');
bool hasDataById(1: i64 id);
@cpp.ProcessInEbThreadUnsafe
string getDataById(1: i64 id);
void putDataById(1: i64 id, 2: string data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
* limitations under the License.
*/

include "thrift/annotation/cpp.thrift"

struct Foo {
1: optional Foo foo (cpp.ref);
2: optional Foo bar (cpp.ref_type = "shared");
@cpp.Ref{type = cpp.RefType.Unique}
1: optional Foo foo;
@cpp.Ref{type = cpp.RefType.SharedMutable}
2: optional Foo bar;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@

namespace cpp2 apache.thrift.test

include "thrift/annotation/cpp.thrift"

struct A {
1: optional map<i32, B> (cpp2.template = "std::unordered_map") some_map;
@cpp.Type{template = "std::unordered_map"}
1: optional map<i32, B> some_map;
}

struct B {
Expand Down
7 changes: 5 additions & 2 deletions exactprint/tests/fbthrift-tests/patch/src/module.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

include "thrift/annotation/thrift.thrift"
include "thrift/lib/thrift/patch.thrift"
include "thrift/annotation/cpp.thrift"

@thrift.TerseWrite
@patch.GeneratePatch
Expand Down Expand Up @@ -53,7 +54,8 @@ struct MyStruct {
6: float floatVal;
7: double doubleVal;
8: string stringVal;
9: binary (cpp.type = "::folly::IOBuf") binaryVal;
@cpp.Type{name = "::folly::IOBuf"}
9: binary binaryVal;
10: MyData structVal;

11: optional bool optBoolVal;
Expand All @@ -64,7 +66,8 @@ struct MyStruct {
16: optional float optFloatVal;
17: optional double optDoubleVal;
18: optional string optStringVal;
19: optional binary (cpp.type = "::folly::IOBuf") optBinaryVal;
@cpp.Type{name = "::folly::IOBuf"}
19: optional binary optBinaryVal;
20: optional MyData optStructVal;

21: optional list<i16> optListVal;
Expand Down
25 changes: 17 additions & 8 deletions exactprint/tests/fbthrift-tests/py3/src/module.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

include "thrift/annotation/cpp.thrift"
include "thrift/annotation/python.thrift"

namespace cpp2 py3.simple

Expand All @@ -28,25 +29,30 @@ typedef binary IOBufPtr
typedef binary IOBuf

enum AnEnum {
None = 0 (py3.name = "NOTSET"),
@python.Name{name = "NOTSET"}
None = 0,
ONE = 1,
TWO = 2,
THREE = 3,
FOUR = 4,
}

enum AnEnumRenamed {
name = 0 (py3.name = "name_"),
value = 1 (py3.name = "value_"),
normal = 2 (py3.name = "renamed_"),
@python.Name{name = "name_"}
name = 0,
@python.Name{name = "value_"}
value = 1,
@python.Name{name = "renamed_"}
normal = 2,
}

@python.Flags
enum Flags {
flag_A = 1,
flag_B = 2,
flag_C = 4,
flag_D = 8,
} (py3.flags)
}

exception SimpleException {
1: i16 err_code;
Expand All @@ -65,10 +71,12 @@ struct SimpleStruct {
6: double real;
7: float smaller_real;
// The next field should not show up anywhere in the generated code.
8: i16 hidden_field (py3.hidden);
@python.Py3Hidden
8: i16 hidden_field;
}

typedef binary (cpp.type = "foo::Bar") foo_bar
@cpp.Type{name = "foo::Bar"}
typedef binary foo_bar

struct ComplexStruct {
1: SimpleStruct structOne;
Expand All @@ -77,7 +85,8 @@ struct ComplexStruct {
4: string name;
5: AnEnum an_enum;
6: binary some_bytes;
7: string from (py3.name = "sender");
@python.Name{name = "sender"}
7: string from;
8: string cdef;
9: foo_bar bytes_with_cpp_type;
}
Expand Down
182 changes: 100 additions & 82 deletions exactprint/tests/fbthrift-tests/refs/src/module.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,59 @@

namespace java.swift test.fixtures.refs

include "thrift/annotation/cpp.thrift"

include "thrift/annotation/thrift.thrift"

enum MyEnum {
Zero = 0,
One = 1,
}

union MyUnion {
1: i32 anInteger (cpp.ref = "true", cpp2.ref = "true");
2: string aString (cpp.ref = "true", cpp2.ref = "true");
@cpp.Ref{type = cpp.RefType.Unique}
1: i32 anInteger;
@cpp.Ref{type = cpp.RefType.Unique}
2: string aString;
}

struct MyField {
1: optional i64 opt_value (cpp.ref = "true", cpp2.ref = "true");
2: i64 value (cpp.ref = "true", cpp2.ref = "true");
3: required i64 req_value (cpp.ref = "true", cpp2.ref = "true");

4: optional MyEnum opt_enum_value (cpp.ref = "true", cpp2.ref = "true");
5: MyEnum enum_value (cpp.ref = "true", cpp2.ref = "true");
6: required MyEnum req_enum_value (cpp.ref = "true", cpp2.ref = "true");

7: optional string opt_str_value (cpp.ref = "true", cpp2.ref = "true");
8: string str_value (cpp.ref = "true", cpp2.ref = "true");
9: required string req_str_value (cpp.ref = "true", cpp2.ref = "true");
@cpp.Ref{type = cpp.RefType.Unique}
1: optional i64 opt_value;
@cpp.Ref{type = cpp.RefType.Unique}
2: i64 value;
@cpp.Ref{type = cpp.RefType.Unique}
3: required i64 req_value;

@cpp.Ref{type = cpp.RefType.Unique}
4: optional MyEnum opt_enum_value;
@cpp.Ref{type = cpp.RefType.Unique}
5: MyEnum enum_value;
@cpp.Ref{type = cpp.RefType.Unique}
6: required MyEnum req_enum_value;

@cpp.Ref{type = cpp.RefType.Unique}
7: optional string opt_str_value;
@cpp.Ref{type = cpp.RefType.Unique}
8: string str_value;
@cpp.Ref{type = cpp.RefType.Unique}
9: required string req_str_value;
}

struct MyStruct {
1: optional MyField opt_ref (cpp.ref = "true", cpp2.ref = "true");
2: MyField ref (cpp.ref = "true", cpp2.ref = "true");
3: required MyField req_ref (cpp.ref = "true", cpp2.ref = "true");
@cpp.Ref{type = cpp.RefType.Unique}
1: optional MyField opt_ref;
@cpp.Ref{type = cpp.RefType.Unique}
2: MyField ref;
@cpp.Ref{type = cpp.RefType.Unique}
3: required MyField req_ref;
}

struct StructWithUnion {
1: MyUnion u (cpp.ref = "true");
2: double aDouble (cpp.ref = "true", cpp2.ref = "true");
@cpp.Ref{type = cpp.RefType.Unique}
1: MyUnion u;
@cpp.Ref{type = cpp.RefType.Unique}
2: double aDouble;
3: MyField f;
}

Expand All @@ -61,55 +81,53 @@ struct RecursiveStruct {
}

struct StructWithContainers {
1: list<i32> list_ref (cpp.ref = "true", cpp2.ref = "true");
2: set<i32> set_ref (cpp.ref = "true", cpp2.ref = "true");
3: map<i32, i32> map_ref (cpp.ref = "true", cpp2.ref = "true");
4: list<i32> list_ref_unique (
cpp.ref_type = "unique",
cpp2.ref_type = "unique",
);
5: set<i32> set_ref_shared (
cpp.ref_type = "shared",
cpp2.ref_type = "shared",
);
6: list<i32> list_ref_shared_const (
cpp.ref_type = "shared_const",
cpp2.ref_type = "shared_const",
);
@cpp.Ref{type = cpp.RefType.Unique}
1: list<i32> list_ref;
@cpp.Ref{type = cpp.RefType.Unique}
2: set<i32> set_ref;
@cpp.Ref{type = cpp.RefType.Unique}
3: map<i32, i32> map_ref;
@cpp.Ref{type = cpp.RefType.Unique}
4: list<i32> list_ref_unique;
@cpp.Ref{type = cpp.RefType.SharedMutable}
5: set<i32> set_ref_shared;
@cpp.Ref{type = cpp.RefType.Shared}
6: list<i32> list_ref_shared_const;
}

struct StructWithSharedConst {
1: optional MyField opt_shared_const (
cpp.ref_type = "shared_const",
cpp2.ref_type = "shared_const",
);
2: MyField shared_const (
cpp.ref_type = "shared_const",
cpp2.ref_type = "shared_const",
);
3: required MyField req_shared_const (
cpp.ref_type = "shared_const",
cpp2.ref_type = "shared_const",
);
@cpp.Ref{type = cpp.RefType.Shared}
1: optional MyField opt_shared_const;
@cpp.Ref{type = cpp.RefType.Shared}
2: MyField shared_const;
@cpp.Ref{type = cpp.RefType.Shared}
3: required MyField req_shared_const;
}

@cpp.EnumType{type = cpp.EnumUnderlyingType.I16}
enum TypedEnum {
VAL1 = 0,
VAL2 = 1,
} (cpp.enum_type = "short")
}

struct Empty {}

struct StructWithRef {
1: Empty def_field (cpp.ref);
2: optional Empty opt_field (cpp.ref);
3: required Empty req_field (cpp.ref);
@cpp.Ref{type = cpp.RefType.Unique}
1: Empty def_field;
@cpp.Ref{type = cpp.RefType.Unique}
2: optional Empty opt_field;
@cpp.Ref{type = cpp.RefType.Unique}
3: required Empty req_field;
}

struct StructWithBox {
1: optional string a (thrift.box);
2: optional list<i64> b (thrift.box);
3: optional StructWithRef c (thrift.box);
@thrift.Box
1: optional string a;
@thrift.Box
2: optional list<i64> b;
@thrift.Box
3: optional StructWithRef c;
}

const StructWithRef kStructWithRef = {
Expand All @@ -119,9 +137,12 @@ const StructWithRef kStructWithRef = {
};

struct StructWithRefTypeUnique {
1: Empty def_field (cpp.ref_type = "unique");
2: optional Empty opt_field (cpp.ref_type = "unique");
3: required Empty req_field (cpp.ref_type = "unique");
@cpp.Ref{type = cpp.RefType.Unique}
1: Empty def_field;
@cpp.Ref{type = cpp.RefType.Unique}
2: optional Empty opt_field;
@cpp.Ref{type = cpp.RefType.Unique}
3: required Empty req_field;
}

const StructWithRefTypeUnique kStructWithRefTypeUnique = {
Expand All @@ -131,9 +152,12 @@ const StructWithRefTypeUnique kStructWithRefTypeUnique = {
};

struct StructWithRefTypeShared {
1: Empty def_field (cpp.ref_type = "shared");
2: optional Empty opt_field (cpp.ref_type = "shared");
3: required Empty req_field (cpp.ref_type = "shared");
@cpp.Ref{type = cpp.RefType.SharedMutable}
1: Empty def_field;
@cpp.Ref{type = cpp.RefType.SharedMutable}
2: optional Empty opt_field;
@cpp.Ref{type = cpp.RefType.SharedMutable}
3: required Empty req_field;
}

const StructWithRefTypeShared kStructWithRefTypeShared = {
Expand All @@ -143,9 +167,12 @@ const StructWithRefTypeShared kStructWithRefTypeShared = {
};

struct StructWithRefTypeSharedConst {
1: Empty def_field (cpp.ref_type = "shared_const");
2: optional Empty opt_field (cpp.ref_type = "shared_const");
3: required Empty req_field (cpp.ref_type = "shared_const");
@cpp.Ref{type = cpp.RefType.Shared}
1: Empty def_field;
@cpp.Ref{type = cpp.RefType.Shared}
2: optional Empty opt_field;
@cpp.Ref{type = cpp.RefType.Shared}
3: required Empty req_field;
}

const StructWithRefTypeSharedConst kStructWithRefTypeSharedConst = {
Expand All @@ -155,28 +182,19 @@ const StructWithRefTypeSharedConst kStructWithRefTypeSharedConst = {
};

struct StructWithRefAndAnnotCppNoexceptMoveCtor {
1: Empty def_field (cpp.ref);
@cpp.Ref{type = cpp.RefType.Unique}
1: Empty def_field;
}

struct StructWithString {
1: string def_unique_string_ref = "..." (
cpp.ref_type = "unique",
cpp2.ref_type = "unique",
);
2: string def_shared_string_ref = "..." (
cpp.ref_type = "shared",
cpp2.ref_type = "shared",
);
3: string def_shared_string_const_ref = "..." (
cpp.ref_type = "shared_const",
cpp2.ref_type = "shared_const",
);
4: string unique_string_ref (
cpp.ref_type = "unique",
cpp2.ref_type = "unique",
);
5: string shared_string_ref (
cpp.ref_type = "shared",
cpp2.ref_type = "shared",
);
@cpp.Ref{type = cpp.RefType.Unique}
1: string def_unique_string_ref = "...";
@cpp.Ref{type = cpp.RefType.SharedMutable}
2: string def_shared_string_ref = "...";
@cpp.Ref{type = cpp.RefType.Shared}
3: string def_shared_string_const_ref = "...";
@cpp.Ref{type = cpp.RefType.Unique}
4: string unique_string_ref;
@cpp.Ref{type = cpp.RefType.SharedMutable}
5: string shared_string_ref;
}
Loading

0 comments on commit 78f4b10

Please sign in to comment.